Search in sources :

Example 26 with CacheXmlException

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();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) RegionAttributesCreation(org.apache.geode.internal.cache.xmlcache.RegionAttributesCreation) IgnoredException(org.apache.geode.test.dunit.IgnoredException) RegionExistsException(org.apache.geode.cache.RegionExistsException) CacheCreation(org.apache.geode.internal.cache.xmlcache.CacheCreation) ClientCacheCreation(org.apache.geode.internal.cache.xmlcache.ClientCacheCreation) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Example 27 with CacheXmlException

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();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) File(java.io.File) Test(org.junit.Test)

Example 28 with CacheXmlException

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();
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) IgnoredException(org.apache.geode.test.dunit.IgnoredException) Test(org.junit.Test)

Example 29 with CacheXmlException

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);
    }
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) Analyzer(org.apache.lucene.analysis.Analyzer)

Example 30 with CacheXmlException

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;
}
Also used : CacheXmlException(org.apache.geode.cache.CacheXmlException) Analyzer(org.apache.lucene.analysis.Analyzer) SAXException(org.xml.sax.SAXException) CacheXmlException(org.apache.geode.cache.CacheXmlException)

Aggregations

CacheXmlException (org.apache.geode.cache.CacheXmlException)51 Declarable (org.apache.geode.cache.Declarable)22 SAXException (org.xml.sax.SAXException)13 Test (org.junit.Test)12 IgnoredException (org.apache.geode.test.dunit.IgnoredException)11 IOException (java.io.IOException)10 RegionExistsException (org.apache.geode.cache.RegionExistsException)9 CacheException (org.apache.geode.cache.CacheException)8 SAXParseException (org.xml.sax.SAXParseException)8 File (java.io.File)7 EmptyStackException (java.util.EmptyStackException)7 InternalGemFireException (org.apache.geode.InternalGemFireException)7 CacheWriterException (org.apache.geode.cache.CacheWriterException)7 GatewayException (org.apache.geode.cache.GatewayException)7 TimeoutException (org.apache.geode.cache.TimeoutException)7 Properties (java.util.Properties)5 ArrayList (java.util.ArrayList)3 List (java.util.List)3 GatewaySenderFactory (org.apache.geode.cache.wan.GatewaySenderFactory)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2