|
|
@ -79,22 +79,22 @@ func testPoFunc(k Address) (ret uint8) { |
|
|
|
return uint8(Proximity(basekey, k[:])) |
|
|
|
return uint8(Proximity(basekey, k[:])) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testDbStoreRandom(n int, chunksize int64, mock bool, t *testing.T) { |
|
|
|
func testDbStoreRandom(n int, mock bool, t *testing.T) { |
|
|
|
db, cleanup, err := newTestDbStore(mock, true) |
|
|
|
db, cleanup, err := newTestDbStore(mock, true) |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("init dbStore failed: %v", err) |
|
|
|
t.Fatalf("init dbStore failed: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
testStoreRandom(db, n, chunksize, t) |
|
|
|
testStoreRandom(db, n, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testDbStoreCorrect(n int, chunksize int64, mock bool, t *testing.T) { |
|
|
|
func testDbStoreCorrect(n int, mock bool, t *testing.T) { |
|
|
|
db, cleanup, err := newTestDbStore(mock, false) |
|
|
|
db, cleanup, err := newTestDbStore(mock, false) |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf("init dbStore failed: %v", err) |
|
|
|
t.Fatalf("init dbStore failed: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
testStoreCorrect(db, n, chunksize, t) |
|
|
|
testStoreCorrect(db, n, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMarkAccessed(t *testing.T) { |
|
|
|
func TestMarkAccessed(t *testing.T) { |
|
|
@ -138,35 +138,35 @@ func TestMarkAccessed(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestDbStoreRandom_1(t *testing.T) { |
|
|
|
func TestDbStoreRandom_1(t *testing.T) { |
|
|
|
testDbStoreRandom(1, 0, false, t) |
|
|
|
testDbStoreRandom(1, false, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestDbStoreCorrect_1(t *testing.T) { |
|
|
|
func TestDbStoreCorrect_1(t *testing.T) { |
|
|
|
testDbStoreCorrect(1, 4096, false, t) |
|
|
|
testDbStoreCorrect(1, false, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestDbStoreRandom_1k(t *testing.T) { |
|
|
|
func TestDbStoreRandom_1k(t *testing.T) { |
|
|
|
testDbStoreRandom(1000, 0, false, t) |
|
|
|
testDbStoreRandom(1000, false, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestDbStoreCorrect_1k(t *testing.T) { |
|
|
|
func TestDbStoreCorrect_1k(t *testing.T) { |
|
|
|
testDbStoreCorrect(1000, 4096, false, t) |
|
|
|
testDbStoreCorrect(1000, false, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMockDbStoreRandom_1(t *testing.T) { |
|
|
|
func TestMockDbStoreRandom_1(t *testing.T) { |
|
|
|
testDbStoreRandom(1, 0, true, t) |
|
|
|
testDbStoreRandom(1, true, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMockDbStoreCorrect_1(t *testing.T) { |
|
|
|
func TestMockDbStoreCorrect_1(t *testing.T) { |
|
|
|
testDbStoreCorrect(1, 4096, true, t) |
|
|
|
testDbStoreCorrect(1, true, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMockDbStoreRandom_1k(t *testing.T) { |
|
|
|
func TestMockDbStoreRandom_1k(t *testing.T) { |
|
|
|
testDbStoreRandom(1000, 0, true, t) |
|
|
|
testDbStoreRandom(1000, true, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func TestMockDbStoreCorrect_1k(t *testing.T) { |
|
|
|
func TestMockDbStoreCorrect_1k(t *testing.T) { |
|
|
|
testDbStoreCorrect(1000, 4096, true, t) |
|
|
|
testDbStoreCorrect(1000, true, t) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func testDbStoreNotFound(t *testing.T, mock bool) { |
|
|
|
func testDbStoreNotFound(t *testing.T, mock bool) { |
|
|
@ -243,54 +243,38 @@ func TestMockIterator(t *testing.T) { |
|
|
|
testIterator(t, true) |
|
|
|
testIterator(t, true) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func benchmarkDbStorePut(n int, processors int, chunksize int64, mock bool, b *testing.B) { |
|
|
|
func benchmarkDbStorePut(n int, mock bool, b *testing.B) { |
|
|
|
db, cleanup, err := newTestDbStore(mock, true) |
|
|
|
db, cleanup, err := newTestDbStore(mock, true) |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
b.Fatalf("init dbStore failed: %v", err) |
|
|
|
b.Fatalf("init dbStore failed: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
benchmarkStorePut(db, n, chunksize, b) |
|
|
|
benchmarkStorePut(db, n, b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func benchmarkDbStoreGet(n int, processors int, chunksize int64, mock bool, b *testing.B) { |
|
|
|
func benchmarkDbStoreGet(n int, mock bool, b *testing.B) { |
|
|
|
db, cleanup, err := newTestDbStore(mock, true) |
|
|
|
db, cleanup, err := newTestDbStore(mock, true) |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
b.Fatalf("init dbStore failed: %v", err) |
|
|
|
b.Fatalf("init dbStore failed: %v", err) |
|
|
|
} |
|
|
|
} |
|
|
|
benchmarkStoreGet(db, n, chunksize, b) |
|
|
|
benchmarkStoreGet(db, n, b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkDbStorePut_1_500(b *testing.B) { |
|
|
|
func BenchmarkDbStorePut_500(b *testing.B) { |
|
|
|
benchmarkDbStorePut(500, 1, 4096, false, b) |
|
|
|
benchmarkDbStorePut(500, false, b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkDbStorePut_8_500(b *testing.B) { |
|
|
|
func BenchmarkDbStoreGet_500(b *testing.B) { |
|
|
|
benchmarkDbStorePut(500, 8, 4096, false, b) |
|
|
|
benchmarkDbStoreGet(500, false, b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkDbStoreGet_1_500(b *testing.B) { |
|
|
|
func BenchmarkMockDbStorePut_500(b *testing.B) { |
|
|
|
benchmarkDbStoreGet(500, 1, 4096, false, b) |
|
|
|
benchmarkDbStorePut(500, true, b) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkDbStoreGet_8_500(b *testing.B) { |
|
|
|
func BenchmarkMockDbStoreGet_500(b *testing.B) { |
|
|
|
benchmarkDbStoreGet(500, 8, 4096, false, b) |
|
|
|
benchmarkDbStoreGet(500, true, b) |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkMockDbStorePut_1_500(b *testing.B) { |
|
|
|
|
|
|
|
benchmarkDbStorePut(500, 1, 4096, true, b) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkMockDbStorePut_8_500(b *testing.B) { |
|
|
|
|
|
|
|
benchmarkDbStorePut(500, 8, 4096, true, b) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkMockDbStoreGet_1_500(b *testing.B) { |
|
|
|
|
|
|
|
benchmarkDbStoreGet(500, 1, 4096, true, b) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func BenchmarkMockDbStoreGet_8_500(b *testing.B) { |
|
|
|
|
|
|
|
benchmarkDbStoreGet(500, 8, 4096, true, b) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// TestLDBStoreWithoutCollectGarbage tests that we can put a number of random chunks in the LevelDB store, and
|
|
|
|
// TestLDBStoreWithoutCollectGarbage tests that we can put a number of random chunks in the LevelDB store, and
|
|
|
@ -303,7 +287,7 @@ func TestLDBStoreWithoutCollectGarbage(t *testing.T) { |
|
|
|
ldb.setCapacity(uint64(capacity)) |
|
|
|
ldb.setCapacity(uint64(capacity)) |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
|
|
|
|
|
|
|
|
chunks, err := mputRandomChunks(ldb, n, int64(ch.DefaultSize)) |
|
|
|
chunks, err := mputRandomChunks(ldb, n) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err.Error()) |
|
|
|
t.Fatal(err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
@ -383,7 +367,7 @@ func testLDBStoreCollectGarbage(t *testing.T) { |
|
|
|
putCount = roundTarget |
|
|
|
putCount = roundTarget |
|
|
|
} |
|
|
|
} |
|
|
|
remaining -= putCount |
|
|
|
remaining -= putCount |
|
|
|
chunks, err := mputRandomChunks(ldb, putCount, int64(ch.DefaultSize)) |
|
|
|
chunks, err := mputRandomChunks(ldb, putCount) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err.Error()) |
|
|
|
t.Fatal(err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
@ -430,7 +414,7 @@ func TestLDBStoreAddRemove(t *testing.T) { |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
|
|
|
|
|
|
|
|
n := 100 |
|
|
|
n := 100 |
|
|
|
chunks, err := mputRandomChunks(ldb, n, int64(ch.DefaultSize)) |
|
|
|
chunks, err := mputRandomChunks(ldb, n) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatalf(err.Error()) |
|
|
|
t.Fatalf(err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
@ -578,7 +562,7 @@ func TestLDBStoreCollectGarbageAccessUnlikeIndex(t *testing.T) { |
|
|
|
ldb.setCapacity(uint64(capacity)) |
|
|
|
ldb.setCapacity(uint64(capacity)) |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
|
|
|
|
|
|
|
|
chunks, err := mputRandomChunks(ldb, n, int64(ch.DefaultSize)) |
|
|
|
chunks, err := mputRandomChunks(ldb, n) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err.Error()) |
|
|
|
t.Fatal(err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
@ -591,7 +575,7 @@ func TestLDBStoreCollectGarbageAccessUnlikeIndex(t *testing.T) { |
|
|
|
t.Fatalf("fail add chunk #%d - %s: %v", i, chunks[i].Address(), err) |
|
|
|
t.Fatalf("fail add chunk #%d - %s: %v", i, chunks[i].Address(), err) |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
_, err = mputRandomChunks(ldb, 2, int64(ch.DefaultSize)) |
|
|
|
_, err = mputRandomChunks(ldb, 2) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err.Error()) |
|
|
|
t.Fatal(err.Error()) |
|
|
|
} |
|
|
|
} |
|
|
@ -625,7 +609,7 @@ func TestCleanIndex(t *testing.T) { |
|
|
|
ldb.setCapacity(uint64(capacity)) |
|
|
|
ldb.setCapacity(uint64(capacity)) |
|
|
|
defer cleanup() |
|
|
|
defer cleanup() |
|
|
|
|
|
|
|
|
|
|
|
chunks, err := mputRandomChunks(ldb, n, 4096) |
|
|
|
chunks, err := mputRandomChunks(ldb, n) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
t.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
@ -756,7 +740,7 @@ func TestCleanIndex(t *testing.T) { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// check that the iterator quits properly
|
|
|
|
// check that the iterator quits properly
|
|
|
|
chunks, err = mputRandomChunks(ldb, 4100, 4096) |
|
|
|
chunks, err = mputRandomChunks(ldb, 4100) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
t.Fatal(err) |
|
|
|
t.Fatal(err) |
|
|
|
} |
|
|
|
} |
|
|
|