diff options
author | Valery Piashchynski <[email protected]> | 2021-06-05 22:44:02 +0300 |
---|---|---|
committer | Valery Piashchynski <[email protected]> | 2021-06-05 22:44:02 +0300 |
commit | 599771ebbfb1b9142d4010e37369284ffda381eb (patch) | |
tree | 95bbaca6621ba8e562263d3cfb571c78d2d8a1b9 | |
parent | e1b6b6a771e09128ea8aa65c895c715b08996165 (diff) |
- Remove storage as unused
Signed-off-by: Valery Piashchynski <[email protected]>
-rwxr-xr-x | Makefile | 2 | ||||
-rw-r--r-- | plugins/websockets/storage/storage.go | 90 | ||||
-rw-r--r-- | plugins/websockets/storage/storage_test.go | 299 |
3 files changed, 0 insertions, 391 deletions
@@ -15,7 +15,6 @@ test_coverage: go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/worker_stack.out -covermode=atomic ./pkg/worker_watcher go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/bst.out -covermode=atomic ./pkg/bst go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/http.out -covermode=atomic ./tests/plugins/http - go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/storage-ws.out -covermode=atomic ./plugins/websockets/storage go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/http_config.out -covermode=atomic ./plugins/http/config go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/informer.out -covermode=atomic ./tests/plugins/informer go test -v -race -cover -tags=debug -coverpkg=./... -coverprofile=./coverage/reload.out -covermode=atomic ./tests/plugins/reload @@ -44,7 +43,6 @@ test: ## Run application tests go test -v -race -tags=debug ./pkg/worker_watcher go test -v -race -tags=debug ./pkg/bst go test -v -race -tags=debug ./tests/plugins/http - go test -v -race -tags=debug ./plugins/websockets/storage go test -v -race -tags=debug ./plugins/http/config go test -v -race -tags=debug ./tests/plugins/informer go test -v -race -tags=debug ./tests/plugins/reload diff --git a/plugins/websockets/storage/storage.go b/plugins/websockets/storage/storage.go deleted file mode 100644 index 43834658..00000000 --- a/plugins/websockets/storage/storage.go +++ /dev/null @@ -1,90 +0,0 @@ -package storage - -import ( - "sync" - - "github.com/spiral/roadrunner/v2/pkg/bst" -) - -type Storage struct { - sync.RWMutex - BST bst.Storage -} - -func NewStorage() *Storage { - return &Storage{ - BST: bst.NewBST(), - } -} - -func (s *Storage) InsertMany(connID string, topics []string) { - s.Lock() - defer s.Unlock() - - for i := 0; i < len(topics); i++ { - s.BST.Insert(connID, topics[i]) - } -} - -func (s *Storage) Insert(connID string, topic string) { - s.Lock() - defer s.Unlock() - - s.BST.Insert(connID, topic) -} - -func (s *Storage) RemoveMany(connID string, topics []string) { - s.Lock() - defer s.Unlock() - - for i := 0; i < len(topics); i++ { - s.BST.Remove(connID, topics[i]) - } -} - -func (s *Storage) Remove(connID string, topic string) { - s.Lock() - defer s.Unlock() - - s.BST.Remove(connID, topic) -} - -// GetByPtrTS Thread safe get -func (s *Storage) GetByPtrTS(topics []string, res map[string]struct{}) { - s.Lock() - defer s.Unlock() - - for i := 0; i < len(topics); i++ { - d := s.BST.Get(topics[i]) - if len(d) > 0 { - for ii := range d { - res[ii] = struct{}{} - } - } - } -} -func (s *Storage) GetOneByPtr(topic string, res map[string]struct{}) { - s.RLock() - defer s.RUnlock() - - d := s.BST.Get(topic) - if len(d) > 0 { - for ii := range d { - res[ii] = struct{}{} - } - } -} - -func (s *Storage) GetByPtr(topics []string, res map[string]struct{}) { - s.RLock() - defer s.RUnlock() - - for i := 0; i < len(topics); i++ { - d := s.BST.Get(topics[i]) - if len(d) > 0 { - for ii := range d { - res[ii] = struct{}{} - } - } - } -} diff --git a/plugins/websockets/storage/storage_test.go b/plugins/websockets/storage/storage_test.go deleted file mode 100644 index 4072992a..00000000 --- a/plugins/websockets/storage/storage_test.go +++ /dev/null @@ -1,299 +0,0 @@ -package storage - -import ( - "math/rand" - "testing" - "time" - - "github.com/google/uuid" - "github.com/stretchr/testify/assert" -) - -const predifined = "chat-1-2" - -func TestNewBST(t *testing.T) { - // create a new bst - g := NewStorage() - - for i := 0; i < 100; i++ { - g.InsertMany(uuid.NewString(), []string{"comments"}) - } - - for i := 0; i < 100; i++ { - g.InsertMany(uuid.NewString(), []string{"comments2"}) - } - - for i := 0; i < 100; i++ { - g.InsertMany(uuid.NewString(), []string{"comments3"}) - } - - res := make(map[string]struct{}, 100) - assert.Len(t, res, 0) - - // should be 100 - g.GetByPtr([]string{"comments"}, res) - assert.Len(t, res, 100) - - res = make(map[string]struct{}, 100) - assert.Len(t, res, 0) - - // should be 100 - g.GetByPtr([]string{"comments2"}, res) - assert.Len(t, res, 100) - - res = make(map[string]struct{}, 100) - assert.Len(t, res, 0) - - // should be 100 - g.GetByPtr([]string{"comments3"}, res) - assert.Len(t, res, 100) -} - -func BenchmarkGraph(b *testing.B) { - g := NewStorage() - - for i := 0; i < 1000; i++ { - uid := uuid.New().String() - g.InsertMany(uuid.NewString(), []string{uid}) - } - - g.Insert(uuid.NewString(), predifined) - - b.ResetTimer() - b.ReportAllocs() - - res := make(map[string]struct{}) - - for i := 0; i < b.N; i++ { - g.GetByPtr([]string{predifined}, res) - - for i := range res { - delete(res, i) - } - } -} - -func BenchmarkBigSearch(b *testing.B) { - g1 := NewStorage() - - predefinedSlice := make([]string, 0, 1000) - for i := 0; i < 1000; i++ { - predefinedSlice = append(predefinedSlice, uuid.NewString()) - } - if predefinedSlice == nil { - b.FailNow() - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), uuid.NewString()) - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), predefinedSlice[i]) - } - - b.ResetTimer() - b.ReportAllocs() - - res := make(map[string]struct{}, 333) - - for i := 0; i < b.N; i++ { - g1.GetByPtr(predefinedSlice, res) - - for i := range res { - delete(res, i) - } - } -} - -func BenchmarkBigSearchWithRemoves(b *testing.B) { - g1 := NewStorage() - - predefinedSlice := make([]string, 0, 1000) - for i := 0; i < 1000; i++ { - predefinedSlice = append(predefinedSlice, uuid.NewString()) - } - if predefinedSlice == nil { - b.FailNow() - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), uuid.NewString()) - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), predefinedSlice[i]) - } - - b.ResetTimer() - b.ReportAllocs() - - go func() { - tt := time.NewTicker(time.Microsecond) - - res := make(map[string]struct{}, 1000) - for { - select { - case <-tt.C: - num := rand.Intn(1000) //nolint:gosec - g1.GetByPtr(predefinedSlice, res) - for k := range res { - g1.Remove(k, predefinedSlice[num]) - } - } - } - }() - - res := make(map[string]struct{}, 100) - - for i := 0; i < b.N; i++ { - g1.GetByPtr(predefinedSlice, res) - - for i := range res { - delete(res, i) - } - } -} - -func TestBigSearchWithRemoves(t *testing.T) { - g1 := NewStorage() - - predefinedSlice := make([]string, 0, 1000) - for i := 0; i < 1000; i++ { - predefinedSlice = append(predefinedSlice, uuid.NewString()) - } - if predefinedSlice == nil { - t.FailNow() - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), uuid.NewString()) - } - - for i := 0; i < 1000; i++ { - g1.Insert(uuid.NewString(), predefinedSlice[i]) - } - - stopCh := make(chan struct{}) - - go func() { - tt := time.NewTicker(time.Microsecond) - - res := make(map[string]struct{}, 1000) - for { - select { - case <-tt.C: - num := rand.Intn(1000) //nolint:gosec - g1.GetByPtr(predefinedSlice, res) - for k := range res { - g1.Remove(k, predefinedSlice[num]) - } - - case <-stopCh: - tt.Stop() - return - } - } - }() - - res := make(map[string]struct{}, 100) - - for i := 0; i < 1000; i++ { - g1.GetByPtr(predefinedSlice, res) - - for i := range res { - delete(res, i) - } - } - - stopCh <- struct{}{} -} - -func TestGraph(t *testing.T) { - g := NewStorage() - - for i := 0; i < 1000; i++ { - uid := uuid.New().String() - g.Insert(uuid.NewString(), uid) - } - - g.Insert(uuid.NewString(), predifined) - - res := make(map[string]struct{}) - - g.GetByPtr([]string{predifined}, res) - assert.NotEmpty(t, res) - assert.Len(t, res, 1) -} - -func TestTreeConcurrentContains(t *testing.T) { - g := NewStorage() - - key1 := uuid.NewString() - key2 := uuid.NewString() - key3 := uuid.NewString() - key4 := uuid.NewString() - key5 := uuid.NewString() - - g.Insert(key1, predifined) - g.Insert(key2, predifined) - g.Insert(key3, predifined) - g.Insert(key4, predifined) - g.Insert(key5, predifined) - - res := make(map[string]struct{}, 100) - - for i := 0; i < 100; i++ { - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - - go func() { - g.GetByPtrTS([]string{predifined}, res) - }() - } - - time.Sleep(time.Second * 5) - - res2 := make(map[string]struct{}, 5) - - g.GetByPtr([]string{predifined}, res2) - assert.NotEmpty(t, res2) - assert.Len(t, res2, 5) -} - -func TestGraphRemove(t *testing.T) { - g := NewStorage() - - key1 := uuid.NewString() - key2 := uuid.NewString() - key3 := uuid.NewString() - key4 := uuid.NewString() - key5 := uuid.NewString() - - g.Insert(key1, predifined) - g.Insert(key2, predifined) - g.Insert(key3, predifined) - g.Insert(key4, predifined) - g.Insert(key5, predifined) - - res := make(map[string]struct{}, 5) - g.GetByPtr([]string{predifined}, res) - assert.NotEmpty(t, res) - assert.Len(t, res, 5) - - g.Remove(key1, predifined) - - res2 := make(map[string]struct{}, 4) - g.GetByPtr([]string{predifined}, res2) - assert.NotEmpty(t, res2) - assert.Len(t, res2, 4) -} |