additional test for block manager
@@ -160,6 +160,52 @@ func TestBlockManagerEmpty(t *testing.T) {
}
}
+func TestBlockManagerMultiplePrefixes(t *testing.T) {
+ data1 := seededRandomData(1, 600)
+ h := md5hash(data1)
+
+ data := map[string][]byte{}
+ bm := newTestBlockManager(data)
+
+ prefixes := []string{"A", "B", "C", "D", "E"}
+
+ for _, prefix := range prefixes {
+ b1, err := bm.WriteBlock("", data1, prefix)
+ if err != nil {
+ t.Errorf("error writing block with prefix %q", prefix)
+ continue
+ }
+
+ verifyBlock(t, bm, b1, data1)
+ bm.Flush()
+ verifyBlock(t, bm, b1, data1)
+
+ if got, want := b1, prefix+h; got != want {
+ t.Errorf("unexpected block ID: %v, want %v", got, want)
+ }
+ }
+
+ bm = newTestBlockManager(data)
+ for _, prefix := range prefixes {
+ verifyBlock(t, bm, prefix+h, data1)
+ }
+
+ if got, want := len(data), len(prefixes)+1; got != want {
+ t.Errorf("unexpected block count: %v, wanted %v", got, want)
+ }
+
+ // should have 1 data block + indexes
+ if err := bm.CompactIndexes(fakeTime, nil); err != nil {
+ t.Errorf("error compacting indexes: %v", err)
+ }
+
+ if got, want := len(data), 2; got != want {
+ t.Errorf("unexpected block count: %v, wanted %v", got, want)
+ }
+
+ dumpBlockManagerData(data)
+}
+
func TestBlockManagerPackIdentialToRawObject(t *testing.T) {
data0 := []byte{}
data1 := seededRandomData(1, 600)
