use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testPARTITION_PERSISTENT.
@Test
public void testPARTITION_PERSISTENT() throws Exception {
CacheCreation cache = new CacheCreation();
RegionCreation root = (RegionCreation) cache.createRegion("ppartition", "PARTITION_PERSISTENT");
testXml(cache);
GemFireCacheImpl c = (GemFireCacheImpl) getCache();
Region r = c.getRegion("ppartition");
assertNotNull(r);
RegionAttributes ra = r.getAttributes();
assertEquals(DataPolicy.PERSISTENT_PARTITION, ra.getDataPolicy());
assertNotNull(ra.getPartitionAttributes());
assertEquals(0, ra.getPartitionAttributes().getRedundantCopies());
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml66DUnitTest method testRedefineOfDefaultDiskStore.
@Test
public void testRedefineOfDefaultDiskStore() throws Exception {
CacheCreation cache = new CacheCreation();
DiskStoreFactory dsf = cache.createDiskStoreFactory();
dsf.setAutoCompact(!DiskStoreFactory.DEFAULT_AUTO_COMPACT);
DiskStore ds1 = dsf.create(DiskStoreFactory.DEFAULT_DISK_STORE_NAME);
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
attrs.setScope(Scope.DISTRIBUTED_ACK);
attrs.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE);
AttributesFactory factory = new AttributesFactory(attrs);
RegionAttributes ra = factory.create();
RegionCreation root = (RegionCreation) cache.createRegion("root", ra);
testXml(cache);
Cache c = getCache();
assertNotNull(c);
DiskStore ds2 = c.findDiskStore(DiskStoreFactory.DEFAULT_DISK_STORE_NAME);
assertNotNull(ds2);
assertEquals(ds1.getAutoCompact(), ds2.getAutoCompact());
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml81DUnitTest method testLocatorInException.
/**
* Test {@link Locator} is used in {@link SAXParseException}. Exercises
* {@link XmlParser#setDocumentLocator(Locator)}
*
* @since GemFire 8.2
*/
@Test
public void testLocatorInException() throws Exception {
final String regionName = "testRegionExtension";
final CacheCreation cache = new CacheCreation();
final RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
@SuppressWarnings("unchecked") Extensible<Region<?, ?>> region = (Extensible<Region<?, ?>>) cache.createRegion(regionName, attrs);
final MockRegionExtension extension = new MockRegionExtension("exception");
region.getExtensionPoint().addExtension(extension);
assertEquals(0, extension.beforeCreateCounter.get());
assertEquals(0, extension.onCreateCounter.get());
assertEquals(0, extension.getXmlGeneratorCounter.get());
IgnoredException.addIgnoredException("While reading Cache XML file");
try {
testXml(cache);
fail("Excepted CacheXmlException");
} catch (final CacheXmlException e) {
if (e.getCause() instanceof SAXParseException) {
assertTrue(((SAXParseException) e.getCause()).getLineNumber() > 0);
assertTrue(((SAXParseException) e.getCause()).getColumnNumber() > 0);
assertEquals("Value is 'exception'.", e.getCause().getMessage());
}
}
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXml81DUnitTest method testCacheExtension.
/**
* Test extensions to <code>cache</code> element.
*
* @since GemFire 8.1
*/
@Test
public void testCacheExtension() throws Exception {
final CacheCreation cache = new CacheCreation();
final MockCacheExtension extension = new MockCacheExtension("testCacheExtension");
cache.getExtensionPoint().addExtension(extension);
assertEquals(0, extension.beforeCreateCounter.get());
assertEquals(0, extension.onCreateCounter.get());
assertEquals(0, extension.getXmlGeneratorCounter.get());
testXml(cache);
assertEquals(0, extension.beforeCreateCounter.get());
assertEquals(0, extension.onCreateCounter.get());
assertEquals(1, extension.getXmlGeneratorCounter.get());
@SuppressWarnings("unchecked") final Extensible<Cache> c = (Extensible<Cache>) getCache();
assertNotNull(c);
final MockCacheExtension m = (MockCacheExtension) c.getExtensionPoint().getExtensions().iterator().next();
assertNotNull(m);
assertEquals(1, m.beforeCreateCounter.get());
assertEquals(1, m.onCreateCounter.get());
assertEquals(0, m.getXmlGeneratorCounter.get());
}
use of org.apache.geode.internal.cache.xmlcache.CacheCreation in project geode by apache.
the class CacheXmlGeode10DUnitTest method testEnableOffHeapMemorySubRegionWithoutOffHeapMemoryThrowsException.
@SuppressWarnings({ "rawtypes", "deprecation", "unchecked" })
@Test
public void testEnableOffHeapMemorySubRegionWithoutOffHeapMemoryThrowsException() throws Exception {
final String rootRegionName = getUniqueName();
final String subRegionName = "subRegion";
final CacheCreation cache = new CacheCreation();
final RegionAttributesCreation rootRegionAttrs = new RegionAttributesCreation(cache);
assertEquals(false, rootRegionAttrs.getOffHeap());
final Region rootRegionBefore = cache.createRegion(rootRegionName, rootRegionAttrs);
assertNotNull(rootRegionBefore);
assertEquals(false, rootRegionBefore.getAttributes().getOffHeap());
final RegionAttributesCreation subRegionAttrs = new RegionAttributesCreation(cache);
subRegionAttrs.setOffHeap(true);
assertEquals(true, subRegionAttrs.getOffHeap());
final Region subRegionBefore = rootRegionBefore.createSubregion(subRegionName, subRegionAttrs);
assertNotNull(subRegionBefore);
assertEquals(true, subRegionBefore.getAttributes().getOffHeap());
IgnoredException.addIgnoredException(LocalizedStrings.LocalRegion_THE_REGION_0_WAS_CONFIGURED_TO_USE_OFF_HEAP_MEMORY_BUT_OFF_HEAP_NOT_CONFIGURED.toLocalizedString("/" + rootRegionName + "/" + subRegionName));
try {
testXml(cache);
fail("Expected IllegalStateException to be thrown");
} catch (IllegalStateException e) {
// expected
final String msg = LocalizedStrings.LocalRegion_THE_REGION_0_WAS_CONFIGURED_TO_USE_OFF_HEAP_MEMORY_BUT_OFF_HEAP_NOT_CONFIGURED.toLocalizedString("/" + rootRegionName + "/" + subRegionName);
assertEquals(msg, e.getMessage());
}
}
Aggregations