use of org.apache.geode.internal.cache.CacheObserverAdapter in project geode by apache.
the class DiskRegionOverflowAsyncRollingOpLogJUnitTest method populateSecond10kto20kwrites.
private void populateSecond10kto20kwrites() {
afterHavingCompacted = false;
DiskRegionTestingBase.setCacheObserverCallBack();
CacheObserverHolder.setInstance(new CacheObserverAdapter() {
public void afterHavingCompacted() {
afterHavingCompacted = true;
}
});
// put another 10000-19999 entries
final byte[] value = new byte[ENTRY_SIZE];
Arrays.fill(value, (byte) 77);
for (int i = 10000; i < 20000; i++) {
region.put("" + i, value);
}
// Now get 10000-19999 which will fault in from second oplog
long startTimeGet2 = System.currentTimeMillis();
for (int i = 10000; i < 20000; i++) {
region.get("" + i);
}
long endTimeGet2 = System.currentTimeMillis();
if (debug)
System.out.println(" done with getting 10000-19999 which will fault in from second oplog");
// over
if (((LocalRegion) region).getDiskRegion().isBackup()) {
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return afterHavingCompacted;
}
public String description() {
return null;
}
};
Wait.waitForCriterion(ev, 30 * 1000, 200, true);
}
// Now get 0-9999 entries
long startTimeGet1 = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
region.get("" + i);
}
long endTimeGet1 = System.currentTimeMillis();
if (debug)
System.out.println(" done with getting 0-9999 entries from H-tree");
// closes disk file which will flush all buffers
region.close();
// Perf stats for get op (fauting in from H-tree)
float etGet1 = endTimeGet1 - startTimeGet1;
float etSecsGet1 = etGet1 / 1000f;
float opPerSecGet1 = etSecsGet1 == 0 ? 0 : (10000 / (etGet1 / 1000f));
float bytesPerSecGet1 = etSecsGet1 == 0 ? 0 : ((10000 * ENTRY_SIZE) / (etGet1 / 1000f));
String statsGet1 = "etGet=" + etGet1 + "ms gets/sec=" + opPerSecGet1 + " bytes/sec=" + bytesPerSecGet1;
log.info(statsGet1);
if (debug)
System.out.println("Perf Stats of get which is fauting in from H-tree :" + statsGet1);
// Perf stats for get op (fauting in from second op log)
float etGet2 = endTimeGet2 - startTimeGet2;
float etSecsGet2 = etGet2 / 1000f;
float opPerSecGet2 = etSecsGet2 == 0 ? 0 : (10000 / (etGet2 / 1000f));
float bytesPerSecGet2 = etSecsGet2 == 0 ? 0 : ((10000 * ENTRY_SIZE) / (etGet2 / 1000f));
String statsGet2 = "etGet=" + etGet2 + "ms gets/sec=" + opPerSecGet2 + " bytes/sec=" + bytesPerSecGet2;
log.info(statsGet2);
if (debug)
System.out.println("Perf Stats of get which is fauting in from Second OpLog :" + statsGet2);
DiskRegionTestingBase.unSetCacheObserverCallBack();
}
use of org.apache.geode.internal.cache.CacheObserverAdapter in project geode by apache.
the class ShutdownAllPersistentGatewaySenderDUnitTest method testGatewaySender.
@Test
public void testGatewaySender() throws Exception {
IgnoredException.addIgnoredException("Cache is shutting down");
Integer lnPort = (Integer) vm0.invoke(() -> WANTestBase.createFirstLocatorWithDSId(1));
Integer nyPort = (Integer) vm1.invoke(() -> WANTestBase.createFirstRemoteLocator(2, lnPort));
vm2.invoke(() -> WANTestBase.createCache(nyPort));
vm3.invoke(() -> WANTestBase.createCache(nyPort));
vm2.invoke(() -> WANTestBase.createReceiver());
vm2.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
vm3.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
vm4.invoke(() -> WANTestBase.createCache(lnPort));
vm4.invoke(() -> WANTestBase.createSender("ln", 2, false, 100, 400, false, false, null, true));
vm4.invoke(() -> WANTestBase.startSender("ln"));
vm4.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
// set the CacheObserver to block the ShutdownAll
SerializableRunnable waitAtShutdownAll = new SerializableRunnable() {
@Override
public void run() {
LocalRegion.ISSUE_CALLBACKS_TO_CACHE_OBSERVER = true;
CacheObserverHolder.setInstance(new CacheObserverAdapter() {
@Override
public void beforeShutdownAll() {
final Region region = cache.getRegion(getTestMethodName() + "_PR");
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
return region.size() >= 2;
}
@Override
public String description() {
return "Wait for wan to have processed several events";
}
}, 30000, 100, true);
}
});
}
};
vm2.invoke(waitAtShutdownAll);
vm3.invoke(waitAtShutdownAll);
AsyncInvocation vm4_future = vm4.invokeAsync(() -> WANTestBase.doPuts(getTestMethodName() + "_PR", NUM_KEYS));
// ShutdownAll will be suspended at observer, so puts will continue
AsyncInvocation future = shutDownAllMembers(vm2, 2, MAX_WAIT);
future.join(MAX_WAIT);
// now restart vm1 with gatewayHub
LogWriterUtils.getLogWriter().info("restart in VM2");
vm2.invoke(() -> WANTestBase.createCache(nyPort));
vm3.invoke(() -> WANTestBase.createCache(nyPort));
AsyncInvocation vm3_future = vm3.invokeAsync(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
vm2.invoke(() -> WANTestBase.createPersistentPartitionedRegion(getTestMethodName() + "_PR", "ln", 1, 100, isOffHeap()));
vm3_future.join(MAX_WAIT);
vm3.invoke(new SerializableRunnable() {
public void run() {
final Region region = cache.getRegion(getTestMethodName() + "_PR");
cache.getLogger().info("vm1's region size before restart gatewayHub is " + region.size());
}
});
vm2.invoke(() -> WANTestBase.createReceiver());
// wait for vm0 to finish its work
vm4_future.join(MAX_WAIT);
vm4.invoke(new SerializableRunnable() {
public void run() {
Region region = cache.getRegion(getTestMethodName() + "_PR");
assertEquals(NUM_KEYS, region.size());
}
});
// verify the other side (vm1)'s entries received from gateway
vm2.invoke(new SerializableRunnable() {
public void run() {
final Region region = cache.getRegion(getTestMethodName() + "_PR");
cache.getLogger().info("vm1's region size after restart gatewayHub is " + region.size());
Wait.waitForCriterion(new WaitCriterion() {
public boolean done() {
Object lastValue = region.get(NUM_KEYS - 1);
if (lastValue != null && lastValue.equals(NUM_KEYS - 1)) {
region.getCache().getLogger().info("Last key has arrived, its value is " + lastValue + ", end of wait.");
return true;
} else
return (region.size() == NUM_KEYS);
}
public String description() {
return "Waiting for destination region to reach size: " + NUM_KEYS + ", current is " + region.size();
}
}, MAX_WAIT, 100, true);
assertEquals(NUM_KEYS, region.size());
}
});
}
Aggregations