use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class RemoveAllMultiVmDUnitTest method createCache.
public static void createCache() {
try {
ds = (new RemoveAllMultiVmDUnitTest()).getSystem(props);
cache = CacheFactory.create(ds);
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.DISTRIBUTED_ACK);
RegionAttributes attr = factory.create();
region = cache.createRegion("map", attr);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class RegionTestCase method testCloseRegion.
/**
* Tests closing a region, and checks different behavior when this is a disk region with
* persistBackup.
*/
@Test
public void testCloseRegion() throws CacheException {
// @todo added a remote region to make sure close just does a localDestroy
String name = this.getUniqueName();
AttributesFactory fac = new AttributesFactory(getRegionAttributes());
TestCacheListener list = new TestCacheListener() {
public void afterCreate2(EntryEvent event) {
// do nothing
}
public void afterRegionDestroy2(RegionEvent re) {
assertEquals(Operation.REGION_CLOSE, re.getOperation());
}
public void close2() {
// okay
}
};
fac.setCacheListener(list);
RegionAttributes attrs = fac.create();
Region region = createRegion(name, attrs);
File diskDir = null;
if (attrs.getDataPolicy().withPersistence()) {
diskDir = getCache().findDiskStore(attrs.getDiskStoreName()).getDiskDirs()[0];
// @todo We no longer start with a clean slate because the DiskStore hangs around.
// If we want a clean slate then we need to destroy the DiskStore after each
// test completes.
// assert that if this is a disk region, the disk dirs are empty
// to make sure we start with a clean slate
getCache().getLogger().info("list=" + Arrays.toString(diskDir.list()));
// assertIndexDetailsEquals("list="+Arrays.toString(diskDir.list()),
// 0, diskDir.list().length);
}
for (int i = 0; i < 1000; i++) {
region.put(new Integer(i), String.valueOf(i));
}
// reset wasInvoked after creates
assertTrue(list.wasInvoked());
// assert that if this is a disk region, the disk dirs are not empty
if (attrs.getDataPolicy().withPersistence()) {
assertTrue(diskDir.list().length > 0);
}
boolean persistent = region.getAttributes().getDataPolicy().withPersistence();
region.close();
// assert that if this is a disk region, the disk dirs are not empty
if (attrs.getDataPolicy().withPersistence()) {
assertTrue(diskDir.list().length > 0);
}
assertTrue(list.waitForInvocation(333));
assertTrue(list.isClosed());
assertTrue(region.isDestroyed());
// if (persistent) {
// // remove this when bug #41049 is fixed
// return;
// }
// if this is a disk region, then check to see if recreating the region
// repopulates with data
region = createRegion(name, attrs);
if (attrs.getDataPolicy().withPersistence()) {
for (int i = 0; i < 1000; i++) {
Region.Entry entry = region.getEntry(new Integer(i));
assertNotNull("entry " + i + " not found", entry);
assertEquals(String.valueOf(i), entry.getValue());
}
assertEquals(1000, region.keySet().size());
} else {
assertEquals(0, region.keySet().size());
}
region.localDestroyRegion();
}
use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class RegionTestCase method testEntryTtl3.
/**
* Configure entry expiration with a ttl time. Create an entry and records its scheduled
* expiration time. Then mutate the region expiration configuration and confirm that the entry's
* expiration time is rescheduled.
*/
@Test
public void testEntryTtl3() {
final String name = this.getUniqueName();
// test no longer waits for this expiration to happen
// ms
final int timeout1 = 500 * 1000;
// ms
final int timeout2 = 2000 * 1000;
final String key1 = "KEY1";
final String value1 = "VALUE1";
AttributesFactory factory = new AttributesFactory(getRegionAttributes());
ExpirationAttributes expire1 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
factory.setEntryTimeToLive(expire1);
factory.setStatisticsEnabled(true);
TestCacheListener list = new TestCacheListener() {
public void afterCreate2(EntryEvent e) {
}
public void afterUpdate2(EntryEvent e) {
}
public void afterInvalidate2(EntryEvent e) {
eventCount++;
}
};
eventCount = 0;
factory.addCacheListener(list);
RegionAttributes attrs = factory.create();
LocalRegion region;
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
region = (LocalRegion) createRegion(name, attrs);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
region.create(key1, value1);
EntryExpiryTask eet = region.getEntryExpiryTask(key1);
final long firstExpiryTime = eet.getExpirationTime();
AttributesMutator mutt = region.getAttributesMutator();
ExpirationAttributes expire2 = new ExpirationAttributes(timeout2, ExpirationAction.INVALIDATE);
mutt.setEntryTimeToLive(expire2);
eet = region.getEntryExpiryTask(key1);
final long secondExpiryTime = eet.getExpirationTime();
if ((secondExpiryTime - firstExpiryTime) <= 0) {
fail("expiration time should have been greater after changing region config from 500 to 2000. firstExpiryTime=" + firstExpiryTime + " secondExpiryTime=" + secondExpiryTime);
}
// now set back to be more recent
mutt = region.getAttributesMutator();
ExpirationAttributes expire3 = new ExpirationAttributes(timeout1, ExpirationAction.INVALIDATE);
mutt.setEntryTimeToLive(expire3);
eet = region.getEntryExpiryTask(key1);
final long thirdExpiryTime = eet.getExpirationTime();
assertEquals(firstExpiryTime, thirdExpiryTime);
// confirm that it still has not expired
assertEquals(0, eventCount);
// now set it to a really short time and make sure it expires immediately
Wait.waitForExpiryClockToChange(region);
final Region.Entry entry = region.getEntry(key1);
mutt = region.getAttributesMutator();
ExpirationAttributes expire4 = new ExpirationAttributes(1, ExpirationAction.INVALIDATE);
mutt.setEntryTimeToLive(expire4);
WaitCriterion wc = new WaitCriterion() {
public boolean done() {
return fetchEntryValue(entry) == null;
}
public String description() {
return "entry never became invalid";
}
};
Wait.waitForCriterion(wc, 10 * 1000, 10, true);
WaitCriterion waitForEventCountToBeOne = new WaitCriterion() {
public boolean done() {
return eventCount == 1;
}
public String description() {
return "eventCount never became 1";
}
};
Wait.waitForCriterion(waitForEventCountToBeOne, 10 * 1000, 10, true);
eventCount = 0;
}
use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class RemoveAllMultiVmDUnitTest method createMirroredRegion.
// end of createCache
public static void createMirroredRegion() {
try {
AttributesFactory factory = new AttributesFactory();
factory.setDataPolicy(DataPolicy.REPLICATE);
factory.setScope(Scope.DISTRIBUTED_ACK);
RegionAttributes attr = factory.create();
mirroredRegion = cache.createRegion("mirrored", attr);
} catch (Exception ex) {
ex.printStackTrace();
}
}
use of org.apache.geode.cache.RegionAttributes in project geode by apache.
the class DeltaPropagationDUnitTest method createDurableCacheClient.
public static void createDurableCacheClient(Pool poolAttr, String regionName, Properties dsProperties, Integer listenerCode, Boolean close) throws Exception {
new DeltaPropagationDUnitTest().createCache(dsProperties);
PoolFactoryImpl pf = (PoolFactoryImpl) PoolManager.createFactory();
pf.init(poolAttr);
PoolImpl p = (PoolImpl) pf.create("DeltaPropagationDUnitTest");
AttributesFactory factory = new AttributesFactory();
factory.setScope(Scope.LOCAL);
factory.setConcurrencyChecksEnabled(false);
factory.setPoolName(p.getName());
if (listenerCode.intValue() != 0) {
factory.addCacheListener(getCacheListener(listenerCode));
}
RegionAttributes attrs = factory.create();
Region r = cache.createRegion(regionName, attrs);
r.registerInterest("ALL_KEYS");
pool = p;
cache.readyForEvents();
logger = cache.getLogger();
closeCache = close.booleanValue();
}
Aggregations