use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXml66DUnitTest method testCreateSameRegionTwice.
/**
* Tests to make sure that we cannot create the same region multiple times in a {@code cache.xml}
* file.
*/
@Test
public void testCreateSameRegionTwice() throws Exception {
CacheCreation cache = new CacheCreation();
RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
String name = "root";
cache.createRegion(name, attrs);
try {
cache.createRegion(name, attrs);
fail("Should have thrown a RegionExistsException");
} catch (RegionExistsException ex) {
// pass...
}
setXmlFile(findFile("sameRootRegion.xml"));
IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
try {
getCache();
fail("Should have thrown a CacheXmlException");
} catch (CacheXmlException ex) {
Throwable cause = ex.getCause();
assertTrue(cause instanceof SAXException);
cause = ((SAXException) cause).getException();
if (!(cause instanceof RegionExistsException)) {
Assert.fail("Expected a RegionExistsException, not a " + cause.getClass().getName(), cause);
}
} finally {
expectedException.remove();
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXml66DUnitTest method testNonExistentFile.
/**
* Tests creating a cache with a non-existent XML file
*/
@Test
public void testNonExistentFile() throws Exception {
// System.out.println("testNonExistentFile - start: " + System.currentTimeMillis());
File nonExistent = new File(this.getName() + ".xml");
nonExistent.delete();
// System.out.println("testNonExistentFile - deleted: " + System.currentTimeMillis());
setXmlFile(nonExistent);
// System.out.println("testNonExistentFile - set: " + System.currentTimeMillis());
IgnoredException expectedException = IgnoredException.addIgnoredException(LocalizedStrings.GemFireCache_DECLARATIVE_CACHE_XML_FILERESOURCE_0_DOES_NOT_EXIST.toLocalizedString(nonExistent.getPath()));
try {
getCache();
fail("Should have thrown a CacheXmlException");
} catch (CacheXmlException ex) {
// System.out.println("testNonExistentFile - caught: " + System.currentTimeMillis());
// pass...
} finally {
expectedException.remove();
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class CacheXml66DUnitTest method testCallbackWithException.
/**
* Tests parsing an XML file that specifies a cache listener whose constructor throws an
* {@linkplain AssertionError exception}.
*/
@Test
public void testCallbackWithException() throws Exception {
setXmlFile(findFile("callbackWithException.xml"));
IgnoredException expectedException = IgnoredException.addIgnoredException("While reading Cache XML file");
try {
getCache();
fail("Should have thrown a CacheXmlException");
} catch (CacheXmlException ex) {
if (!(ex.getCause() instanceof AssertionError)) {
throw ex;
}
} finally {
expectedException.remove();
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class LuceneXmlParser method startField.
private void startField(Attributes atts) {
// Ignore any whitespace noise between fields
if (stack.peek() instanceof StringBuffer) {
stack.pop();
}
if (!(stack.peek() instanceof LuceneIndexCreation)) {
throw new CacheXmlException("lucene <field> elements must occur within lucene <index> elements");
}
LuceneIndexCreation creation = (LuceneIndexCreation) stack.peek();
String name = atts.getValue(NAME);
String className = atts.getValue(ANALYZER);
if (className == null) {
creation.addField(name);
} else {
Analyzer analyzer = createAnalyzer(className);
creation.addFieldAndAnalyzer(name, analyzer);
}
}
use of org.apache.geode.cache.CacheXmlException in project geode by apache.
the class LuceneXmlParser method createAnalyzer.
private Analyzer createAnalyzer(String className) {
Object obj;
try {
Class c = InternalDataSerializer.getCachedClass(className);
obj = c.newInstance();
} catch (Exception ex) {
throw new CacheXmlException(LocalizedStrings.CacheXmlParser_WHILE_INSTANTIATING_A_0.toLocalizedString(className), ex);
}
if (!(obj instanceof Analyzer)) {
throw new CacheXmlException(LocalizedStrings.LuceneXmlParser_CLASS_0_IS_NOT_AN_INSTANCE_OF_ANALYZER.toLocalizedString(className));
}
return (Analyzer) obj;
}
Aggregations