use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testSerializationRegistration.
@Test
public void testSerializationRegistration() throws Exception {
CacheCreation cc = new CacheCreation();
SerializerCreation sc = new SerializerCreation();
cc.setSerializerCreation(sc);
sc.registerInstantiator(DS1.class, 15);
sc.registerInstantiator(DS2.class, 16);
sc.registerSerializer(GoodSerializer.class);
testXml(cc);
// Now make sure all of the classes were registered....
assertEquals(15, InternalInstantiator.getClassId(DS1.class));
assertEquals(16, InternalInstantiator.getClassId(DS2.class));
assertEquals(GoodSerializer.class, InternalDataSerializer.getSerializer(101).getClass());
sc = new SerializerCreation();
sc.registerInstantiator(NotDataSerializable.class, 15);
closeCache();
cc.setSerializerCreation(sc);
IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
try {
testXml(cc);
fail("Instantiator should not have registered due to bad class.");
} catch (Exception e) {
} finally {
expectedException.remove();
}
sc = new SerializerCreation();
sc.registerSerializer(BadSerializer.class);
closeCache();
cc.setSerializerCreation(sc);
IgnoredException expectedException1 = IgnoredException.addIgnoredException("While reading Cache XML file");
try {
testXml(cc);
fail("Serializer should not have registered due to bad class.");
} catch (Exception e) {
} finally {
expectedException1.remove();
}
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testFixedPartitioning.
/**
* Tests that a partitioned region is created with FixedPartitionAttributes set programatically
* and correct cache.xml is generated with the same FixedPartitionAttributes
*/
@Test
public void testFixedPartitioning() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation();
FixedPartitionAttributes fpa1 = FixedPartitionAttributes.createFixedPartition("Q1");
FixedPartitionAttributes fpa2 = FixedPartitionAttributes.createFixedPartition("Q2", true);
FixedPartitionAttributes fpa3 = FixedPartitionAttributes.createFixedPartition("Q3", 3);
FixedPartitionAttributes fpa4 = FixedPartitionAttributes.createFixedPartition("Q4", false, 3);
List<FixedPartitionAttributes> fpattrsList = new ArrayList<FixedPartitionAttributes>();
fpattrsList.add(fpa1);
fpattrsList.add(fpa2);
fpattrsList.add(fpa3);
fpattrsList.add(fpa4);
QuarterPartitionResolver resolver = new QuarterPartitionResolver();
PartitionAttributesFactory paf = new PartitionAttributesFactory();
paf.setRedundantCopies(1).setPartitionResolver(resolver).addFixedPartitionAttributes(fpa1).addFixedPartitionAttributes(fpa2).addFixedPartitionAttributes(fpa3).addFixedPartitionAttributes(fpa4);
attrs.setPartitionAttributes(paf.create());
cache.createRegion("Quarter", attrs);
Region r = cache.getRegion("Quarter");
validateAttributes(r, fpattrsList, resolver, false);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("Quarter");
assertNotNull(region);
validateAttributes(region, fpattrsList, resolver, false);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testPartitionedRegionAttributesForEviction.
/**
* Tests that a Partitioned Region can be created with a named attributes set programmatically for
* ExpirationAttributes
*/
@Test
public void testPartitionedRegionAttributesForEviction() throws Exception {
final int redundantCopies = 1;
CacheCreation cache = new CacheCreation();
if (getGemFireVersion().equals(CacheXml.VERSION_6_0)) {
ResourceManagerCreation rm = new ResourceManagerCreation();
rm.setCriticalHeapPercentage(95);
cache.setResourceManagerCreation(rm);
}
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(redundantCopies);
paf.setTotalMaxMemory(500);
paf.setLocalMaxMemory(100);
paf.setPartitionResolver(partitionResolver);
AttributesFactory fac = new AttributesFactory(attrs);
// TODO: Move test back to using LRUHeap when config issues have settled
// if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) {
// fac.setEvictionAttributes(EvictionAttributes.createLRUHeapAttributes(null,
// EvictionAction.OVERFLOW_TO_DISK));
// } else {
fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(100, null, EvictionAction.OVERFLOW_TO_DISK));
// }
fac.setEntryTimeToLive(expiration);
fac.setEntryIdleTimeout(expiration);
DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
dwaf.setSynchronous(true);
fac.setPartitionAttributes(paf.create());
rootAttrs = fac.create();
cache.createRegion("parRoot", rootAttrs);
Region r = cache.getRegion("parRoot");
assertNotNull(r);
assertEquals(r.getAttributes().getPartitionAttributes().getRedundantCopies(), redundantCopies);
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();
EvictionAttributes ea = regionAttrs.getEvictionAttributes();
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());
// TODO: Move test back to using LRUHeap when config issues have settled
// if (getGemFireVersion().equals(CacheXml.GEMFIRE_6_0)) {
// assertIndexDetailsEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_HEAP);
// } else {
assertEquals(ea.getAlgorithm(), EvictionAlgorithm.LRU_MEMORY);
// }
assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testRollOplogs.
@Test
public void testRollOplogs() throws Exception {
CacheCreation cache = new CacheCreation();
// Set properties for Asynch writes
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
RegionCreation root = (RegionCreation) cache.createRegion("root", attrs);
{
attrs = new RegionAttributesCreation(cache);
DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
dwaf.setSynchronous(true);
dwaf.setRollOplogs(true);
attrs.setDiskWriteAttributes(dwaf.create());
root.createSubregion("sync", attrs);
}
{
attrs = new RegionAttributesCreation(cache);
DiskWriteAttributesFactory dwaf = new DiskWriteAttributesFactory();
dwaf.setTimeInterval(123L);
dwaf.setBytesThreshold(456L);
dwaf.setRollOplogs(false);
attrs.setDiskWriteAttributes(dwaf.create());
root.createSubregion("async", attrs);
}
testXml(cache);
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testPersistentPartition.
/**
* Make sure you can create a persistent partitioned region from xml.
*/
@Test
public void testPersistentPartition() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setDataPolicy(DataPolicy.PERSISTENT_PARTITION);
cache.createRegion("parRoot", attrs);
Region r = cache.getRegion("parRoot");
assertEquals(DataPolicy.PERSISTENT_PARTITION, r.getAttributes().getDataPolicy());
testXml(cache);
Cache c = getCache();
assertNotNull(c);
Region region = c.getRegion("parRoot");
assertNotNull(region);
assertEquals(DataPolicy.PERSISTENT_PARTITION, region.getAttributes().getDataPolicy());
// since CacheTestCase remoteTearDown does not destroy PartitionedRegion
region.localDestroyRegion();
}
Aggregations