@Test
public void testConcurrentModificationAnlysis() throws IOException {
String locationKey = "a location key";
String contentKey = "content key";
H2HTestData dataOther = new H2HTestData("dataOther");
dataOther.generateVersionKey();
Number640 dataOtherKey = new Number640(Number160.createHash(locationKey), Number160.ZERO,
Number160.createHash(contentKey), dataOther.getVersionKey());
H2HTestData data1 = new H2HTestData("data1");
data1.generateVersionKey();
Number640 data1Key = new Number640(Number160.createHash(locationKey), Number160.ZERO,
Number160.createHash(contentKey), data1.getVersionKey());
waitATick();
H2HTestData data2AOlder = new H2HTestData("data2AOlder");
data2AOlder.generateVersionKey();
data2AOlder.setBasedOnKey(data1.getVersionKey());
Number640 data2AOlderKey = new Number640(Number160.createHash(locationKey), Number160.ZERO,
Number160.createHash(contentKey), data2AOlder.getVersionKey());
waitATick();
H2HTestData data2B = new H2HTestData("data2B");
data2B.generateVersionKey();
data2B.setBasedOnKey(data1.getVersionKey());
Number640 data2BKey = new Number640(Number160.createHash(locationKey), Number160.ZERO,
Number160.createHash(contentKey), data2B.getVersionKey());
waitATick();
H2HTestData data2ANewer = new H2HTestData("data2ANewer");
data2ANewer.generateVersionKey();
data2ANewer.setBasedOnKey(data1.getVersionKey());
Number640 data2ANewerKey = new Number640(Number160.createHash(locationKey), Number160.ZERO,
Number160.createHash(contentKey), data2ANewer.getVersionKey());
TestFuturePutListener futurePutListener = new TestFuturePutListener(new Parameters()
.setLocationKey(locationKey).setContentKey(contentKey).setVersionKey(data2B.getVersionKey())
.setData(data2B), null);
NavigableMap<Number640, Number160> dataMap = new ConcurrentSkipListMap<Number640, Number160>();
// empty map
assertTrue(futurePutListener.checkIfMyVerisonWins(dataMap));
// no based on entry
dataMap.put(dataOtherKey, dataOther.getBasedOnKey());
assertTrue(futurePutListener.checkIfMyVerisonWins(dataMap));
// contains only parent entry
dataMap.clear();
dataMap.put(data1Key, data1.getBasedOnKey());
assertTrue(futurePutListener.checkIfMyVerisonWins(dataMap));
// first entry is parent, second is corrupt
dataMap.clear();
dataMap.put(data1Key, data1.getBasedOnKey());
dataMap.put(dataOtherKey, dataOther.getBasedOnKey());
assertTrue(futurePutListener.checkIfMyVerisonWins(dataMap));
// first entry is parent, second entry is older
dataMap.clear();
dataMap.put(data1Key, data1.getBasedOnKey());
dataMap.put(data2AOlderKey, data2AOlder.getBasedOnKey());
assertFalse(futurePutListener.checkIfMyVerisonWins(dataMap));
// first entry is parent, second entry is newer
dataMap.clear();
dataMap.put(data1Key, data1.getBasedOnKey());
dataMap.put(data2ANewerKey, data2ANewer.getBasedOnKey());
assertTrue(futurePutListener.checkIfMyVerisonWins(dataMap));
// first entry is parent, second entry is same
dataMap.clear();
dataMap.put(data1Key, data1.getBasedOnKey());