use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class CqQueryDUnitTest method testForSupportedRegionAttributes.
/**
* Tests execution of queries with NULL in where clause like where ID = NULL etc.
*
* @throws Exception
*/
@Test
public void testForSupportedRegionAttributes() throws Exception {
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
VM client = host.getVM(2);
// Create server with Global scope.
SerializableRunnable createServer = new CacheSerializableRunnable("Create Cache Server") {
public void run2() throws CacheException {
LogWriterUtils.getLogWriter().info("### Create Cache Server. ###");
// Create region with Global scope
AttributesFactory factory1 = new AttributesFactory();
factory1.setScope(Scope.GLOBAL);
factory1.setMirrorType(MirrorType.KEYS_VALUES);
createRegion(regions[0], factory1.createRegionAttributes());
// Create region with non Global, distributed_ack scope
AttributesFactory factory2 = new AttributesFactory();
factory2.setScope(Scope.DISTRIBUTED_NO_ACK);
factory2.setMirrorType(MirrorType.KEYS_VALUES);
createRegion(regions[1], factory2.createRegionAttributes());
Wait.pause(2000);
try {
startBridgeServer(port, true);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
Wait.pause(2000);
}
};
server1.invoke(createServer);
server2.invoke(createServer);
final int port1 = server1.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
final String host0 = NetworkUtils.getServerHostName(server1.getHost());
final int thePort2 = server2.invoke(() -> CqQueryDUnitTest.getCacheServerPort());
// Create client.
createClient(client, new int[] { port1, thePort2 }, host0, "-1");
// Create CQ on region with GLOBAL SCOPE.
createCQ(client, "testForSupportedRegionAttributes_0", cqs[0]);
executeCQ(client, "testForSupportedRegionAttributes_0", false, null);
int size = 5;
createValues(server1, regions[0], size);
for (int i = 1; i <= size; i++) {
waitForCreated(client, "testForSupportedRegionAttributes_0", KEY + i);
}
// Create CQ on region with non GLOBAL, DISTRIBUTED_ACK SCOPE.
createCQ(client, "testForSupportedRegionAttributes_1", cqs[2]);
String errMsg = "The replicated region " + " specified in CQ creation does not have scope supported by CQ." + " The CQ supported scopes are DISTRIBUTED_ACK and GLOBAL.";
final String expectedErr = "Cq not registered on primary";
client.invoke(new CacheSerializableRunnable("Set expect") {
public void run2() {
getCache().getLogger().info("<ExpectedException action=add>" + expectedErr + "</ExpectedException>");
}
});
try {
executeCQ(client, "testForSupportedRegionAttributes_1", false, "CqException");
fail("The test should have failed with exception, " + errMsg);
} catch (Exception ex) {
// Expected.
} finally {
client.invoke(new CacheSerializableRunnable("Remove expect") {
public void run2() {
getCache().getLogger().info("<ExpectedException action=remove>" + expectedErr + "</ExpectedException>");
}
});
}
// Close.
closeClient(client);
closeServer(server1);
closeServer(server2);
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class CqQueryDUnitTest method createServer.
public void createServer(VM server, final int thePort, final boolean eviction, final MirrorType mirrorType) {
SerializableRunnable createServer = 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.setMirrorType(mirrorType);
// setting the eviction attributes.
if (eviction) {
EvictionAttributes evictAttrs = EvictionAttributes.createLRUEntryAttributes(100000, EvictionAction.OVERFLOW_TO_DISK);
factory.setEvictionAttributes(evictAttrs);
}
for (int i = 0; i < regions.length; i++) {
createRegion(regions[i], factory.createRegionAttributes());
}
Wait.pause(2000);
try {
startBridgeServer(thePort, true);
} catch (Exception ex) {
Assert.fail("While starting CacheServer", ex);
}
Wait.pause(2000);
}
};
server.invoke(createServer);
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PutAllCSDUnitTest method closeCache.
protected void closeCache(VM vm0) {
SerializableRunnable close = new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
cache.close();
}
};
vm0.invoke(close);
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class PutAllCSDUnitTest method closeCacheAsync.
protected void closeCacheAsync(VM vm0) {
SerializableRunnable close = new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
cache.close();
}
};
vm0.invokeAsync(close);
}
use of org.apache.geode.test.dunit.SerializableRunnable in project geode by apache.
the class QueryMonitorDUnitTest method testQueryExecutionLocallyAndCacheOp.
/**
* Tests query execution on local vm.
*/
@Test
public void testQueryExecutionLocallyAndCacheOp() throws Exception {
setup(2);
final Host host = Host.getHost(0);
VM server1 = host.getVM(0);
VM server2 = host.getVM(1);
final int numberOfEntries = 1000;
// Start server
// All
server1.invoke("Create BridgeServer", () -> configServer(20, "testQueryExecutionLocally"));
// the
// queries
// taking
// more
// than
// 20ms
// should
// be
// canceled
// by
// Query
// monitor.
server1.invoke("createRegion", () -> createRegion());
// All
server2.invoke("Create BridgeServer", () -> configServer(20, "testQueryExecutionLocally"));
// the
// queries
// taking
// more
// than
// 20ms
// should
// be
// canceled
// by
// Query
// monitor.
server2.invoke("createRegion", () -> createRegion());
// Initialize server regions.
server1.invoke("populatePortfolioRegions", () -> populatePortfolioRegions(numberOfEntries));
// Initialize server regions.
server2.invoke("populatePortfolioRegions", () -> populatePortfolioRegions(numberOfEntries));
// Execute server queries
SerializableRunnable executeQuery = new CacheSerializableRunnable("Execute queries") {
public void run2() throws CacheException {
try {
QueryService queryService = GemFireCacheImpl.getInstance().getQueryService();
String qStr = "SELECT DISTINCT * FROM /root/exampleRegion p, (SELECT DISTINCT pos FROM /root/exampleRegion x, x.positions.values pos" + " WHERE x.ID = p.ID) as itrX";
executeQuery(queryService, qStr);
// Create index and Perform cache op. Bug#44307
queryService.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", "/root/exampleRegion");
queryService.createIndex("statusIndex", IndexType.FUNCTIONAL, "status", "/root/exampleRegion");
Region exampleRegion = getRootRegion().getSubregion(exampleRegionName);
for (int i = (1 + 100); i <= (numberOfEntries + 200); i++) {
exampleRegion.put("" + i, new Portfolio(i));
}
} catch (Exception ex) {
Assert.fail("Exception creating the query service", ex);
}
}
};
server1.invoke(executeQuery);
server2.invoke(executeQuery);
stopServer(server1);
stopServer(server2);
}
Aggregations