mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-21 04:06:44 +00:00
Merge branch 'bzz' of https://github.com/ethersphere/go-ethereum into bzz
This commit is contained in:
commit
0e07d1921e
3 changed files with 23 additions and 13 deletions
|
|
@ -284,7 +284,6 @@ func (s *dbStore) Put(chunk *Chunk) {
|
||||||
batch.Put(ikey, idata)
|
batch.Put(ikey, idata)
|
||||||
|
|
||||||
s.db.Write(batch)
|
s.db.Write(batch)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// try to find index; if found, update access cnt and return true
|
// try to find index; if found, update access cnt and return true
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,6 @@ package bzz
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"fmt"
|
|
||||||
"github.com/ethereum/go-ethereum/bzz/test"
|
"github.com/ethereum/go-ethereum/bzz/test"
|
||||||
"os"
|
"os"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
@ -16,25 +15,23 @@ func TestDPA(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("DB error: %v", err)
|
t.Errorf("DB error: %v", err)
|
||||||
}
|
}
|
||||||
// memStore := newMemStore(dbStore)
|
memStore := newMemStore(dbStore)
|
||||||
// localStore := &localStore{
|
localStore := &localStore{
|
||||||
// memStore,
|
memStore,
|
||||||
// dbStore,
|
dbStore,
|
||||||
// }
|
}
|
||||||
chunker := &TreeChunker{}
|
chunker := &TreeChunker{}
|
||||||
chunker.Init()
|
chunker.Init()
|
||||||
dpa := &DPA{
|
dpa := &DPA{
|
||||||
Chunker: chunker,
|
Chunker: chunker,
|
||||||
ChunkStore: dbStore,
|
ChunkStore: localStore,
|
||||||
}
|
}
|
||||||
dpa.Start()
|
dpa.Start()
|
||||||
reader, slice := testDataReader(0x100)
|
reader, slice := testDataReader(0x1000000)
|
||||||
fmt.Printf("Chunk size: %d.", len(slice))
|
|
||||||
key, err := dpa.Store(reader)
|
key, err := dpa.Store(reader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("Store error: %v", err)
|
t.Errorf("Store error: %v", err)
|
||||||
}
|
}
|
||||||
// time.Sleep(2 * time.Second)
|
|
||||||
resultReader := dpa.Retrieve(key)
|
resultReader := dpa.Retrieve(key)
|
||||||
resultSlice := make([]byte, len(slice))
|
resultSlice := make([]byte, len(slice))
|
||||||
n, err := resultReader.ReadAt(resultSlice, 0)
|
n, err := resultReader.ReadAt(resultSlice, 0)
|
||||||
|
|
@ -47,5 +44,19 @@ func TestDPA(t *testing.T) {
|
||||||
if !bytes.Equal(slice, resultSlice) {
|
if !bytes.Equal(slice, resultSlice) {
|
||||||
t.Errorf("Comparison error.")
|
t.Errorf("Comparison error.")
|
||||||
}
|
}
|
||||||
// time.Sleep(time.Second)
|
localStore.memStore = newMemStore(dbStore)
|
||||||
|
resultReader = dpa.Retrieve(key)
|
||||||
|
for i, _ := range resultSlice {
|
||||||
|
resultSlice[i] = 0
|
||||||
|
}
|
||||||
|
n, err = resultReader.ReadAt(resultSlice, 0)
|
||||||
|
if err != nil {
|
||||||
|
t.Errorf("Retrieve error after removing memStore: %v", err)
|
||||||
|
}
|
||||||
|
if n != len(slice) {
|
||||||
|
t.Errorf("Slice size error after removing memStore got %d, expected %d.", n, len(slice))
|
||||||
|
}
|
||||||
|
if !bytes.Equal(slice, resultSlice) {
|
||||||
|
t.Errorf("Comparison error after removing memStore.")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ type localStore struct {
|
||||||
// its integrity is checked ?
|
// its integrity is checked ?
|
||||||
func (self *localStore) Put(chunk *Chunk) {
|
func (self *localStore) Put(chunk *Chunk) {
|
||||||
self.memStore.Put(chunk)
|
self.memStore.Put(chunk)
|
||||||
self.dbStore.Put(chunk)
|
go self.dbStore.Put(chunk)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get(chunk *Chunk) looks up a chunk in the local stores
|
// Get(chunk *Chunk) looks up a chunk in the local stores
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue