use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testModifyRegionViaCacheXml.
/**
* Tests that loading cache XML can modify a region.
*/
@Test
public void testModifyRegionViaCacheXml() throws Exception {
CacheCreation creation = new CacheCreation();
int timeout1a = 123;
ExpirationAction action1a = ExpirationAction.LOCAL_DESTROY;
int timeout1b = 456;
ExpirationAction action1b = ExpirationAction.DESTROY;
RegionAttributesCreation attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1a, action1a));
Region root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout1b, action1b));
Region subregion = root.createSubregion("subregion", attrs);
testXml(creation);
Cache cache = getCache();
root = cache.getRegion("root");
assertEquals(timeout1a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1a, root.getAttributes().getEntryIdleTimeout().getAction());
subregion = root.getSubregion("subregion");
assertEquals(timeout1b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action1b, subregion.getAttributes().getEntryIdleTimeout().getAction());
creation = new CacheCreation();
int timeout2a = 234;
ExpirationAction action2a = ExpirationAction.LOCAL_INVALIDATE;
int timeout2b = 567;
ExpirationAction action2b = ExpirationAction.INVALIDATE;
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2a, action2a));
attrs.setCacheListener(new MyTestCacheListener());
root = creation.createRegion("root", attrs);
attrs = new RegionAttributesCreation(creation);
attrs.setStatisticsEnabled(true);
attrs.setEntryIdleTimeout(new ExpirationAttributes(timeout2b, action2b));
subregion = root.createSubregion("subregion", attrs);
cache.loadCacheXml(generate(creation));
root = cache.getRegion("root");
subregion = root.getSubregion("subregion");
assertEquals(timeout2a, root.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2a, root.getAttributes().getEntryIdleTimeout().getAction());
assertTrue(root.getAttributes().getCacheListener() instanceof MyTestCacheListener);
assertEquals(timeout2b, subregion.getAttributes().getEntryIdleTimeout().getTimeout());
assertEquals(action2b, subregion.getAttributes().getEntryIdleTimeout().getAction());
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testPartitionedRegionAttributesForExpiration.
/**
* Tests that a Partitioned Region can be created with a named attributes set programmatically for
* ExpirationAttributes
*/
@Test
public void testPartitionedRegionAttributesForExpiration() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setStatisticsEnabled(true);
RegionAttributes rootAttrs = null;
ExpirationAttributes expiration = new ExpirationAttributes(60, ExpirationAction.DESTROY);
CacheXMLPartitionResolver partitionResolver = new CacheXMLPartitionResolver();
Properties params = new Properties();
params.setProperty("initial-index-value", "1000");
params.setProperty("secondary-index-value", "5000");
partitionResolver.init(params);
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1);
paf.setTotalMaxMemory(500);
paf.setLocalMaxMemory(100);
paf.setPartitionResolver(partitionResolver);
AttributesFactory fac = new AttributesFactory(attrs);
fac.setEntryTimeToLive(expiration);
fac.setEntryIdleTimeout(expiration);
fac.setPartitionAttributes(paf.create());
rootAttrs = fac.create();
cache.createRegion("parRoot", rootAttrs);
Region r = cache.getRegion("parRoot");
assertNotNull(r);
assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(), 1);
assertEquals(r.getAttributes().getPartitionAttributes().getLocalMaxMemory(), 100);
assertEquals(r.getAttributes().getPartitionAttributes().getTotalMaxMemory(), 500);
assertEquals(r.getAttributes().getPartitionAttributes().getPartitionResolver(), partitionResolver);
assertEquals(r.getAttributes().getEntryIdleTimeout().getTimeout(), expiration.getTimeout());
assertEquals(r.getAttributes().getEntryTimeToLive().getTimeout(), expiration.getTimeout());
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("parRoot");
assertNotNull(region);
RegionAttributes regionAttrs = region.getAttributes();
PartitionAttributes pa = regionAttrs.getPartitionAttributes();
assertEquals(pa.getRedundantCopies(), 1);
assertEquals(pa.getLocalMaxMemory(), 100);
assertEquals(pa.getTotalMaxMemory(), 500);
assertNotNull(pa.getPartitionResolver().getClass());
assertEquals(pa.getPartitionResolver(), partitionResolver);
assertEquals(regionAttrs.getEntryIdleTimeout().getTimeout(), expiration.getTimeout());
assertEquals(regionAttrs.getEntryTimeToLive().getTimeout(), expiration.getTimeout());
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testNonDefaultRegionAttributes.
/**
* Tests a region with non-default region attributes
*/
@Test
public void testNonDefaultRegionAttributes() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_NO_ACK);
attrs.setMirrorType(MirrorType.KEYS_VALUES);
attrs.setInitialCapacity(142);
attrs.setLoadFactor(42.42f);
attrs.setStatisticsEnabled(false);
cache.createRegion("root", attrs);
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testDiskStoreValidation.
@Test
public void testDiskStoreValidation() throws Exception {
CacheCreation cache = new CacheCreation();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
DiskStore ds1 = dsf.create(getUniqueName());
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setDataPolicy(DataPolicy.REPLICATE);
attrs.setDiskStoreName(getUniqueName());
RegionCreation root;
try {
root = (RegionCreation) cache.createRegion("root", attrs);
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_IS_USED_IN_NONPERSISTENT_REGION.toLocalizedString()));
}
EvictionAttributes ea = EvictionAttributes.createLRUEntryAttributes(1000, EvictionAction.OVERFLOW_TO_DISK);
attrs.setEvictionAttributes(ea);
root = (RegionCreation) cache.createRegion("root", attrs);
File dir = new File("testDiskStoreValidation");
dir.mkdir();
dir.deleteOnExit();
File[] dirs2 = new File[] { dir, new File("").getAbsoluteFile() };
try {
AttributesFactory factory = new AttributesFactory();
factory.setDiskDirs(dirs2);
factory.setDiskStoreName(getUniqueName());
RegionAttributes ra = factory.create();
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1.toLocalizedString("setDiskDirs or setDiskWriteAttributes", getUniqueName())));
}
try {
AttributesFactory factory = new AttributesFactory();
factory.setDiskStoreName(getUniqueName());
factory.setDiskDirs(dirs2);
RegionAttributes ra = factory.create();
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
assertTrue(e.getMessage().contains(LocalizedStrings.DiskStore_Deprecated_API_0_Cannot_Mix_With_DiskStore_1.toLocalizedString("setDiskDirs", getUniqueName())));
}
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation in project geode by apache.
the class CacheXml66DUnitTest method testBridgeMaxThreads.
/**
* Tests the bridge-server attributes ({@code max-threads}
*/
@Test
public void testBridgeMaxThreads() throws Exception {
CacheCreation cache = new CacheCreation();
CacheServer bs = cache.addCacheServer();
bs.setMaxThreads(37);
bs.setMaxConnections(999);
bs.setPort(AvailablePortHelper.getRandomAvailableTCPPort());
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.NORMAL);
cache.createVMRegion("rootNORMAL", attrs);
testXml(cache);
}
Aggregations