use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class DistrbutedRegionProfileOffHeapDUnitTest method testPartitionedRegionProfileWithConflict.
/**
* Asserts that creating a region on two members, with one member having the region as on-heap and
* the other as having the region as off-heap, will cause an exception and the region will not be
* created.
*/
@Test
public void testPartitionedRegionProfileWithConflict() throws Exception {
final String regionName = getTestMethodName() + "Region";
Host.getHost(0).getVM(0).invoke(new CacheSerializableRunnable("createRegionNoException") {
private static final long serialVersionUID = 1L;
@Override
public void run2() throws CacheException {
disconnectFromDS();
Properties properties = new Properties();
properties.put(OFF_HEAP_MEMORY_SIZE, "2m");
getSystem(properties);
GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
regionFactory.setOffHeap(true);
Region region = regionFactory.create(regionName);
assertNotNull("Region is null", region);
assertNotNull("Cache does not contain region", cache.getRegion(regionName));
}
});
Host.getHost(0).getVM(1).invoke(new CacheSerializableRunnable("createRegionException") {
private static final long serialVersionUID = 1L;
@SuppressWarnings("synthetic-access")
@Override
public void run2() throws CacheException {
disconnectFromDS();
final GemFireCacheImpl cache = (GemFireCacheImpl) getCache();
final RegionFactory regionFactory = cache.createRegionFactory(RegionShortcut.PARTITION);
Region region = null;
try {
IgnoredException.addIgnoredException("IllegalStateException");
region = regionFactory.create(regionName);
fail("Expected exception upon creation with invalid off-heap state");
} catch (IllegalStateException expected) {
// An exception is expected.
} finally {
removeExceptionTag1("IllegalStateException");
}
assertNull("Region is not null", region);
assertNull("Cache contains region", cache.getRegion(regionName));
}
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class RemoteTransactionDUnitTest method testExpirySuspend_bug45984.
@Test
public void testExpirySuspend_bug45984() {
Host host = Host.getHost(0);
VM vm1 = host.getVM(0);
VM vm2 = host.getVM(1);
final String regionName = getName();
// create region with expiration
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
System.setProperty(LocalRegion.EXPIRY_MS_PROPERTY, "true");
try {
RegionFactory<String, String> rf = getCache().createRegionFactory();
rf.setEntryTimeToLive(new ExpirationAttributes(1, ExpirationAction.LOCAL_DESTROY));
rf.setScope(Scope.DISTRIBUTED_ACK);
rf.create(regionName);
} finally {
System.getProperties().remove(LocalRegion.EXPIRY_MS_PROPERTY);
}
return null;
}
});
// create replicate region
vm2.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
getCache().createRegionFactory(RegionShortcut.REPLICATE).create(regionName);
return null;
}
});
vm1.invoke(new SerializableCallable() {
@Override
public Object call() throws Exception {
final Region<String, String> r = getCache().getRegion(regionName);
WaitCriterion wc2 = new WaitCriterion() {
@Override
public boolean done() {
return !r.containsKey("key") && !r.containsKey("nonTXKey");
}
@Override
public String description() {
return "did not expire containsKey(key)=" + r.containsKey("key") + " r.containsKey(nonTXKey)=" + r.containsKey("nonTXKey");
}
};
ExpiryTask.suspendExpiration();
Region.Entry entry = null;
long tilt;
try {
r.put("key", "value");
LocalRegion lr = (LocalRegion) r;
r.put("nonTXkey", "nonTXvalue");
getCache().getCacheTransactionManager().begin();
r.put("key", "newvalue");
TXExpiryJUnitTest.waitForEntryExpiration(lr, "key");
} finally {
ExpiryTask.permitExpiration();
}
TransactionId tx = getCache().getCacheTransactionManager().suspend();
// A remote tx will allow expiration to happen on the side that
// is not hosting the tx. But it will not allow an expiration
// initiated on the hosting jvm.
// tx is hosted in vm2 so expiration can happen in vm1.
Wait.waitForCriterion(wc2, 30000, 5, true);
getCache().getCacheTransactionManager().resume(tx);
assertTrue(r.containsKey("key"));
getCache().getCacheTransactionManager().commit();
Wait.waitForCriterion(wc2, 30000, 5, true);
return null;
}
});
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class PersistentPartitionedRegionDUnitTest method testOverflowCacheClose.
/**
* This test is in here just to test to make sure that we don't get a suspect string with an
* exception during cache closure.
*/
@Test
public void testOverflowCacheClose() {
Cache cache = getCache();
RegionFactory rf = new RegionFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
rf.setPartitionAttributes(paf.create());
rf.setDataPolicy(DataPolicy.PARTITION);
rf.setEvictionAttributes(EvictionAttributes.createLRUEntryAttributes(50, EvictionAction.OVERFLOW_TO_DISK));
rf.setDiskDirs(getDiskDirs());
Region region = rf.create(PR_REGION_NAME);
region.get(0);
cache.getDistributedSystem().disconnect();
// cache.close();
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class CliUtilDUnitTest method createRegion.
@SuppressWarnings("rawtypes")
private Region createRegion(String regionName) {
RegionFactory regionFactory = getCache().createRegionFactory(RegionShortcut.REPLICATE);
Region region = regionFactory.create(regionName);
final ManagementService service = ManagementService.getManagementService(getCache());
assertNotNull(service.getMemberMXBean());
RegionMXBean bean = service.getLocalRegionMBean(Region.SEPARATOR + regionName);
assertNotNull(bean);
LogWriterUtils.getLogWriter().info("Created region=" + regionName + " Bean=" + bean);
return region;
}
use of org.apache.geode.cache.RegionFactory in project geode by apache.
the class MyGatewayEventSubstitutionFilter method createReplicatedRegionWithCacheLoaderAndAsyncEventQueue.
public static void createReplicatedRegionWithCacheLoaderAndAsyncEventQueue(String regionName, String asyncQueueIds) {
AttributesFactory fact = new AttributesFactory();
addAsyncEventQueueIds(fact, asyncQueueIds);
fact.setDataPolicy(DataPolicy.REPLICATE);
// set the CacheLoader
fact.setCacheLoader(new MyCacheLoader());
RegionFactory regionFactory = cache.createRegionFactory(fact.create());
Region r = regionFactory.create(regionName);
assertNotNull(r);
}
Aggregations