geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kl...@apache.org
Subject [21/47] incubator-geode git commit: GEODE-719: Add error logs while cache.xml processing
Date Fri, 08 Jan 2016 18:42:22 GMT
GEODE-719: Add error logs while cache.xml processing

While processing cache.xml, log an error before throwing an exception so
that the reason for cache close is clear by looking at the log.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/13a3adf6
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/13a3adf6
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/13a3adf6

Branch: refs/heads/feature/GEODE-714
Commit: 13a3adf696111861c9727d8e010b7b468670c6d4
Parents: cb7dbd0
Author: Swapnil Bawaskar <sbawaskar@pivotal.io>
Authored: Thu Dec 31 13:00:01 2015 -0800
Committer: Swapnil Bawaskar <sbawaskar@pivotal.io>
Committed: Tue Jan 5 10:35:48 2016 -0800

----------------------------------------------------------------------
 .../internal/cache/GemFireCacheImpl.java        | 12 ++++++----
 .../gemfire/cache30/CacheXml30DUnitTest.java    | 24 ++++++++++++++++++++
 .../gemfire/cache30/CacheXml41DUnitTest.java    |  7 ++++++
 .../gemfire/cache30/CacheXml60DUnitTest.java    | 14 ++++++++----
 .../gemfire/cache30/CacheXml81DUnitTest.java    |  4 ++++
 5 files changed, 53 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/13a3adf6/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
