diff options
Diffstat (limited to 'swarm/storage/localstore/mode_get_test.go')
-rw-r--r-- | swarm/storage/localstore/mode_get_test.go | 67 |
1 files changed, 34 insertions, 33 deletions
diff --git a/swarm/storage/localstore/mode_get_test.go b/swarm/storage/localstore/mode_get_test.go index 28a70ee0c..217fa5d2d 100644 --- a/swarm/storage/localstore/mode_get_test.go +++ b/swarm/storage/localstore/mode_get_test.go @@ -18,8 +18,11 @@ package localstore import ( "bytes" + "context" "testing" "time" + + "github.com/ethereum/go-ethereum/swarm/chunk" ) // TestModeGetRequest validates ModeGetRequest index values on the provided DB. @@ -32,15 +35,13 @@ func TestModeGetRequest(t *testing.T) { return uploadTimestamp })() - chunk := generateTestRandomChunk() + ch := generateTestRandomChunk() - err := db.NewPutter(ModePutUpload).Put(chunk) + _, err := db.Put(context.Background(), chunk.ModePutUpload, ch) if err != nil { t.Fatal(err) } - requester := db.NewGetter(ModeGetRequest) - // set update gc test hook to signal when // update gc goroutine is done by sending to // testHookUpdateGCChan channel, which is @@ -52,22 +53,22 @@ func TestModeGetRequest(t *testing.T) { })() t.Run("get unsynced", func(t *testing.T) { - got, err := requester.Get(chunk.Address()) + got, err := db.Get(context.Background(), chunk.ModeGetRequest, ch.Address()) if err != nil { t.Fatal(err) } // wait for update gc goroutine to be done <-testHookUpdateGCChan - if !bytes.Equal(got.Address(), chunk.Address()) { - t.Errorf("got chunk address %x, want %x", got.Address(), chunk.Address()) + if !bytes.Equal(got.Address(), ch.Address()) { + t.Errorf("got chunk address %x, want %x", got.Address(), ch.Address()) } - if !bytes.Equal(got.Data(), chunk.Data()) { - t.Errorf("got chunk data %x, want %x", got.Data(), chunk.Data()) + if !bytes.Equal(got.Data(), ch.Data()) { + t.Errorf("got chunk data %x, want %x", got.Data(), ch.Data()) } - t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, chunk, uploadTimestamp, 0)) + t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, ch, uploadTimestamp, 0)) t.Run("gc index count", newItemsCountTest(db.gcIndex, 0)) @@ -75,30 +76,30 @@ func TestModeGetRequest(t *testing.T) { }) // set chunk to synced state - err = db.NewSetter(ModeSetSync).Set(chunk.Address()) + err = db.Set(context.Background(), chunk.ModeSetSync, ch.Address()) if err != nil { t.Fatal(err) } t.Run("first get", func(t *testing.T) { - got, err := requester.Get(chunk.Address()) + got, err := db.Get(context.Background(), chunk.ModeGetRequest, ch.Address()) if err != nil { t.Fatal(err) } // wait for update gc goroutine to be done <-testHookUpdateGCChan - if !bytes.Equal(got.Address(), chunk.Address()) { - t.Errorf("got chunk address %x, want %x", got.Address(), chunk.Address()) + if !bytes.Equal(got.Address(), ch.Address()) { + t.Errorf("got chunk address %x, want %x", got.Address(), ch.Address()) } - if !bytes.Equal(got.Data(), chunk.Data()) { - t.Errorf("got chunk data %x, want %x", got.Data(), chunk.Data()) + if !bytes.Equal(got.Data(), ch.Data()) { + t.Errorf("got chunk data %x, want %x", got.Data(), ch.Data()) } - t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, chunk, uploadTimestamp, uploadTimestamp)) + t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, ch, uploadTimestamp, uploadTimestamp)) - t.Run("gc index", newGCIndexTest(db, chunk, uploadTimestamp, uploadTimestamp)) + t.Run("gc index", newGCIndexTest(db, ch, uploadTimestamp, uploadTimestamp, 1)) t.Run("gc index count", newItemsCountTest(db.gcIndex, 1)) @@ -111,24 +112,24 @@ func TestModeGetRequest(t *testing.T) { return accessTimestamp })() - got, err := requester.Get(chunk.Address()) + got, err := db.Get(context.Background(), chunk.ModeGetRequest, ch.Address()) if err != nil { t.Fatal(err) } // wait for update gc goroutine to be done <-testHookUpdateGCChan - if !bytes.Equal(got.Address(), chunk.Address()) { - t.Errorf("got chunk address %x, want %x", got.Address(), chunk.Address()) + if !bytes.Equal(got.Address(), ch.Address()) { + t.Errorf("got chunk address %x, want %x", got.Address(), ch.Address()) } - if !bytes.Equal(got.Data(), chunk.Data()) { - t.Errorf("got chunk data %x, want %x", got.Data(), chunk.Data()) + if !bytes.Equal(got.Data(), ch.Data()) { + t.Errorf("got chunk data %x, want %x", got.Data(), ch.Data()) } - t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, chunk, uploadTimestamp, accessTimestamp)) + t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, ch, uploadTimestamp, accessTimestamp)) - t.Run("gc index", newGCIndexTest(db, chunk, uploadTimestamp, accessTimestamp)) + t.Run("gc index", newGCIndexTest(db, ch, uploadTimestamp, accessTimestamp, 1)) t.Run("gc index count", newItemsCountTest(db.gcIndex, 1)) @@ -146,27 +147,27 @@ func TestModeGetSync(t *testing.T) { return uploadTimestamp })() - chunk := generateTestRandomChunk() + ch := generateTestRandomChunk() - err := db.NewPutter(ModePutUpload).Put(chunk) + _, err := db.Put(context.Background(), chunk.ModePutUpload, ch) if err != nil { t.Fatal(err) } - got, err := db.NewGetter(ModeGetSync).Get(chunk.Address()) + got, err := db.Get(context.Background(), chunk.ModeGetSync, ch.Address()) if err != nil { t.Fatal(err) } - if !bytes.Equal(got.Address(), chunk.Address()) { - t.Errorf("got chunk address %x, want %x", got.Address(), chunk.Address()) + if !bytes.Equal(got.Address(), ch.Address()) { + t.Errorf("got chunk address %x, want %x", got.Address(), ch.Address()) } - if !bytes.Equal(got.Data(), chunk.Data()) { - t.Errorf("got chunk data %x, want %x", got.Data(), chunk.Data()) + if !bytes.Equal(got.Data(), ch.Data()) { + t.Errorf("got chunk data %x, want %x", got.Data(), ch.Data()) } - t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, chunk, uploadTimestamp, 0)) + t.Run("retrieve indexes", newRetrieveIndexesTestWithAccess(db, ch, uploadTimestamp, 0)) t.Run("gc index count", newItemsCountTest(db.gcIndex, 0)) |