use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class CqDataDUnitTest method testCQWithEviction.
/**
* Test for CQ when entries are evicted from region.
*
* @throws Exception
*/
@Test
public void testCQWithEviction() throws Exception {
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM client = host.getVM(2);
final int evictionThreshold = 1;
server1.invoke(new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
// factory.setMirrorType(MirrorType.NONE);
// setting the eviction attributes.
EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(evictionThreshold, EvictionAction.OVERFLOW_TO_DISK);
factory.setEvictionAttributes(evictAttrs);
for (int i = 0; i < cqDUnitTest.regions.length; i++) {
Region region = createRegion(cqDUnitTest.regions[i], factory.createRegionAttributes());
// Set CacheListener.
region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
}
Wait.pause(2000);
try {
cqDUnitTest.startBridgeServer(0, true);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
Wait.pause(2000);
}
});
final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
cqDUnitTest.createClient(client, port1, host0);
// Create CQs.
cqDUnitTest.createCQ(client, "testCQWithEviction_0", cqDUnitTest.cqs[0]);
final int size = 10;
// CREATE VALUES.
cqDUnitTest.createValues(server1, cqDUnitTest.regions[0], size);
cqDUnitTest.executeCQ(client, "testCQWithEviction_0", false, "CqException");
Wait.pause(1 * 1000);
// Update VALUES.
cqDUnitTest.createValues(server1, cqDUnitTest.regions[0], size);
for (int i = 1; i <= size; i++) {
cqDUnitTest.waitForUpdated(client, "testCQWithEviction_0", cqDUnitTest.KEY + i);
}
cqDUnitTest.validateCQ(client, "testCQWithEviction_0", cqDUnitTest.noTest, 0, 10, 0);
// Close.
cqDUnitTest.closeClient(client);
cqDUnitTest.closeServer(server1);
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class CQListGIIDUnitTest method registerInterestListCQ.
public static void registerInterestListCQ(String regionName, int keySize) {
// Get CQ Service.
Region region = null;
try {
region = cache.getRegion("root").getSubregion(regionName);
region.getAttributesMutator().setCacheListener(new CertifiableTestCacheListener(org.apache.geode.test.dunit.LogWriterUtils.getLogWriter()));
} catch (Exception e) {
fail("Failed to get Region.", e);
}
try {
List list = new ArrayList();
for (int i = 1; i <= keySize; i++) {
list.add(KEY + i);
}
region.registerInterest(list);
} catch (Exception ex) {
fail("Failed to Register InterestList", ex);
}
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class DestroyEntryPropagationDUnitTest method createServerCache.
private static Integer createServerCache() throws Exception {
new DestroyEntryPropagationDUnitTest().createCache(new Properties());
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
CacheServer server = cache.addCacheServer();
int port = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
server.setPort(port);
server.setNotifyBySubscription(true);
server.start();
return new Integer(server.getPort());
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class DestroyEntryPropagationDUnitTest method createClientCache.
private static void createClientCache(String host, Integer port1, Integer port2) throws Exception {
int PORT1 = port1.intValue();
int PORT2 = port2.intValue();
Properties props = new Properties();
props.setProperty(MCAST_PORT, "0");
props.setProperty(LOCATORS, "");
new DestroyEntryPropagationDUnitTest().createCache(props);
CacheServerTestUtil.disableShufflingOfEndpoints();
Pool p;
try {
p = PoolManager.createFactory().addServer(host, PORT1).addServer(host, PORT2).setSubscriptionEnabled(true).setSubscriptionRedundancy(-1).setReadTimeout(2000).setSocketBufferSize(1000).setMinConnections(4).create("EntryPropagationDUnitTestPool");
} finally {
CacheServerTestUtil.enableShufflingOfEndpoints();
}
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setPoolName(p.getName());
factory.setCacheListener(new CertifiableTestCacheListener(LogWriterUtils.getLogWriter()));
RegionAttributes attrs = factory.create();
cache.createRegion(REGION_NAME, attrs);
}
use of org.apache.geode.cache30.CertifiableTestCacheListener in project geode by apache.
the class CqQueryUsingPoolDUnitTest method testRegionDestroy.
/**
* This will test the events after region destory. The CQs on the destroy region needs to be
* closed.
*/
@Test
public void testRegionDestroy() throws Exception {
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
/* Init Server and Client */
createServer(server);
final int thePort = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server.getHost());
String poolName = "testRegionDestroy";
createPool(client, poolName, host0, thePort);
createClient(client, thePort, host0);
/* Create CQs. */
createCQ(client, poolName, "testRegionDestroy_0", cqs[0]);
createCQ(client, poolName, "testRegionDestroy_1", cqs[0]);
createCQ(client, poolName, "testRegionDestroy_2", cqs[0]);
executeCQ(client, "testRegionDestroy_0", false, null);
executeCQ(client, "testRegionDestroy_1", false, null);
executeCQ(client, "testRegionDestroy_2", false, null);
/* Init values at server. */
final int size = 10;
registerInterestListCQ(client, regions[0], size, false);
createValues(server, regions[0], size);
// Wait for client to Synch.
waitForCreated(client, "testRegionDestroy_0", KEY + 10);
// validate CQs.
validateCQ(client, "testRegionDestroy_0", /* resultSize: */
noTest, /* creates: */
size, /* updates: */
noTest, /* deletes; */
noTest, /* queryInserts: */
size, /* queryUpdates: */
0, /* queryDeletes: */
0, /* totalEvents: */
size);
// Validate InterestList.
// CREATE
client.invoke(new CacheSerializableRunnable("validate updates") {
@Override
public void run2() throws CacheException {
// Wait for the region to become the correct size
WaitCriterion wc = new WaitCriterion() {
String excuse;
@Override
public boolean done() {
Region region = getRootRegion().getSubregion(regions[0]);
if (region == null) {
excuse = "Can't find region";
return false;
}
int sz = region.entrySet().size();
if (sz != size) {
excuse = "Region is of size " + sz + ", expected " + size;
return false;
}
return true;
}
@Override
public String description() {
return excuse;
}
};
Wait.waitForCriterion(wc, 30 * 1000, 250, true);
Region region = getRootRegion().getSubregion(regions[0]);
assertNotNull(region);
CertifiableTestCacheListener ctl = (CertifiableTestCacheListener) region.getAttributes().getCacheListener();
for (int i = 1; i <= 10; i++) {
ctl.waitForCreated(KEY + i);
assertNotNull(region.getEntry(KEY + i));
}
}
});
// Destroy Region.
server.invoke(new CacheSerializableRunnable("Destroy Region") {
@Override
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(regions[0]);
region1.destroyRegion();
}
});
Wait.pause(2 * 1000);
validateCQCount(client, 0);
closeClient(client);
closeServer(server);
}
Aggregations