use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class Bug40632DUnitTest method testLocalDestroyTimeToLive.
@Test
public void testLocalDestroyTimeToLive() throws Exception {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setStatisticsEnabled(true);
attr.setEntryTimeToLive(new ExpirationAttributes(1000, ExpirationAction.LOCAL_DESTROY));
attr.setPartitionAttributes(prAttr);
try {
cache.createRegion("region1", attr.create());
fail("We should not have been able to create the region");
} catch (IllegalStateException expected) {
}
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class Bug40632DUnitTest method testLocalInvalidateIdleTimeout.
@Test
public void testLocalInvalidateIdleTimeout() throws Exception {
Cache cache = getCache();
AttributesFactory attr = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setRecoveryDelay(-1);
paf.setStartupRecoveryDelay(-1);
PartitionAttributes prAttr = paf.create();
attr.setStatisticsEnabled(true);
attr.setEntryIdleTimeout(new ExpirationAttributes(1000, ExpirationAction.LOCAL_INVALIDATE));
attr.setPartitionAttributes(prAttr);
try {
cache.createRegion("region1", attr.create());
fail("We should not have been able to create the region");
} catch (IllegalStateException expected) {
}
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class Bug41091DUnitTest method test.
@Test
public void test() {
final Host host = Host.getHost(0);
VM vm0 = host.getVM(0);
VM vm1 = host.getVM(1);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
final int locatorPort = AvailablePort.getRandomAvailablePort(AvailablePort.SOCKET);
// We need to use our own locator because we need enable network partition detection.
startLocatorInVM(vm3, locatorPort);
try {
final SerializableRunnable createRegion = new SerializableRunnable("create the region") {
public void run() {
DistributionMessageObserver.setInstance(new DistributionMessageObserver() {
@Override
public void beforeProcessMessage(DistributionManager dm, DistributionMessage message) {
if (message instanceof RequestImageMessage) {
RequestImageMessage rim = (RequestImageMessage) message;
Region region = getCache().getRegion(rim.regionPath);
if (region instanceof BucketRegion) {
// We can no longer do any puts until the bucket is completely created,
// so this will hang
// getCache().getRegion("region").put(113, "b");
getCache().close();
}
}
}
});
Properties props = new Properties();
props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
props.setProperty(LOCATORS, NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
getSystem(props);
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
af.setPartitionAttributes(paf.create());
cache.createRegion("region", af.create());
}
};
vm0.invoke(createRegion);
vm1.invoke(createRegion);
vm2.invoke(new SerializableRunnable("create an entry") {
public void run() {
Properties props = new Properties();
props.setProperty(ENABLE_NETWORK_PARTITION_DETECTION, "true");
props.setProperty(LOCATORS, NetworkUtils.getServerHostName(host) + "[" + locatorPort + "]");
getSystem(props);
Cache cache = getCache();
AttributesFactory af = new AttributesFactory();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setLocalMaxMemory(0);
af.setPartitionAttributes(paf.create());
Region region = cache.createRegion("region", af.create());
region.put(Integer.valueOf(0), "a");
}
});
} finally {
SerializableRunnable stopLocator = new SerializableRunnable("Stop locator") {
public void run() {
assertTrue(Locator.hasLocator());
Locator.getLocator().stop();
assertFalse(Locator.hasLocator());
}
};
vm3.invoke(stopLocator);
}
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class DistrbutedRegionProfileOffHeapDUnitTest method testPartitionedRegionProfileWithAccessor.
/**
* Asserts that creating a region on two members, with one being off-heap with local storage and
* the other being on-heap without local storage, will not cause an exception.
*/
@Test
public void testPartitionedRegionProfileWithAccessor() throws Exception {
final String regionName = getTestMethodName() + "Region";
// Create a region using off-heap
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));
}
});
// Create an accessor (no local storage) for the same region
Host.getHost(0).getVM(1).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);
PartitionAttributes partitionAttributes = new PartitionAttributesFactory().setLocalMaxMemory(0).create();
regionFactory.setPartitionAttributes(partitionAttributes);
Region region = regionFactory.create(regionName);
assertNotNull("Region is null", region);
assertNotNull("Cache does not contain region", cache.getRegion(regionName));
}
});
}
use of org.apache.geode.cache.PartitionAttributesFactory in project geode by apache.
the class PartitionedRegionAPIDUnitTest method testCacherLoaderHelper.
@Test
public void testCacherLoaderHelper() throws Exception {
final String rName = getUniqueName();
Host host = Host.getHost(0);
VM vm2 = host.getVM(2);
VM vm3 = host.getVM(3);
final int localMaxMemory = 10;
final String key1 = "key1";
final String arg = "loaderArg";
CacheSerializableRunnable createLoaderPR = new CacheSerializableRunnable("createLoaderPR") {
public void run2() throws CacheException {
getCache();
CacheLoader cl = new TestCacheLoader() {
public Object load2(LoaderHelper helper) throws CacheLoaderException {
assertNotNull(helper);
assertEquals(key1, helper.getKey());
assertEquals(rName, helper.getRegion().getName());
assertEquals(arg, helper.getArgument());
return helper.getArgument();
}
};
PartitionedRegion pr = (PartitionedRegion) new RegionFactory().setCacheLoader(cl).setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(1).setLocalMaxMemory(localMaxMemory).create()).create(rName);
assertSame(cl, pr.getDataStore().getCacheLoader());
}
};
vm2.invoke(createLoaderPR);
vm3.invoke(createLoaderPR);
// create a "pure" accessor, no data storage
getCache();
Region pr = new RegionFactory().setPartitionAttributes(new PartitionAttributesFactory().setRedundantCopies(1).setLocalMaxMemory(0).create()).create(rName);
assertEquals(arg, pr.get(key1, arg));
}
Aggregations