use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqDataUsingPoolDUnitTest method testGetDurableCqsFromServerCycleClientsAndMoreCqs.
@Test
public void testGetDurableCqsFromServerCycleClientsAndMoreCqs() {
final String regionName = "testGetAllDurableCqsFromServerCycleClients";
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client1 = host.getVM(1);
VM client2 = host.getVM(2);
int timeout = 60000;
// Start server 1
final int server1Port = ((Integer) server.invoke(() -> CacheServerTestUtil.createCacheServer(regionName, new Boolean(true)))).intValue();
// Start client 1
client1.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client1.getHost()), server1Port), regionName, getDurableClientProperties("client1_dc", timeout)));
// Start client 2
client2.invoke(() -> CacheServerTestUtil.createClientCache(getClientPool(NetworkUtils.getServerHostName(client2.getHost()), server1Port), regionName, getDurableClientProperties("client2_dc", timeout)));
// create the test cqs
createClient1CqsAndDurableCqs(client1, regionName);
createClient2CqsAndDurableCqs(client2, regionName);
cycleDurableClient(client1, "client1_dc", server1Port, regionName, timeout);
cycleDurableClient(client2, "client2_dc", server1Port, regionName, timeout);
client1.invoke(new CacheSerializableRunnable("Register more cq for client 1") {
@Override
public void run2() throws CacheException {
// register the cq's
QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
CqAttributesFactory cqAf = new CqAttributesFactory();
CqAttributes attributes = cqAf.create();
try {
queryService.newCq("client1MoreDCQ1", "Select * From /" + regionName + " where id = 1", attributes, true).execute();
queryService.newCq("client1MoreDCQ2", "Select * From /" + regionName + " where id = 10", attributes, true).execute();
queryService.newCq("client1MoreNoDC1", "Select * From /" + regionName, attributes, false).execute();
queryService.newCq("client1MoreNoDC2", "Select * From /" + regionName + " where id = 3", attributes, false).execute();
} catch (RegionNotFoundException e) {
fail("failed", e);
} catch (CqException e) {
fail("failed", e);
} catch (CqExistsException e) {
fail("failed", e);
}
}
});
client2.invoke(new CacheSerializableRunnable("Register more cq for client 2") {
@Override
public void run2() throws CacheException {
// register the cq's
QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
CqAttributesFactory cqAf = new CqAttributesFactory();
CqAttributes attributes = cqAf.create();
try {
queryService.newCq("client2MoreDCQ1", "Select * From /" + regionName + " where id = 1", attributes, true).execute();
queryService.newCq("client2MoreDCQ2", "Select * From /" + regionName + " where id = 10", attributes, true).execute();
queryService.newCq("client2MoreDCQ3", "Select * From /" + regionName, attributes, true).execute();
queryService.newCq("client2MoreDCQ4", "Select * From /" + regionName + " where id = 3", attributes, true).execute();
} catch (RegionNotFoundException e) {
fail("failed", e);
} catch (CqException e) {
fail("failed", e);
} catch (CqExistsException e) {
fail("failed", e);
}
}
});
// Cycle clients a second time
cycleDurableClient(client1, "client1_dc", server1Port, regionName, timeout);
cycleDurableClient(client2, "client2_dc", server1Port, regionName, timeout);
client2.invoke(new CacheSerializableRunnable("check durable cqs for client 2") {
@Override
public void run2() throws CacheException {
QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
List<String> list = null;
try {
list = queryService.getAllDurableCqsFromServer();
} catch (CqException e) {
fail("failed", e);
}
assertEquals(8, list.size());
assertTrue(list.contains("client2DCQ1"));
assertTrue(list.contains("client2DCQ2"));
assertTrue(list.contains("client2DCQ3"));
assertTrue(list.contains("client2DCQ4"));
assertTrue(list.contains("client2MoreDCQ1"));
assertTrue(list.contains("client2MoreDCQ2"));
assertTrue(list.contains("client2MoreDCQ3"));
assertTrue(list.contains("client2MoreDCQ4"));
}
});
client1.invoke(new CacheSerializableRunnable("check durable cqs for client 1") {
@Override
public void run2() throws CacheException {
QueryService queryService = CacheServerTestUtil.getCache().getQueryService();
List<String> list = null;
try {
list = queryService.getAllDurableCqsFromServer();
} catch (CqException e) {
fail("failed", e);
}
assertEquals(4, list.size());
assertTrue(list.contains("client1DCQ1"));
assertTrue(list.contains("client1DCQ2"));
assertTrue(list.contains("client1MoreDCQ1"));
assertTrue(list.contains("client1MoreDCQ2"));
}
});
client1.invoke(() -> CacheServerTestUtil.closeCache());
client2.invoke(() -> CacheServerTestUtil.closeCache());
server.invoke(() -> CacheServerTestUtil.closeCache());
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqDataUsingPoolDUnitTest method testEventsDuringQueryExecution.
/**
* Test for events created during the CQ query execution. When CQs are executed using
* executeWithInitialResults there may be possibility that the region changes during that time may
* not be reflected in the query result set thus making the query data and region data
* inconsistent.
*/
@Test
public void testEventsDuringQueryExecution() throws Exception {
final Host host = Host.getHost(0);
VM server = host.getVM(0);
final VM client = host.getVM(1);
final String cqName = "testEventsDuringQueryExecution_0";
cqDUnitTest.createServer(server);
final int port = server.invoke(() -> CqQueryUsingPoolDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server.getHost());
String poolName = "testEventsDuringQueryExecution";
cqDUnitTest.createPool(client, poolName, host0, port);
// create CQ.
cqDUnitTest.createCQ(client, poolName, cqName, cqDUnitTest.cqs[0]);
final int numObjects = 200;
final int totalObjects = 500;
// initialize Region.
server.invoke(new CacheSerializableRunnable("Update Region") {
@Override
public void run2() throws CacheException {
Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
for (int i = 1; i <= numObjects; i++) {
Portfolio p = new Portfolio(i);
region.put("" + i, p);
}
}
});
// First set testhook in executeWithInitialResults so that queued events
// are not drained before we verify there number.
client.invoke(setTestHook());
// Execute CQ while update is in progress.
AsyncInvocation executeCq = client.invokeAsync(new CacheSerializableRunnable("Execute CQ AsyncInvoke") {
@Override
public void run2() throws CacheException {
QueryService cqService = getCache().getQueryService();
// Get CqQuery object.
CqQuery cq1 = cqService.getCq(cqName);
if (cq1 == null) {
fail("Failed to get CQ " + cqName);
}
SelectResults cqResults = null;
try {
cqResults = cq1.executeWithInitialResults();
} catch (Exception ex) {
Assert.fail("CQ execution failed", ex);
}
// Check num of events received during executeWithInitialResults.
final TestHook testHook = CqQueryImpl.testHook;
Wait.waitForCriterion(new WaitCriterion() {
@Override
public boolean done() {
return testHook.numQueuedEvents() > 0;
}
@Override
public String description() {
return "No queued events found.";
}
}, 3000, 5, true);
getCache().getLogger().fine("Queued Events Size" + testHook.numQueuedEvents());
// Make sure CQEvents are queued during execute with initial results.
CqQueryTestListener cqListener = (CqQueryTestListener) cq1.getCqAttributes().getCqListener();
// Wait for the last key to arrive.
cqListener.waitForCreated("" + totalObjects);
// Check if the events from CqListener are in order.
int oldId = 0;
for (Object cqEvent : cqListener.events.toArray()) {
int newId = new Integer(cqEvent.toString()).intValue();
if (oldId > newId) {
fail("Queued events for CQ Listener during execution with " + "Initial results is not in the order in which they are created.");
}
oldId = newId;
}
// Check if all the IDs are present as part of Select Results and CQ Events.
HashSet ids = new HashSet(cqListener.events);
for (Object o : cqResults.asList()) {
Struct s = (Struct) o;
ids.add(s.get("key"));
}
HashSet missingIds = new HashSet();
String key = "";
for (int i = 1; i <= totalObjects; i++) {
key = "" + i;
if (!(ids.contains(key))) {
missingIds.add(key);
}
}
if (!missingIds.isEmpty()) {
fail("Missing Keys in either ResultSet or the Cq Event list. " + " Missing keys : [size : " + missingIds.size() + "]" + missingIds + " Ids in ResultSet and CQ Events :" + ids);
}
}
});
// Keep updating region (async invocation).
server.invoke(new CacheSerializableRunnable("Update Region") {
@Override
public void run2() throws CacheException {
Wait.pause(200);
client.invoke(new CacheSerializableRunnable("Releasing the latch") {
@Override
public void run2() throws CacheException {
// Now release the testhook so that CQListener can proceed.
final TestHook testHook = CqQueryImpl.testHook;
testHook.ready();
}
});
Region region = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
for (int i = numObjects + 1; i <= totalObjects; i++) {
Portfolio p = new Portfolio(i);
region.put("" + i, p);
}
}
});
// Close.
cqDUnitTest.closeClient(client);
cqDUnitTest.closeServer(server);
}
use of org.apache.geode.cache30.CacheSerializableRunnable 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.CacheSerializableRunnable in project geode by apache.
the class CqDataDUnitTest method testCQWithLoad.
/**
* Test for CQ when region is populated with net load.
*
* @throws Exception
*/
@Test
public void testCQWithLoad() throws Exception {
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client = host.getVM(2);
cqDUnitTest.createServer(server1, 0, false, MirrorType.KEYS_VALUES);
cqDUnitTest.createServer(server2, 0, false, MirrorType.KEYS);
final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
cqDUnitTest.createClient(client, port1, host0);
// Create CQs.
cqDUnitTest.createCQ(client, "testCQWithLoad_0", cqDUnitTest.cqs[0]);
cqDUnitTest.executeCQ(client, "testCQWithLoad_0", false, null);
Wait.pause(2 * 1000);
final int size = 10;
// CREATE VALUES.
cqDUnitTest.createValues(server2, cqDUnitTest.regions[0], size);
server1.invoke(new CacheSerializableRunnable("Load from second server") {
public void run2() throws CacheException {
Region region1 = getCache().getRegion("/root/" + cqDUnitTest.regions[0]);
for (int i = 1; i <= size; i++) {
region1.get(CqQueryDUnitTest.KEY + i);
}
}
});
for (int i = 1; i <= size; i++) {
cqDUnitTest.waitForCreated(client, "testCQWithLoad_0", CqQueryDUnitTest.KEY + i);
}
cqDUnitTest.validateCQ(client, "testCQWithLoad_0", CqQueryDUnitTest.noTest, size, 0, 0);
// Close.
cqDUnitTest.closeClient(client);
cqDUnitTest.closeServer(server1);
cqDUnitTest.closeServer(server2);
}
use of org.apache.geode.cache30.CacheSerializableRunnable in project geode by apache.
the class CqDataDUnitTest method testCQWithDestroysAndInvalidates.
/**
* Tests propogation of invalidates and destorys to the clients. Bug 37242.
*
* @throws Exception
*/
@Test
public void testCQWithDestroysAndInvalidates() throws Exception {
final Host host = Host.getHost(0);
VM server = host.getVM(0);
VM client = host.getVM(1);
VM producer = host.getVM(2);
cqDUnitTest.createServer(server, 0, true);
final int port = server.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server.getHost());
// Create client.
cqDUnitTest.createClient(client, port, host0);
// producer is not doing any thing.
cqDUnitTest.createClient(producer, port, host0);
final int size = 10;
final String name = "testQuery_4";
cqDUnitTest.createValues(server, cqDUnitTest.regions[0], size);
cqDUnitTest.createCQ(client, name, cqDUnitTest.cqs[4]);
cqDUnitTest.executeCQ(client, name, true, null);
// do destroys and invalidates.
server.invoke(new CacheSerializableRunnable("Create values") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(cqDUnitTest.regions[0]);
for (int i = 1; i <= 5; i++) {
region1.destroy(CqQueryDUnitTest.KEY + i);
}
}
});
for (int i = 1; i <= 5; i++) {
cqDUnitTest.waitForDestroyed(client, name, CqQueryDUnitTest.KEY + i);
}
// recreate the key values from 1 - 5
cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 5);
// wait for all creates to arrive.
for (int i = 1; i <= 5; i++) {
cqDUnitTest.waitForCreated(client, name, CqQueryDUnitTest.KEY + i);
}
// do more puts to push first five key-value to disk.
cqDUnitTest.createValues(server, cqDUnitTest.regions[0], 10);
// do invalidates on fisrt five keys.
server.invoke(new CacheSerializableRunnable("Create values") {
public void run2() throws CacheException {
Region region1 = getRootRegion().getSubregion(cqDUnitTest.regions[0]);
for (int i = 1; i <= 5; i++) {
region1.invalidate(CqQueryDUnitTest.KEY + i);
}
}
});
// wait for invalidates now.
for (int i = 1; i <= 5; i++) {
cqDUnitTest.waitForInvalidated(client, name, CqQueryDUnitTest.KEY + i);
}
// Close.
cqDUnitTest.closeClient(client);
cqDUnitTest.closeServer(server);
}
Aggregations