use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class TestCacheCallback method waitForInvocation.
public boolean waitForInvocation(int timeoutMs, long interval) {
if (!this.invoked) {
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return invoked;
}
public String description() {
return "listener was never invoked";
}
};
Wait.waitForCriterion(ev, timeoutMs, interval, true);
}
return wasInvoked();
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class DiskRegionJUnitTest method testEntryUpdateInASynchPersistOnlyForIOExceptionCase.
/**
* If IOException occurs while updating an entry in an Asynch mode, DiskAccessException should
* occur & region should be destroyed
*/
@Test
public void testEntryUpdateInASynchPersistOnlyForIOExceptionCase() throws Exception {
DiskRegionProperties props = new DiskRegionProperties();
props.setRegionName("IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase");
props.setOverflow(true);
props.setRolling(false);
props.setBytesThreshold(48);
props.setDiskDirs(dirs);
props.setPersistBackup(true);
region = DiskRegionHelperFactory.getAsyncPersistOnlyRegion(cache, props);
// Get the oplog handle & hence the underlying file & close it
UninterruptibleFileChannel oplogFileChannel = ((LocalRegion) region).getDiskRegion().testHook_getChild().getFileChannel();
oplogFileChannel.close();
region.create("key1", new byte[16]);
region.create("key2", new byte[16]);
DiskRegion dr = ((LocalRegion) region).getDiskRegion();
dr.flushForTesting();
// Join till the asynch writer terminates
if (!dr.testWaitForAsyncFlusherThread(2000)) {
fail("async flusher thread did not terminate");
}
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
return cache.isClosed();
}
@Override
public String description() {
return "Waiting for region IGNORE_EXCEPTION_testEntryUpdateInASynchPersistOnlyForIOExceptionCase to be destroyed.";
}
}, 5000, 500, true);
((LocalRegion) region).getDiskStore().waitForClose();
assertTrue(cache.isClosed());
region = null;
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class PartitionedRegionStatsDUnitTest method testDataStoreEntryCount.
/**
* Test to make sure the datastore entry count is accurate.
*
* @throws InterruptedException
*/
@Test
public void testDataStoreEntryCount() throws InterruptedException {
// Ok, first problem, GC'd tombstone is counted as an entry
// To test
// - modifying a tombstone
// - modifying and doing tombstone GC?
final Host host = Host.getHost(0);
final VM vm0 = host.getVM(0);
final VM vm1 = host.getVM(1);
final VM vm2 = host.getVM(2);
SerializableRunnable createPrRegion = new SerializableRunnable("createRegion") {
public void run() {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(2);
PartitionAttributes prAttr = paf.create();
attr.setPartitionAttributes(prAttr);
cache.createRegion("region1", attr.create());
}
};
vm0.invoke(createPrRegion);
vm1.invoke(createPrRegion);
vm0.invoke(new SerializableRunnable("Put some data") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
region.put(Long.valueOf(0), "A");
region.put(Long.valueOf(1), "A");
region.put(Long.valueOf(113), "A");
region.put(Long.valueOf(226), "A");
}
});
validateEntryCount(vm0, 4);
validateEntryCount(vm1, 4);
// Do a destroy
vm0.invoke(new SerializableRunnable("Put some data") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
region.destroy(Long.valueOf(0));
}
});
// We expect the tombstone won't be recorded as part of
// the entry count
validateEntryCount(vm0, 3);
validateEntryCount(vm1, 3);
// Destroy and modify a tombstone
vm0.invoke(new SerializableRunnable("Put some data") {
public void run() {
Cache cache = getCache();
Region region = cache.getRegion("region1");
region.destroy(Long.valueOf(113));
region.put(Long.valueOf(113), "B");
}
});
validateEntryCount(vm0, 3);
validateEntryCount(vm1, 3);
// After GII (which might include the tombstone), a new members
// should still see only 2 live entries.
vm2.invoke(createPrRegion);
// Wait for redundancy to be restored. Once it is the entry count should be
// 2
vm2.invoke(new SerializableRunnable("validate stats") {
public void run() {
Cache cache = getCache();
PartitionedRegion region = (PartitionedRegion) cache.getRegion("region1");
final PartitionedRegionStats stats = region.getPrStats();
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
return stats.getLowRedundancyBucketCount() == 0;
}
@Override
public String description() {
return "Redundancy was not satisfied " + stats.getLowRedundancyBucketCount();
}
}, 20000, 100, true);
}
});
validateEntryCount(vm2, 3);
// A tombstone GC shouldn't affect the count.
vm0.invoke(new SerializableRunnable("Put some data") {
public void run() {
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
TombstoneService tombstoneService = cache.getTombstoneService();
try {
tombstoneService.forceBatchExpirationForTests(1);
} catch (InterruptedException e) {
Assert.fail("interrupted", e);
}
}
});
validateEntryCount(vm0, 3);
validateEntryCount(vm1, 3);
validateEntryCount(vm2, 3);
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class RemoteTransactionDUnitTest method testTXWithRICommitInDatastore.
@Test
public void testTXWithRICommitInDatastore() throws Exception {
Host host = Host.getHost(0);
VM accessor = host.getVM(0);
VM datastore = host.getVM(1);
VM client = host.getVM(2);
initAccessorAndDataStore(accessor, datastore, 0);
int port = startServer(datastore);
createClientRegion(client, port, false, true);
datastore.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
CustId custId = new CustId(1);
OrderId orderId = new OrderId(1, custId);
getCache().getCacheTransactionManager().begin();
custRegion.put(custId, new Customer("foo", "bar"));
orderRegion.put(orderId, new Order("fooOrder"));
refRegion.put(custId, new Customer("foo", "bar"));
getCache().getCacheTransactionManager().commit();
return null;
}
});
client.invoke(new SerializableCallable() {
public Object call() throws Exception {
Region<CustId, Customer> custRegion = getCache().getRegion(CUSTOMER);
Region<OrderId, Order> orderRegion = getCache().getRegion(ORDER);
Region<CustId, Customer> refRegion = getCache().getRegion(D_REFERENCE);
final ClientListener cl = (ClientListener) custRegion.getAttributes().getCacheListeners()[0];
WaitCriterion waitForListenerInvocation = new WaitCriterion() {
public boolean done() {
return cl.invoked;
}
public String description() {
return "listener was never invoked";
}
};
Wait.waitForCriterion(waitForListenerInvocation, 10 * 1000, 10, true);
return null;
}
});
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class MyFunctionException method startServerHA.
public static void startServerHA() {
WaitCriterion wc = new WaitCriterion() {
String excuse;
public boolean done() {
return false;
}
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 2000, 500, false);
Collection bridgeServers = cache.getCacheServers();
LogWriterUtils.getLogWriter().info("Start Server Bridge Servers list : " + bridgeServers.size());
Iterator bridgeIterator = bridgeServers.iterator();
CacheServer bridgeServer = (CacheServer) bridgeIterator.next();
LogWriterUtils.getLogWriter().info("start Server Bridge Server" + bridgeServer);
try {
bridgeServer.start();
} catch (IOException e) {
fail("not able to start the server");
}
}
Aggregations