use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class OffHeapRegionBase method keep_testOutOfOffHeapMemoryErrorClosesCache.
public void keep_testOutOfOffHeapMemoryErrorClosesCache() {
// this test is redundant but may be useful
final GemFireCacheImpl gfc = createCache();
try {
MemoryAllocator ma = gfc.getOffHeapStore();
assertNotNull(ma);
final long offHeapSize = ma.getFreeMemory();
assertEquals(0, ma.getUsedMemory());
StoredObject mc1 = ma.allocate(64);
assertEquals(64 + perObjectOverhead(), ma.getUsedMemory());
assertEquals(offHeapSize - (64 + perObjectOverhead()), ma.getFreeMemory());
mc1.release();
assertEquals(offHeapSize, ma.getFreeMemory());
assertEquals(0, ma.getUsedMemory());
// do an allocation larger than the slab size
try {
ma.allocate(1024 * 1024 * 10);
fail("Expected an out of heap exception");
} catch (OutOfOffHeapMemoryException expected) {
// passed
}
assertEquals(0, ma.getUsedMemory());
final WaitCriterion waitForDisconnect = new WaitCriterion() {
public boolean done() {
return gfc.isClosed();
}
public String description() {
return "Waiting for disconnect to complete";
}
};
org.apache.geode.test.dunit.Wait.waitForCriterion(waitForDisconnect, 10 * 1000, 100, true);
assertTrue(gfc.isClosed());
} finally {
closeCache(gfc, false);
}
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class CliUtilDUnitTest method startManager.
private void startManager() {
final ManagementService service = ManagementService.getManagementService(getCache());
service.startManager();
assertEquals(true, service.isManager());
assertNotNull(service.getManagerMXBean());
assertTrue(service.getManagerMXBean().isRunning());
final WaitCriterion waitForMaangerMBean = new WaitCriterion() {
@Override
public boolean done() {
boolean flag = checkBean(COMMON_REGION, 4) && checkBean(COMMON_REGION_GROUP1, 2) && checkBean(COMMON_REGION_GROUP2, 2) && checkBean(REGION_MEMBER1_GROUP1, 1) && checkBean(REGION_MEMBER2_GROUP1, 1) && checkBean(REGION_MEMBER1_GROUP2, 1) && checkBean(REGION_MEMBER2_GROUP2, 1);
if (!flag) {
LogWriterUtils.getLogWriter().info("Still probing for mbeans");
return false;
} else {
LogWriterUtils.getLogWriter().info("All distributed region mbeans are federated to manager.");
return true;
}
}
private boolean checkBean(String string, int memberCount) {
DistributedRegionMXBean bean2 = service.getDistributedRegionMXBean(Region.SEPARATOR + string);
LogWriterUtils.getLogWriter().info("DistributedRegionMXBean for region=" + string + " is " + bean2);
if (bean2 == null)
return false;
else {
int members = bean2.getMemberCount();
LogWriterUtils.getLogWriter().info("DistributedRegionMXBean for region=" + string + " is aggregated for " + memberCount + " expected count=" + memberCount);
if (members < memberCount) {
return false;
} else {
return true;
}
}
}
@Override
public String description() {
return "Probing for ManagerMBean";
}
};
Wait.waitForCriterion(waitForMaangerMBean, 120000, 2000, true);
LogWriterUtils.getLogWriter().info("Manager federation is complete");
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class QueueCommandsDUnitTest method testCreateUpdatesSharedConfig.
/**
* Asserts that creating async event queues correctly updates the shared configuration.
*/
// GEODE-1976
@Category(FlakyTest.class)
@Test
public void testCreateUpdatesSharedConfig() throws IOException {
disconnectAllFromDS();
final int[] ports = AvailablePortHelper.getRandomAvailableTCPPorts(2);
jmxPort = ports[0];
httpPort = ports[1];
try {
jmxHost = InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException ignore) {
jmxHost = "localhost";
}
final String queueName = "testAsyncEventQueueQueue";
final String groupName = "testAsyncEventQueueSharedConfigGroup";
final Properties locatorProps = new Properties();
locatorProps.setProperty(NAME, "Locator");
locatorProps.setProperty(MCAST_PORT, "0");
locatorProps.setProperty(LOG_LEVEL, "fine");
locatorProps.setProperty(ENABLE_CLUSTER_CONFIGURATION, "true");
locatorProps.setProperty(JMX_MANAGER, "true");
locatorProps.setProperty(JMX_MANAGER_START, "true");
locatorProps.setProperty(JMX_MANAGER_BIND_ADDRESS, String.valueOf(jmxHost));
locatorProps.setProperty(JMX_MANAGER_PORT, String.valueOf(jmxPort));
locatorProps.setProperty(HTTP_SERVICE_PORT, String.valueOf(httpPort));
// Start the Locator and wait for shared configuration to be available
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
final File locatorLogFile = new File("locator-" + locatorPort + ".log");
try {
final InternalLocator locator = (InternalLocator) Locator.startLocatorAndDS(locatorPort, locatorLogFile, null, locatorProps);
WaitCriterion wc = new WaitCriterion() {
@Override
public boolean done() {
return locator.isSharedConfigurationRunning();
}
@Override
public String description() {
return "Waiting for shared configuration to be started";
}
};
waitForCriterion(wc, 5000, 500, true);
} catch (IOException ioex) {
fail("Unable to create a locator with a shared configuration");
}
}
});
connect(jmxHost, jmxPort, httpPort, getDefaultShell());
// Create a cache in VM 1
VM vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
getSystem(localProps);
assertNotNull(getCache());
}
});
// Deploy a JAR file with an AsyncEventListener that can be instantiated on each server
final File jarFile = new File(new File(".").getAbsolutePath(), "QueueCommandsDUnit.jar");
QueueCommandsDUnitTest.this.filesToBeDeleted.add(jarFile.getAbsolutePath());
ClassBuilder classBuilder = new ClassBuilder();
byte[] jarBytes = classBuilder.createJarFromClassContent("com/qcdunit/QueueCommandsDUnitTestListener", "package com.qcdunit;" + "import java.util.List; import java.util.Properties;" + "import org.apache.geode.internal.cache.xmlcache.Declarable2; import org.apache.geode.cache.asyncqueue.AsyncEvent;" + "import org.apache.geode.cache.asyncqueue.AsyncEventListener;" + "public class QueueCommandsDUnitTestListener implements Declarable2, AsyncEventListener {" + "Properties props;" + "public boolean processEvents(List<AsyncEvent> events) { return true; }" + "public void close() {}" + "public void init(final Properties props) {this.props = props;}" + "public Properties getConfig() {return this.props;}}");
writeJarBytesToFile(jarFile, jarBytes);
CommandResult cmdResult = executeCommand("deploy --jar=QueueCommandsDUnit.jar");
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Test creating the queue
CommandStringBuilder commandStringBuilder = new CommandStringBuilder(CliStrings.CREATE_ASYNC_EVENT_QUEUE);
commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__ID, queueName);
commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__GROUP, groupName);
commandStringBuilder.addOption(CliStrings.CREATE_ASYNC_EVENT_QUEUE__LISTENER, "com.qcdunit.QueueCommandsDUnitTestListener");
cmdResult = executeCommand(commandStringBuilder.toString());
assertEquals(Result.Status.OK, cmdResult.getStatus());
// Make sure the queue exists in the shared config
Host.getHost(0).getVM(0).invoke(new SerializableRunnable() {
@Override
public void run() {
ClusterConfigurationService sharedConfig = ((InternalLocator) Locator.getLocator()).getSharedConfiguration();
String xmlFromConfig;
try {
xmlFromConfig = sharedConfig.getConfiguration(groupName).getCacheXmlContent();
assertTrue(xmlFromConfig.contains(queueName));
} catch (Exception e) {
fail("Error occurred in cluster configuration service", e);
}
}
});
// Close cache in the vm1 and restart it to get the shared configuration
vm = Host.getHost(0).getVM(1);
vm.invoke(new SerializableRunnable() {
@Override
public void run() {
Cache cache = getCache();
assertNotNull(cache);
cache.close();
assertTrue(cache.isClosed());
Properties localProps = new Properties();
localProps.setProperty(MCAST_PORT, "0");
localProps.setProperty(LOCATORS, "localhost[" + locatorPort + "]");
localProps.setProperty(GROUPS, groupName);
localProps.setProperty(USE_CLUSTER_CONFIGURATION, "true");
getSystem(localProps);
cache = getCache();
assertNotNull(cache);
AsyncEventQueue aeq = cache.getAsyncEventQueue(queueName);
assertNotNull(aeq);
}
});
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class DiskRegionDUnitTest method testRemoteUpdates.
/**
* Makes sure that updates from other VMs cause existing entries to be written to disk.
*/
@Test
public void testRemoteUpdates() throws Exception {
final String name = this.getUniqueName();
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_NO_ACK);
factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(2, null, EvictionAction.OVERFLOW_TO_DISK));
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
dsf.setDiskDirs(new File[] { d });
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
createRegion(name, factory.create());
}
};
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(create);
vm1.invoke(create);
vm0.invoke(new CacheSerializableRunnable("Fill Region") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// DiskRegion dr = region.getDiskRegion();
LRUStatistics lruStats = getLRUStats(region);
int i;
for (i = 0; lruStats.getEvictions() <= 0; i++) {
region.put(new Integer(i), new short[250]);
}
assertTrue(i > 5);
}
});
vm1.invoke(new CacheSerializableRunnable("Update Region") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// LRUStatistics lruStats = getLRUStats(region);
for (int i = 0; i < 10; i++) {
region.put(new Integer(i), new int[250]);
}
}
});
vm0.invoke(new CacheSerializableRunnable("Verify overflow") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// DiskRegion dr = region.getDiskRegion();
final LRUStatistics lruStats = getLRUStats(region);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return lruStats.getEvictions() > 6;
}
public String description() {
return "waiting for evictions to exceed 6";
}
};
Wait.waitForCriterion(ev, 5 * 1000, 200, true);
// DiskRegionStats diskStats = dr.getStats();
// assertTrue(diskStats.getWrites() > 6);
}
});
vm0.invoke(new CacheSerializableRunnable("Populate with byte[]") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// LRUStatistics lruStats = getLRUStats(region);
for (int i = 0; i < 10000; i++) {
region.put(String.valueOf(i), String.valueOf(i).getBytes());
}
}
});
vm1.invoke(new CacheSerializableRunnable("Get with byte[]") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// LRUStatistics lruStats = getLRUStats(region);
for (int i = 0; i < 10000; i++) {
byte[] bytes = (byte[]) region.get(String.valueOf(i));
assertEquals(String.valueOf(i), new String(bytes));
}
}
});
}
use of org.apache.geode.test.dunit.WaitCriterion in project geode by apache.
the class DiskRegionDUnitTest method testDistributedInvalidate.
/**
* Tests that invalidates and updates received from different VMs are handled appropriately by
* overflow regions.
*/
@Test
public void testDistributedInvalidate() throws Exception {
final String name = this.getUniqueName();
SerializableRunnable create = new CacheSerializableRunnable("Create region") {
public void run2() throws CacheException {
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
factory.setEarlyAck(false);
factory.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(100, EvictionAction.OVERFLOW_TO_DISK));
File d = new File("DiskRegions" + OSProcess.getId());
d.mkdirs();
DiskStoreFactory dsf = getCache().createDiskStoreFactory();
dsf.setDiskDirs(new File[] { d });
DiskStore ds = dsf.create(name);
factory.setDiskStoreName(ds.getName());
createRegion(name, factory.create());
}
};
Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
vm0.invoke(create);
vm1.invoke(create);
vm0.invoke(new CacheSerializableRunnable("Fill Region") {
public void run2() throws CacheException {
LocalRegion region = (LocalRegion) getRootRegion().getSubregion(name);
// DiskRegion dr = region.getDiskRegion();
LRUStatistics lruStats = getLRUStats(region);
for (int i = 0; lruStats.getEvictions() < 10; i++) {
LogWriterUtils.getLogWriter().info("Put " + i);
region.put(new Integer(i), new byte[1]);
}
assertEquals(10, lruStats.getEvictions());
}
});
final Object key = new Integer(20);
vm1.invoke(new CacheSerializableRunnable("Invalidate entry") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
assertNotNull(region.get(key));
region.invalidate(key);
}
});
vm0.invoke(new CacheSerializableRunnable("Verify invalidate") {
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return region.get(key) == null;
}
public String description() {
return "value for key remains: " + key;
}
};
Wait.waitForCriterion(ev, 500, 200, true);
}
});
final String newValue = "NEW VALUE";
vm1.invoke(new CacheSerializableRunnable("Update entry") {
public void run2() throws CacheException {
Region region = getRootRegion().getSubregion(name);
region.put(key, newValue);
}
});
vm0.invoke(new CacheSerializableRunnable("Verify update") {
public void run2() throws CacheException {
final Region region = getRootRegion().getSubregion(name);
WaitCriterion ev = new WaitCriterion() {
public boolean done() {
return newValue.equals(region.get(key));
}
public String description() {
return "verify update";
}
};
Wait.waitForCriterion(ev, 500, 200, true);
}
});
}
Aggregations