StorageEngine<ByteArray, byte[], byte[]> store = getStorageEngine();
try {
// Insert with concurrent versions
ByteArray key = new ByteArray("mvpKey1".getBytes());
List<Versioned<byte[]>> vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val1".getBytes(), 1));
vals.add(TestUtils.getVersioned("val2".getBytes(), 2));
vals.add(TestUtils.getVersioned("val3".getBytes(), 3));
List<Versioned<byte[]>> obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any rejected versions..", obsoletes.size() == 0);
assertEquals("Should have all 3 versions stored", 3, store.get(key, null).size());
assertTrue("All concurrent versions expected",
TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
List<Versioned<byte[]>> saveVals = vals;
// Insert with some concurrent and some obsolete versions
key = new ByteArray("mvpKey2".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val1".getBytes(), 1));
vals.add(TestUtils.getVersioned("val2".getBytes(), 2));
vals.add(TestUtils.getVersioned("val3".getBytes(), 1, 1));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any obsolete versions..", obsoletes.size() == 0);
assertEquals("Should have 2 versions stored, with 1:2 superceding 1:1",
2,
store.get(key, null).size());
vals.remove(0);
assertTrue("Should have 2 versiones stored, with 1:2 superceding 1:1",
TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
// Update of concurrent versions, on top of concurrent versions
key = new ByteArray("mvpKey1".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val4".getBytes(), 4));
vals.add(TestUtils.getVersioned("val5".getBytes(), 5));
vals.add(TestUtils.getVersioned("val6".getBytes(), 6));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any rejected versions..", obsoletes.size() == 0);
assertEquals("Should have all 6 versions stored", 6, store.get(key, null).size());
vals.addAll(saveVals);
assertTrue("All 6 concurrent versions expected",
TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
saveVals = vals;
// Update of some obsolete versions, on top of concurrent versions
key = new ByteArray("mvpKey1".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
// one obsolete version
Versioned<byte[]> obsoleteVersion = TestUtils.getVersioned("val4-obsolete".getBytes(),
4);
vals.add(obsoleteVersion);
// one new concurrent version
vals.add(TestUtils.getVersioned("val7".getBytes(), 7));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should be one version rejected..", obsoletes.size() == 1);
assertEquals("Obsolete's version should be 4:1", obsoleteVersion, obsoletes.get(0));
assertEquals("Should have all 7 versions stored", 7, store.get(key, null).size());
vals.remove(0);
vals.addAll(saveVals);
assertTrue("All 7 concurrent versions expected",
TestUtils.areVersionedListsEqual(vals, store.get(key, null)));
// super version, makes all versions obsolete
key = new ByteArray("mvpKey1".getBytes());
vals = new ArrayList<Versioned<byte[]>>();
vals.add(TestUtils.getVersioned("val1234567".getBytes(), 1, 2, 3, 4, 5, 6, 7));
obsoletes = store.multiVersionPut(key, vals);
assertTrue("Should not be any rejected versions..", obsoletes.size() == 0);
assertEquals("Exactly one version to be stored", 1, store.get(key, null).size());