aboutsummaryrefslogtreecommitdiffstats
path: root/swarm/storage/localstore/index_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'swarm/storage/localstore/index_test.go')
-rw-r--r--swarm/storage/localstore/index_test.go49
1 files changed, 19 insertions, 30 deletions
diff --git a/swarm/storage/localstore/index_test.go b/swarm/storage/localstore/index_test.go
index cf19e4f6c..0f23aa10a 100644
--- a/swarm/storage/localstore/index_test.go
+++ b/swarm/storage/localstore/index_test.go
@@ -18,6 +18,7 @@ package localstore
import (
"bytes"
+ "context"
"math/rand"
"testing"
@@ -35,29 +36,22 @@ func TestDB_pullIndex(t *testing.T) {
db, cleanupFunc := newTestDB(t, nil)
defer cleanupFunc()
- uploader := db.NewPutter(ModePutUpload)
-
chunkCount := 50
chunks := make([]testIndexChunk, chunkCount)
// upload random chunks
for i := 0; i < chunkCount; i++ {
- chunk := generateTestRandomChunk()
+ ch := generateTestRandomChunk()
- err := uploader.Put(chunk)
+ _, err := db.Put(context.Background(), chunk.ModePutUpload, ch)
if err != nil {
t.Fatal(err)
}
chunks[i] = testIndexChunk{
- Chunk: chunk,
- // this timestamp is not the same as in
- // the index, but given that uploads
- // are sequential and that only ordering
- // of events matter, this information is
- // sufficient
- storeTimestamp: now(),
+ Chunk: ch,
+ binID: uint64(i),
}
}
@@ -70,10 +64,10 @@ func TestDB_pullIndex(t *testing.T) {
if poi > poj {
return false
}
- if chunks[i].storeTimestamp < chunks[j].storeTimestamp {
+ if chunks[i].binID < chunks[j].binID {
return true
}
- if chunks[i].storeTimestamp > chunks[j].storeTimestamp {
+ if chunks[i].binID > chunks[j].binID {
return false
}
return bytes.Compare(chunks[i].Address(), chunks[j].Address()) == -1
@@ -87,23 +81,21 @@ func TestDB_gcIndex(t *testing.T) {
db, cleanupFunc := newTestDB(t, nil)
defer cleanupFunc()
- uploader := db.NewPutter(ModePutUpload)
-
chunkCount := 50
chunks := make([]testIndexChunk, chunkCount)
// upload random chunks
for i := 0; i < chunkCount; i++ {
- chunk := generateTestRandomChunk()
+ ch := generateTestRandomChunk()
- err := uploader.Put(chunk)
+ _, err := db.Put(context.Background(), chunk.ModePutUpload, ch)
if err != nil {
t.Fatal(err)
}
chunks[i] = testIndexChunk{
- Chunk: chunk,
+ Chunk: ch,
}
}
@@ -123,9 +115,9 @@ func TestDB_gcIndex(t *testing.T) {
})()
t.Run("request unsynced", func(t *testing.T) {
- chunk := chunks[1]
+ ch := chunks[1]
- _, err := db.NewGetter(ModeGetRequest).Get(chunk.Address())
+ _, err := db.Get(context.Background(), chunk.ModeGetRequest, ch.Address())
if err != nil {
t.Fatal(err)
}
@@ -140,9 +132,9 @@ func TestDB_gcIndex(t *testing.T) {
})
t.Run("sync one chunk", func(t *testing.T) {
- chunk := chunks[0]
+ ch := chunks[0]
- err := db.NewSetter(ModeSetSync).Set(chunk.Address())
+ err := db.Set(context.Background(), chunk.ModeSetSync, ch.Address())
if err != nil {
t.Fatal(err)
}
@@ -154,10 +146,8 @@ func TestDB_gcIndex(t *testing.T) {
})
t.Run("sync all chunks", func(t *testing.T) {
- setter := db.NewSetter(ModeSetSync)
-
for i := range chunks {
- err := setter.Set(chunks[i].Address())
+ err := db.Set(context.Background(), chunk.ModeSetSync, chunks[i].Address())
if err != nil {
t.Fatal(err)
}
@@ -171,7 +161,7 @@ func TestDB_gcIndex(t *testing.T) {
t.Run("request one chunk", func(t *testing.T) {
i := 6
- _, err := db.NewGetter(ModeGetRequest).Get(chunks[i].Address())
+ _, err := db.Get(context.Background(), chunk.ModeGetRequest, chunks[i].Address())
if err != nil {
t.Fatal(err)
}
@@ -189,14 +179,13 @@ func TestDB_gcIndex(t *testing.T) {
})
t.Run("random chunk request", func(t *testing.T) {
- requester := db.NewGetter(ModeGetRequest)
rand.Shuffle(len(chunks), func(i, j int) {
chunks[i], chunks[j] = chunks[j], chunks[i]
})
- for _, chunk := range chunks {
- _, err := requester.Get(chunk.Address())
+ for _, ch := range chunks {
+ _, err := db.Get(context.Background(), chunk.ModeGetRequest, ch.Address())
if err != nil {
t.Fatal(err)
}
@@ -212,7 +201,7 @@ func TestDB_gcIndex(t *testing.T) {
t.Run("remove one chunk", func(t *testing.T) {
i := 3
- err := db.NewSetter(modeSetRemove).Set(chunks[i].Address())
+ err := db.Set(context.Background(), chunk.ModeSetRemove, chunks[i].Address())
if err != nil {
t.Fatal(err)
}