use of org.apache.geode.cache.Cache in project geode by apache.
the class CacheXmlGeode10DUnitTest method testAsyncEventQueueIsForwardExpirationDestroyAttribute.
@SuppressWarnings("rawtypes")
@Test
public void testAsyncEventQueueIsForwardExpirationDestroyAttribute() throws Exception {
final String regionName = this.testName.getMethodName();
// Create AsyncEventQueue with Listener
final CacheCreation cache = new CacheCreation();
AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
AsyncEventListener listener = new MyAsyncEventListenerGeode10();
// Test for default forwardExpirationDestroy attribute value (which is false)
String aeqId1 = "aeqWithDefaultFED";
factory.create(aeqId1, listener);
AsyncEventQueue aeq1 = cache.getAsyncEventQueue(aeqId1);
assertFalse(aeq1.isForwardExpirationDestroy());
// Test by setting forwardExpirationDestroy attribute value.
String aeqId2 = "aeqWithFEDsetToTrue";
factory.setForwardExpirationDestroy(true);
factory.create(aeqId2, listener);
AsyncEventQueue aeq2 = cache.getAsyncEventQueue(aeqId2);
assertTrue(aeq2.isForwardExpirationDestroy());
// Create region and set the AsyncEventQueue
final RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.addAsyncEventQueueId(aeqId2);
final Region regionBefore = cache.createRegion(regionName, attrs);
assertNotNull(regionBefore);
assertTrue(regionBefore.getAttributes().getAsyncEventQueueIds().size() == 1);
testXml(cache);
final Cache c = getCache();
assertNotNull(c);
aeq1 = c.getAsyncEventQueue(aeqId1);
assertFalse(aeq1.isForwardExpirationDestroy());
aeq2 = c.getAsyncEventQueue(aeqId2);
assertTrue(aeq2.isForwardExpirationDestroy());
final Region regionAfter = c.getRegion(regionName);
assertNotNull(regionAfter);
assertTrue(regionAfter.getAttributes().getAsyncEventQueueIds().size() == 1);
regionAfter.localDestroyRegion();
// Clear AsyncEventQueues.
c.close();
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class CacheXml66DUnitTest method testDiskStoreInTemplates.
/**
* Tests that a region created with a named attributes with diskstore
*/
@Test
public void testDiskStoreInTemplates() throws Exception {
File dir = new File("west");
dir.mkdir();
dir.deleteOnExit();
dir = new File("east");
dir.mkdir();
dir.deleteOnExit();
setXmlFile(findFile("ewtest.xml"));
String regionName_west = "orders/west";
String regionName_east = "orders/east";
Cache cache = getCache();
// verify diskstores
DiskStore ds = cache.findDiskStore("persistentDiskStore1");
assertNotNull(ds);
assertEquals(500, ds.getQueueSize());
File[] dirs = ds.getDiskDirs();
assertEquals("west", dirs[0].getPath());
ds = cache.findDiskStore("persistentDiskStore2");
assertNotNull(ds);
assertEquals(500, ds.getQueueSize());
dirs = ds.getDiskDirs();
assertEquals("east", dirs[0].getPath());
// verify templates
assertNotNull(cache.getRegionAttributes("nack"));
RegionAttributes attrs = cache.getRegionAttributes("persistent");
assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy());
assertEquals(false, attrs.isDiskSynchronous());
assertEquals("persistentDiskStore1", attrs.getDiskStoreName());
Region region = cache.getRegion(regionName_west);
assertNotNull(region);
attrs = region.getAttributes();
assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy());
assertEquals(false, attrs.isDiskSynchronous());
assertEquals("persistentDiskStore1", attrs.getDiskStoreName());
region = cache.getRegion(regionName_east);
assertNotNull(region);
// Make sure that attributes can be "overridden"
attrs = region.getAttributes();
assertEquals(DataPolicy.PERSISTENT_REPLICATE, attrs.getDataPolicy());
assertEquals(false, attrs.isDiskSynchronous());
assertEquals("persistentDiskStore2", attrs.getDiskStoreName());
// bug 41934
String regionName_datap = "data-p";
region = cache.getRegion(regionName_datap);
assertNotNull(region);
attrs = region.getAttributes();
PartitionAttributes pa = attrs.getPartitionAttributes();
assertEquals(1, pa.getRedundantCopies());
assertEquals(3, pa.getTotalNumBuckets());
assertEquals(DataPolicy.PERSISTENT_PARTITION, attrs.getDataPolicy());
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class CacheXml66DUnitTest method testPartitionedRegionAttributesForCoLocation.
@Test
public void testPartitionedRegionAttributesForCoLocation() throws Exception {
closeCache();
CacheCreation cache = new CacheCreation();
RegionAttributesCreation custAttrs = new RegionAttributesCreation(cache);
RegionAttributesCreation orderAttrs = new RegionAttributesCreation(cache);
PartitionAttributesFactory custPaf = new PartitionAttributesFactory();
PartitionAttributesFactory orderPaf = new PartitionAttributesFactory();
custPaf.setRedundantCopies(1);
custPaf.setTotalMaxMemory(500);
custPaf.setLocalMaxMemory(100);
custAttrs.setPartitionAttributes(custPaf.create());
cache.createRegion("Customer", custAttrs);
orderPaf.setRedundantCopies(1);
orderPaf.setTotalMaxMemory(500);
orderPaf.setLocalMaxMemory(100);
orderPaf.setColocatedWith("Customer");
orderAttrs.setPartitionAttributes(orderPaf.create());
cache.createRegion("Order", orderAttrs);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region cust = c.getRegion(Region.SEPARATOR + "Customer");
assertNotNull(cust);
Region order = c.getRegion(Region.SEPARATOR + "Order");
assertNotNull(order);
String coLocatedRegion = order.getAttributes().getPartitionAttributes().getColocatedWith();
assertEquals("Customer", coLocatedRegion);
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class CacheXml70DUnitTest method testAsyncEventQueue.
@Test
public void testAsyncEventQueue() throws Exception {
getSystem();
CacheCreation cache = new CacheCreation();
String id = "WBCLChannel";
AsyncEventQueueFactory factory = cache.createAsyncEventQueueFactory();
factory.setBatchSize(100);
factory.setBatchTimeInterval(500);
factory.setBatchConflationEnabled(true);
factory.setMaximumQueueMemory(200);
factory.setDiskSynchronous(true);
factory.setParallel(false);
factory.setDispatcherThreads(19);
AsyncEventListener eventListener = new MyAsyncEventListener();
AsyncEventQueue asyncEventQueue = factory.create(id, eventListener);
RegionAttributesCreation attrs = new RegionAttributesCreation();
attrs.addAsyncEventQueueId(asyncEventQueue.getId());
cache.createRegion("UserRegion", attrs);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Set<AsyncEventQueue> asyncEventQueuesOnCache = c.getAsyncEventQueues();
assertTrue("Size of asyncEventQueues should be greater than 0", asyncEventQueuesOnCache.size() > 0);
for (AsyncEventQueue asyncEventQueueOnCache : asyncEventQueuesOnCache) {
validateAsyncEventQueue(asyncEventQueue, asyncEventQueueOnCache);
}
}
use of org.apache.geode.cache.Cache in project geode by apache.
the class DistributedSystemDUnitTest method testIsolatedDistributedSystem.
@Test
public void testIsolatedDistributedSystem() throws Exception {
Properties config = createLonerConfig();
InternalDistributedSystem system = getSystem(config);
// make sure isolated distributed system can still create a cache and region
Cache cache = CacheFactory.create(system);
Region region = cache.createRegion(getUniqueName(), new AttributesFactory().create());
region.put("test", "value");
assertThat(region.get("test")).isEqualTo("value");
}
Aggregations