use of org.apache.geode.internal.cache.AbstractUpdateOperation.AbstractUpdateMessage in project geode by apache.
the class PersistentRecoveryOrderDUnitTest method doTestPersistConflictOperations.
/**
* vm0 and vm1 are peers, each holds a DR. They do put to the same key for different value at the
* same time. Use DistributionMessageObserver.beforeSendMessage to hold on the distribution
* message. One of the member will persist the conflict version tag, while another member will
* persist both of the 2 operations. Overall, their RVV should match after the operations.
*/
public void doTestPersistConflictOperations(boolean diskSync) throws Exception {
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
// Add a hook which will disconnect the DS before sending a prepare message
SerializableRunnable addObserver = new SerializableRunnable() {
public void run() {
// System.setProperty("disk.TRACE_WRITES", "true");
// System.setProperty("disk.TRACE_RECOVERY", "true");
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeSendMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof AbstractUpdateMessage) {
try {
Thread.sleep(2000);
getCache().getLogger().info("testPersistConflictOperations, beforeSendMessage");
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
@Override
public void afterProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof AbstractUpdateMessage) {
getCache().getLogger().info("testPersistConflictOperations, beforeSendMessage");
DistributionMessageObserver.setInstance(null);
}
}
});
}
};
vm0.invoke(addObserver);
vm1.invoke(addObserver);
AsyncInvocation future0 = createPersistentRegionAsync(vm0, diskSync);
AsyncInvocation future1 = createPersistentRegionAsync(vm1, diskSync);
future0.join(MAX_WAIT);
future1.join(MAX_WAIT);
// createPersistentRegion(vm0);
// createPersistentRegion(vm1);
AsyncInvocation ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
region.put("A", "vm0");
}
});
AsyncInvocation ins1 = vm1.invokeAsync(new SerializableRunnable("change the entry") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
region.put("A", "vm1");
}
});
ins0.join(MAX_WAIT);
ins1.join(MAX_WAIT);
RegionVersionVector rvv0 = getRVV(vm0);
RegionVersionVector rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
Object value0 = getEntry(vm0, "A");
Object value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
closeRegion(vm0);
closeRegion(vm1);
// recover
future1 = createPersistentRegionAsync(vm1, diskSync);
future0 = createPersistentRegionAsync(vm0, diskSync);
future1.join(MAX_WAIT);
future0.join(MAX_WAIT);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
// round 2: async disk write
vm0.invoke(addObserver);
vm1.invoke(addObserver);
ins0 = vm0.invokeAsync(new SerializableRunnable("change the entry at vm0") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 1000; i++) {
region.put("A", "vm0-" + i);
}
}
});
ins1 = vm1.invokeAsync(new SerializableRunnable("change the entry at vm1") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion(REGION_NAME);
for (int i = 0; i < 1000; i++) {
region.put("A", "vm1-" + i);
}
}
});
ins0.join(MAX_WAIT);
ins1.join(MAX_WAIT);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
closeCache(vm0);
closeCache(vm1);
// recover again
future1 = createPersistentRegionAsync(vm1, diskSync);
future0 = createPersistentRegionAsync(vm0, diskSync);
future1.join(MAX_WAIT);
future0.join(MAX_WAIT);
value0 = getEntry(vm0, "A");
value1 = getEntry(vm1, "A");
assertEquals(value0, value1);
rvv0 = getRVV(vm0);
rvv1 = getRVV(vm1);
assertSameRVV(rvv1, rvv0);
}
Aggregations