index 506bd7a..9d77556 100644
--- a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
+++ b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/GemFireCacheImpl.java
@@ -1359,12 +1359,16 @@ public class GemFireCacheImpl implements InternalCache, ClientCache,
HasCachePer
             LocalizedStrings.GemFireCache_CACHE_INITIALIZED_USING__0__1, new Object[] {"generated
description from old cache", cacheXmlDescription}));
       }
     } catch (IOException ex) {
-      throw new CacheXmlException(LocalizedStrings.GemFireCache_WHILE_OPENING_CACHE_XML_0_THE_FOLLOWING_ERROR_OCCURRED_1
-          .toLocalizedString(new Object[] { url.toString(), ex }));
+      String exceptionMsg = LocalizedStrings.GemFireCache_WHILE_OPENING_CACHE_XML_0_THE_FOLLOWING_ERROR_OCCURRED_1
+          .toLocalizedString(new Object[] { url.toString(), ex });
+      logger.error(exceptionMsg);
+      throw new CacheXmlException(exceptionMsg);
 
     } catch (CacheXmlException ex) {
-      CacheXmlException newEx = new CacheXmlException(LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1
-          .toLocalizedString(new Object[] { url, ex.getMessage() }));
+      String exceptionMsg = LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1
+          .toLocalizedString(new Object[] { url, ex.getMessage() });
+      logger.error(exceptionMsg);
+      CacheXmlException newEx = new CacheXmlException(exceptionMsg);
       newEx.setStackTrace(ex.getStackTrace());
       newEx.initCause(ex.getCause());
       throw newEx;

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/13a3adf6/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml30DUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml30DUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml30DUnitTest.java
index b678884..adafa69 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml30DUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml30DUnitTest.java
@@ -285,12 +285,15 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testMalformed() {
     setXmlFile(findFile("malformed.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
 
     } catch (CacheXmlException ex) {
       assertTrue(ex.getCause() instanceof SAXException);
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -300,6 +303,7 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testBadInt() {
     setXmlFile(findFile("badInt.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
@@ -310,6 +314,8 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
       assertTrue("Didn't expect cause:" + cause + " (a " +
                  cause.getClass().getName() + ")",
                  cause instanceof NumberFormatException);
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -319,12 +325,15 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testBadFloat() {
     setXmlFile(findFile("badFloat.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
 
     } catch (CacheXmlException ex) {
       assertTrue(ex.getCause() instanceof NumberFormatException);
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -335,12 +344,15 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testBadScope() {
     setXmlFile(findFile("badScope.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
 
     } catch (CacheXmlException ex) {
       assertTrue(ex.getCause() instanceof SAXException);
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -351,12 +363,15 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testBadKeyConstraintClass() {
     setXmlFile(findFile("badKeyConstraintClass.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
 
     } catch (CacheXmlException ex) {
       assertTrue(ex.getCause() instanceof ClassNotFoundException);
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -367,6 +382,7 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testCallbackNotDeclarable() {
     setXmlFile(findFile("callbackNotDeclarable.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
@@ -376,6 +392,8 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
       assertNull(/*"Didn't expect a cause of " + cause + " (a " +
                    cause.getClass().getName() + ")" + " from " + ex, */
                  cause);
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -386,6 +404,7 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testCallbackWithException() {
     setXmlFile(findFile("callbackWithException.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
@@ -394,6 +413,8 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
       if (!(ex.getCause() instanceof TestException)) {
         throw ex;
       }
+    } finally {
+      expectedException.remove();
     }
 
   }
@@ -405,6 +426,7 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
   public void testLoaderNotLoader() {
     setXmlFile(findFile("loaderNotLoader.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
@@ -412,6 +434,8 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
     } catch (CacheXmlException ex) {
       Throwable cause = ex.getCause();
       assertNull("Didn't expect a " + cause, cause);
+    } finally {
+      expectedException.remove();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/13a3adf6/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml41DUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml41DUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml41DUnitTest.java
index 0d9cdf0..5a41d31 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml41DUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml41DUnitTest.java
@@ -22,6 +22,7 @@ import com.gemstone.gemfire.internal.cache.xmlcache.*;
 
 import java.io.*;
 
+import dunit.DistributedTestCase;
 import org.xml.sax.SAXException;
 
 /**
@@ -175,6 +176,7 @@ public class CacheXml41DUnitTest extends CacheXml40DUnitTest
 
     setXmlFile(findFile("sameRootRegion.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
@@ -188,6 +190,8 @@ public class CacheXml41DUnitTest extends CacheXml40DUnitTest
         fail("Expected a RegionExistsException, not a "
             + cause.getClass().getName(), cause);
       }
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -216,6 +220,7 @@ public class CacheXml41DUnitTest extends CacheXml40DUnitTest
 
     setXmlFile(findFile("sameSubregion.xml"));
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
@@ -229,6 +234,8 @@ public class CacheXml41DUnitTest extends CacheXml40DUnitTest
         fail("Expected a RegionExistsException, not a "
             + cause.getClass().getName(), cause);
       }
+    } finally {
+      expectedException.remove();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/13a3adf6/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml60DUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml60DUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml60DUnitTest.java
index ddb35b7..8699a05 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml60DUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml60DUnitTest.java
@@ -307,22 +307,28 @@ public class CacheXml60DUnitTest extends CacheXml58DUnitTest
     sc.registerInstantiator(NotDataSerializable.class, 15);
     closeCache();
     cc.setSerializerCreation(sc);
-    
+
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       testXml(cc);
       fail("Instantiator should not have registered due to bad class.");
+    } catch(Exception e) {
+    } finally {
+      expectedException.remove();
     }
-    catch(Exception e){}
     
     sc = new SerializerCreation();
     sc.registerSerializer(BadSerializer.class);
     closeCache();
     cc.setSerializerCreation(sc);
-    
+
+    ExpectedException expectedException1 = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       testXml(cc);
       fail("Serializer should not have registered due to bad class.");
+    } catch(Exception e){
+    } finally {
+      expectedException1.remove();
     }
-    catch(Exception e){}
   }
 }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/13a3adf6/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml81DUnitTest.java
----------------------------------------------------------------------
diff --git a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml81DUnitTest.java
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml81DUnitTest.java
index 3c77326..831875a 100644
--- a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml81DUnitTest.java
+++ b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml81DUnitTest.java
@@ -16,6 +16,7 @@
  */
 package com.gemstone.gemfire.cache30;
 
+import dunit.DistributedTestCase;
 import org.junit.Rule;
 import org.junit.Test;
 import org.xml.sax.Locator;
@@ -140,6 +141,7 @@ public class CacheXml81DUnitTest extends CacheXml80DUnitTest {
     assertEquals(0, extension.onCreateCounter.get());
     assertEquals(0, extension.getXmlGeneratorCounter.get());
 
+    ExpectedException expectedException = DistributedTestCase.addExpectedException("While
reading Cache XML file");
     try {
       testXml(cache);
       fail("Excepted CacheXmlException");
@@ -149,6 +151,8 @@ public class CacheXml81DUnitTest extends CacheXml80DUnitTest {
         assertTrue(((SAXParseException) e.getCause()).getColumnNumber() > 0);
         assertEquals("Value is 'exception'.", e.getCause().getMessage());
       }
+    } finally {
+      expectedException.remove();
     }
   }
 


Mime
View raw message