mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 09:53:48 +00:00
swarm/storage: NewRandomChunk method rather than FakeChunk
This commit is contained in:
parent
fa8acc90fb
commit
47cfe074f0
1 changed files with 30 additions and 5 deletions
|
|
@ -17,8 +17,11 @@
|
||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"crypto/rand"
|
||||||
|
"encoding/binary"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
|
|
@ -55,8 +58,8 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
||||||
memStore := NewMemStore(ldb, defaultCacheCapacity)
|
memStore := NewMemStore(ldb, defaultCacheCapacity)
|
||||||
|
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
n int // number of chunks to push to memStore
|
n int // number of chunks to push to memStore
|
||||||
chunkSize int64 // size of chunk (by default in Swarm - 4096)
|
chunkSize uint64 // size of chunk (by default in Swarm - 4096)
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
n: 1,
|
n: 1,
|
||||||
|
|
@ -70,6 +73,10 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
||||||
n: 9999,
|
n: 9999,
|
||||||
chunkSize: 4096,
|
chunkSize: 4096,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
n: 20001,
|
||||||
|
chunkSize: 4096,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
n: 80001,
|
n: 80001,
|
||||||
chunkSize: 4096,
|
chunkSize: 4096,
|
||||||
|
|
@ -80,11 +87,9 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
||||||
var chunks []*Chunk
|
var chunks []*Chunk
|
||||||
|
|
||||||
for i := 0; i < tt.n; i++ {
|
for i := 0; i < tt.n; i++ {
|
||||||
chunks = append(chunks, NewChunk(nil, make(chan bool)))
|
chunks = append(chunks, NewRandomChunk(tt.chunkSize))
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeChunk(tt.chunkSize, tt.n, chunks)
|
|
||||||
|
|
||||||
for i := 0; i < tt.n; i++ {
|
for i := 0; i < tt.n; i++ {
|
||||||
go ldb.Put(chunks[i])
|
go ldb.Put(chunks[i])
|
||||||
memStore.Put(chunks[i])
|
memStore.Put(chunks[i])
|
||||||
|
|
@ -110,3 +115,23 @@ func TestMemStoreAndLDBStore(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewRandomChunk(chunkSize uint64) *Chunk {
|
||||||
|
c := &Chunk{
|
||||||
|
Key: make([]byte, 32),
|
||||||
|
ReqC: nil,
|
||||||
|
SData: make([]byte, chunkSize),
|
||||||
|
dbStoredC: make(chan bool),
|
||||||
|
dbStoredMu: &sync.Mutex{},
|
||||||
|
}
|
||||||
|
|
||||||
|
rand.Read(c.SData)
|
||||||
|
|
||||||
|
binary.LittleEndian.PutUint64(c.SData[:8], chunkSize)
|
||||||
|
|
||||||
|
hasher := MakeHashFunc(SHA3Hash)()
|
||||||
|
hasher.Write(c.SData)
|
||||||
|
copy(c.Key, hasher.Sum(nil))
|
||||||
|
|
||||||
|
return c
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue