diff --git a/internal/database/blockchainDB/shard_test.go b/internal/database/blockchainDB/shard_test.go new file mode 100644 index 000000000..76241c629 --- /dev/null +++ b/internal/database/blockchainDB/shard_test.go @@ -0,0 +1,46 @@ +package blockchainDB + +import ( + "fmt" + "os" + "path/filepath" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestShard(t *testing.T) { + directory := filepath.Join(os.TempDir(), "ShardTest") + os.Mkdir(directory, os.ModePerm) + defer os.RemoveAll(directory) + filename := filepath.Join(directory, "shard") + + shard, err := NewShard(5, filename) + assert.NoError(t, err, err) + + entries := make(map[[32]byte][]byte) + fr := NewFastRandom([32]byte{1, 2, 3, 4, 5}) + + for i := 0; i < 100; i++ { + if i%10 == 0 && i != 0 { + fmt.Printf("%d ",i) + if i%100==0 { + fmt.Println() + } + } + for i := 0; i < 100; i++ { + entries[fr.NextHash()] = fr.RandBuff(100, 500) + } + for k := range entries { + nv := fr.RandBuff(100, 500) + shard.Put(k, nv) + entries[k] = nv + } + for k, v := range entries { + v2, err := shard.Get(k) + assert.NoError(t, err, err) + assert.Equal(t, v, v2, "Didn't get the right value back") + } + } + shard.Close() +} diff --git a/internal/database/blockchainDB/sharddb_test.go b/internal/database/blockchainDB/sharddb_test.go index 956772deb..42b7cb264 100644 --- a/internal/database/blockchainDB/sharddb_test.go +++ b/internal/database/blockchainDB/sharddb_test.go @@ -1,8 +1,6 @@ package blockchainDB import ( - "os" - "path/filepath" "testing" "github.com/stretchr/testify/assert" @@ -25,31 +23,3 @@ func TestShardDB(t *testing.T) { assert.Equal(t, value, v, "did not get the same value back") } } - -func TestShard(t *testing.T) { - directory := filepath.Join(os.TempDir(),"ShardTest") - os.Mkdir(directory,os.ModePerm) - defer os.RemoveAll(directory) - filename := filepath.Join(directory,"shard") - - shard,err := NewShard(5,filename) - assert.NoError(t,err,err) - - entries := make(map[[32]byte][]byte) - fr := NewFastRandom([32]byte {1,2,3,4,5}) - for i:= 0; i<100000; i++ { - entries[fr.NextHash()] = fr.RandBuff(100,500) - } - for k := range entries { - nv := fr.RandBuff(100,500) - shard.Put(k,nv) - entries[k]=nv - } - for i:=0;i<1000000,i++ { - v2,err := shard.Get(k) - assert.NoError(t,err,err) - assert.Equal(t,v,v2,"Didn't get the right value back") - } - - shard.Close() -} \ No newline at end of file