Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-259 [created] aa9d21cda


GEODE-719: Processing errors in cache.xml do not log a warning

- Catch all Errors and RuntimeExceptions while creating a cache and log
an error level message.
- Display the cache.xml contents before trying to initialize the cache
so that the errors have a better context.
- Converted some exception messages to i18n.


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

Branch: refs/heads/feature/GEODE-259
Commit: 22f31f8c8e06348c83d9a2051be70210f8ad5d28
Parents: d863b6e
Author: Swapnil Bawaskar <sbawas...@pivotal.io>
Authored: Thu Jan 7 10:51:59 2016 -0800
Committer: Swapnil Bawaskar <sbawas...@pivotal.io>
Committed: Mon Jan 18 16:01:57 2016 -0800

----------------------------------------------------------------------
 .../cache/client/ClientCacheFactory.java        |  2 +-
 .../gemfire/internal/cache/AbstractRegion.java  |  5 +-
 .../internal/cache/GemFireCacheImpl.java        | 96 ++++++++++++--------
 .../gemfire/internal/cache/LocalRegion.java     |  3 +-
 .../gemfire/internal/cache/PoolManagerImpl.java |  4 +-
 .../internal/i18n/ParentLocalizedStrings.java   |  9 +-
 .../gemfire/cache/CacheFactoryTest.java         |  7 ++
 .../gemfire/cache30/CacheXml30DUnitTest.java    |  9 ++
 .../gemfire/cache30/CacheXml41DUnitTest.java    |  4 +
 .../gemfire/cache30/CacheXml57DUnitTest.java    |  7 ++
 .../gemfire/cache30/CacheXml60DUnitTest.java    |  3 +
 .../gemfire/cache30/CacheXml66DUnitTest.java    |  5 +-
 .../gemfire/cache30/CacheXml90DUnitTest.java    | 17 +++-
 .../internal/cache/GemFireCacheImplTest.java    |  7 ++
 14 files changed, 125 insertions(+), 53 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/main/java/com/gemstone/gemfire/cache/client/ClientCacheFactory.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/client/ClientCacheFactory.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/client/ClientCacheFactory.java
index c39e33a..adb1c67 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/cache/client/ClientCacheFactory.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/cache/client/ClientCacheFactory.java
@@ -213,7 +213,7 @@ public class ClientCacheFactory {
       
       return instance;
     } else {
-      GemFireCacheImpl gfc = GemFireCacheImpl.create(true, this.pf, system, 
cacheConfig);
+      GemFireCacheImpl gfc = GemFireCacheImpl.createClient(system, this.pf, 
cacheConfig);
       return gfc;
     }
     }

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
index 45adbd6..4711f80 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/AbstractRegion.java
@@ -1778,9 +1778,8 @@ public abstract class AbstractRegion implements Region, 
RegionAttributes,
     if (this.poolName != null) {
       PoolImpl cp = getPool();
       if (cp == null) {
-        throw new IllegalStateException("The connection pool \""
-                                        + this.poolName
-                                        + "\" has not been created");
+        throw new IllegalStateException(LocalizedStrings.
+            
AbstractRegion_THE_CONNECTION_POOL_0_HAS_NOT_BEEN_CREATED.toLocalizedString(this.poolName));
       }
       cp.attach();
       if (cp.getMultiuserAuthentication() && !this.dataPolicy.isEmpty()) {

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/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 9d77556..7565871 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
@@ -766,18 +766,40 @@ public class GemFireCacheImpl implements InternalCache, 
ClientCache, HasCachePer
   // instance = null;
   // }
 
-  public static GemFireCacheImpl create(boolean isClient, PoolFactory pf, 
DistributedSystem system, CacheConfig cacheConfig) {
-    return new GemFireCacheImpl(true, pf, system, cacheConfig).init();
+  public static GemFireCacheImpl createClient(DistributedSystem system, 
PoolFactory pf, CacheConfig cacheConfig) {
+    return basicCreate(system, true, cacheConfig, pf, true);
   }
 
   public static GemFireCacheImpl create(DistributedSystem system, CacheConfig 
cacheConfig) {
-    return new GemFireCacheImpl(false, null, system, cacheConfig).init();
+    return basicCreate(system, true, cacheConfig, null, false);
   }
-  public static Cache create(DistributedSystem system, boolean existingOk, 
CacheConfig cacheConfig)
+
+  public static Cache create(DistributedSystem system, boolean existingOk, 
CacheConfig cacheConfig) {
+    return basicCreate(system, existingOk, cacheConfig, null, false);
+  }
+
+  private static GemFireCacheImpl basicCreate(DistributedSystem system, 
boolean existingOk, CacheConfig cacheConfig, PoolFactory pf, boolean isClient)
   throws CacheExistsException, TimeoutException, CacheWriterException,
   GatewayException,
   RegionExistsException 
   {
+    try {
+      GemFireCacheImpl instance = checkExistingCache(existingOk, cacheConfig);
+      if (instance == null) {
+        instance = new GemFireCacheImpl(isClient, pf, system, cacheConfig);
+        instance.initialize();
+      }
+      return instance;
+    } catch (CacheXmlException | IllegalArgumentException e) {
+      logger.error(e.getLocalizedMessage());
+      throw e;
+    } catch (Error | RuntimeException e) {
+      logger.error(e);
+      throw e;
+    }
+  }
+
+  private static GemFireCacheImpl checkExistingCache(boolean existingOk, 
CacheConfig cacheConfig) {
     GemFireCacheImpl instance = getInstance();
 
     if (instance != null && !instance.isClosed()) {
@@ -785,15 +807,14 @@ public class GemFireCacheImpl implements InternalCache, 
ClientCache, HasCachePer
         // Check if cache configuration matches.
         cacheConfig.validateCacheConfig(instance);
 
-        return instance;
       } else {
         // instance.creationStack argument is for debugging...
         throw new CacheExistsException(instance, 
LocalizedStrings.CacheFactory_0_AN_OPEN_CACHE_ALREADY_EXISTS.toLocalizedString(instance),
 instance.creationStack);
       }
     }
-    return create(system, cacheConfig);
+    return instance;
   }
-  
+
   /**
    * Creates a new instance of GemFireCache and populates it according to the 
<code>cache.xml</code>, if appropriate.
    */
@@ -1102,7 +1123,7 @@ public class GemFireCacheImpl implements InternalCache, 
ClientCache, HasCachePer
    *
    * @return the initialized instance of the cache
    */
-  private GemFireCacheImpl init() {
+  private void initialize() {
     if (GemFireCacheImpl.instance != null) {
       Assert.assertTrue(GemFireCacheImpl.instance == null, "Cache instance 
already in place: " + instance);
     }
@@ -1172,7 +1193,6 @@ public class GemFireCacheImpl implements InternalCache, 
ClientCache, HasCachePer
         DEFAULT_CLIENT_FUNCTION_TIMEOUT);
     clientFunctionTimeout = time >= 0 ? time : DEFAULT_CLIENT_FUNCTION_TIMEOUT;
 
-    return this;
   }
 
   /**
@@ -1323,6 +1343,7 @@ public class GemFireCacheImpl implements InternalCache, 
ClientCache, HasCachePer
     }
 
     try {
+      logCacheXML(url, cacheXmlDescription);
       InputStream stream = null;
       if (cacheXmlDescription != null) {
         if (logger.isTraceEnabled()) {
@@ -1337,44 +1358,43 @@ public class GemFireCacheImpl implements InternalCache, 
ClientCache, HasCachePer
         stream.close();
       } catch (IOException ignore) {
       }
-      if (cacheXmlDescription == null) {
-        StringBuilder sb = new StringBuilder();
-        try {
-          final String EOLN = System.getProperty("line.separator");
-          BufferedReader br = new BufferedReader(new 
InputStreamReader(url.openStream()));
-          String l = br.readLine();
-          while (l != null) {
-            if (!l.isEmpty()) {
-              sb.append(EOLN).append(l);
-            }
-            l = br.readLine();
-          }
-          br.close();
-        } catch (IOException ignore) {
-        }
-        logger.info(LocalizedMessage.create(
-            LocalizedStrings.GemFireCache_CACHE_INITIALIZED_USING__0__1, new 
Object[] {url.toString(), sb.toString()}));
-      } else {
-        logger.info(LocalizedMessage.create(
-            LocalizedStrings.GemFireCache_CACHE_INITIALIZED_USING__0__1, new 
Object[] {"generated description from old cache", cacheXmlDescription}));
-      }
     } catch (IOException 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);
+      throw new 
CacheXmlException(LocalizedStrings.GemFireCache_WHILE_OPENING_CACHE_XML_0_THE_FOLLOWING_ERROR_OCCURRED_1
+          .toLocalizedString(new Object[] { url.toString(), ex }));
 
     } catch (CacheXmlException ex) {
-      String exceptionMsg = 
LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1
-          .toLocalizedString(new Object[] { url, ex.getMessage() });
-      logger.error(exceptionMsg);
-      CacheXmlException newEx = new CacheXmlException(exceptionMsg);
+      CacheXmlException newEx = new 
CacheXmlException(LocalizedStrings.GemFireCache_WHILE_READING_CACHE_XML_0_1
+          .toLocalizedString(new Object[] { url, ex.getMessage() }));
       newEx.setStackTrace(ex.getStackTrace());
       newEx.initCause(ex.getCause());
       throw newEx;
     }
   }
 
+  private void logCacheXML(URL url, String cacheXmlDescription) {
+    if (cacheXmlDescription == null) {
+      StringBuilder sb = new StringBuilder();
+      try {
+        final String EOLN = System.getProperty("line.separator");
+        BufferedReader br = new BufferedReader(new 
InputStreamReader(url.openStream()));
+        String l = br.readLine();
+        while (l != null) {
+          if (!l.isEmpty()) {
+            sb.append(EOLN).append(l);
+          }
+          l = br.readLine();
+        }
+        br.close();
+      } catch (IOException ignore) {
+      }
+      logger.info(LocalizedMessage.create(
+          LocalizedStrings.GemFireCache_INITIALIZING_CACHE_USING__0__1, new 
Object[]{url.toString(), sb.toString()}));
+    } else {
+      logger.info(LocalizedMessage.create(
+          LocalizedStrings.GemFireCache_INITIALIZING_CACHE_USING__0__1, new 
Object[] {"generated description from old cache", cacheXmlDescription}));
+    }
+  }
+
   public synchronized void initializePdxRegistry() {
     if (this.pdxRegistry == null) {
       //The member with locator is initialized with a NullTypePdxRegistration

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
index 2bc2f05..2c12421 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/LocalRegion.java
@@ -611,7 +611,8 @@ public class LocalRegion extends AbstractRegion
     this.offHeap = attrs.getOffHeap() || 
Boolean.getBoolean(myName+":OFF_HEAP");
     if (getOffHeap()) {
       if (cache.getOffHeapStore() == null) {
-        throw new IllegalStateException("The region " + myName + " was 
configured to use off heap memory but no off heap memory was configured.");
+        throw new IllegalStateException(LocalizedStrings.
+            
LocalRegion_THE_REGION_0_WAS_CONFIGURED_TO_USE_OFF_HEAP_MEMORY_BUT_OFF_HEAP_NOT_CONFIGURED.toLocalizedString(myName));
       }
     }
     

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PoolManagerImpl.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PoolManagerImpl.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PoolManagerImpl.java
index 35b043f..effd7ed 100644
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PoolManagerImpl.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/cache/PoolManagerImpl.java
@@ -149,8 +149,8 @@ public class PoolManagerImpl {
       //debugStack("register pool=" + name);
       Object old = copy.put(name, pool);
       if (old != null) {
-        throw new IllegalStateException("A pool named \"" + name
-                                        + "\" already exists.");
+        throw new IllegalStateException(LocalizedStrings.
+            
PoolManagerImpl_POOL_NAMED_0_ALREADY_EXISTS.toLocalizedString(name));
       }
 //      Boolean specialCase=Boolean.getBoolean("gemfire.SPECIAL_DURABLE");
 //      if(specialCase && copy.size()>1){

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/ParentLocalizedStrings.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/ParentLocalizedStrings.java
 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/ParentLocalizedStrings.java
index 780fe18..c0ef60d 100755
--- 
a/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/ParentLocalizedStrings.java
+++ 
b/gemfire-core/src/main/java/com/gemstone/gemfire/internal/i18n/ParentLocalizedStrings.java
@@ -48,7 +48,7 @@ class ParentLocalizedStrings {
   public static final StringId AbstractHealthEvaluator_OKAY_HEALTH__0 = new 
StringId(1025, "OKAY_HEALTH:  {0}");
   public static final StringId AbstractHealthEvaluator_POOR_HEALTH__0 = new 
StringId(1026, "POOR_HEALTH:  {0}");
   public static final StringId AbstractRegion_CACHECALLBACK_CLOSE_EXCEPTION = 
new StringId(1027, "CacheCallback close exception");
-  // ok to reuse 1028
+  public static final StringId PoolManagerImpl_POOL_NAMED_0_ALREADY_EXISTS = 
new StringId(1028, "A pool named \"{0}\" already exists");
   public static final StringId 
AcceptorImpl_CACHE_SERVER_CONNECTION_LISTENER_BOUND_TO_ADDRESS_0_WITH_BACKLOG_1 
= new StringId(1029, "Cache server connection listener bound to address {0} 
with backlog {1}.");
   public static final StringId 
AcceptorImpl_CACHE_SERVER_FAILED_ACCEPTING_CLIENT_CONNECTION_DUE_TO_SOCKET_TIMEOUT
 = new StringId(1030, "Cache server: failed accepting client connection due to 
socket timeout.");
   public static final StringId 
AcceptorImpl_CACHE_SERVER_FAILED_ACCEPTING_CLIENT_CONNECTION__0 = new 
StringId(1031, "Cache server: failed accepting client connection  {0}");
@@ -87,7 +87,7 @@ class ParentLocalizedStrings {
   public static final StringId AgentImpl_SNMPADAPTOR_ALREADY_REGISTERED_AS__0 
= new StringId(1064, "SnmpAdaptor already registered as  {0}");
   public static final StringId AgentImpl_STOPPING_JMX_AGENT = new 
StringId(1065, "Stopping JMX agent");
   public static final StringId 
AgentImpl_XSLTPROCESSOR_ALREADY_REGISTERED_AS__0 = new StringId(1066, 
"XsltProcessor already registered as  {0}");
-  // ok to reuse 1067
+  public static final StringId 
AbstractRegion_THE_CONNECTION_POOL_0_HAS_NOT_BEEN_CREATED = new StringId(1067, 
"The connection pool \"{0}\" has not been created");
   public static final StringId 
AttributesFactory_0_WAS_NOT_AN_EXISTING_DIRECTORY = new StringId(1068, "\"{0}\" 
was not an existing directory.");
   public static final StringId 
AttributesFactory_ADDCACHELISTENER_PARAMETER_WAS_NULL = new StringId(1069, 
"addCacheListener parameter was null");
   public static final StringId 
AttributesFactory_AN_EVICTION_CONTROLLER_WITH_LOCAL_DESTROY_EVICTION_ACTION_IS_INCOMPATIBLE_WITH_DISTRIBUTED_REPLICATION
 = new StringId(1070, "An Eviction Controller with local destroy eviction 
action is incompatible with distributed replication");
@@ -140,7 +140,8 @@ class ParentLocalizedStrings {
   public static final StringId BaseCommand_UNKNOWN_QUERY_EXCEPTION = new 
StringId(1117, "Uknown query Exception.");
   public static final StringId BaseCommand_SEVERE_CACHE_EXCEPTION_0 = new 
StringId(1118, "Severe cache exception : {0}");
   public static final StringId 
BaseCommand_UNEXPECTED_QUERYINVALIDEXCEPTION_WHILE_PROCESSING_QUERY_0 = new 
StringId(1119, "Unexpected QueryInvalidException while processing query {0}");
-  // ok to reuse 1120..1121
+  public static final StringId 
LocalRegion_THE_REGION_0_WAS_CONFIGURED_TO_USE_OFF_HEAP_MEMORY_BUT_OFF_HEAP_NOT_CONFIGURED
 = new StringId(1120, "The region {0} was configured to use off heap memory but 
no off heap memory was configured");
+  // ok to reuse 1121
   public static final StringId CacheServerImpl_CACHESERVER_CONFIGURATION___0 = 
new StringId(1122, "CacheServer Configuration:   {0}");
   public static final StringId 
CacheServerImpl_FORCING_NOTIFYBYSUBSCRIPTION_TO_SUPPORT_DYNAMIC_REGIONS = new 
StringId(1123, "Forcing notifyBySubscription to support dynamic regions");
   // ok to reuse 1124..1130
@@ -599,7 +600,7 @@ class ParentLocalizedStrings {
   public static final StringId 
GemFireBasicDataSource_AN_EXCEPTION_WAS_CAUGHT_WHILE_TRYING_TO_LOAD_THE_DRIVER 
= new StringId(1589, "An Exception was caught while trying to load the driver. 
{0}");
   public static final StringId 
GemFireBasicDataSource_GEMFIREBASICDATASOURCE_GETCONNECTION_URL_FOR_THE_DATASOURCE_NOT_AVAILABLE
 = new StringId(1590, "GemFireBasicDataSource::getConnection:Url for the 
DataSource not available");
   public static final StringId GemFireCache_0__NOW_CLOSING = new 
StringId(1591, "{0} : Now closing.");
-  public static final StringId GemFireCache_CACHE_INITIALIZED_USING__0__1 = 
new StringId(1592, "Cache initialized using \"{0}\":{1}");
+  public static final StringId GemFireCache_INITIALIZING_CACHE_USING__0__1 = 
new StringId(1592, "Initializing cache using \"{0}\":{1}");
   public static final StringId 
GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_1 = new 
StringId(1593, "Failed to get the CqService, to close during cache close (1).");
   public static final StringId 
GemFireCache_FAILED_TO_GET_THE_CQSERVICE_TO_CLOSE_DURING_CACHE_CLOSE_2 = new 
StringId(1594, "Failed to get the CqService, to close during cache close (2).");
   public static final StringId GemFireCache_WHILE_READING_CACHE_XML_0_1 = new 
StringId(1595, "While reading Cache XML {0}. {1}");

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/test/java/com/gemstone/gemfire/cache/CacheFactoryTest.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache/CacheFactoryTest.java 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/CacheFactoryTest.java
new file mode 100644
index 0000000..7ca2b40
--- /dev/null
+++ 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache/CacheFactoryTest.java
@@ -0,0 +1,7 @@
+package com.gemstone.gemfire.cache;
+
+/**
+ * Created by sbawaskar on 1/18/16.
+ */
+public class CacheFactoryTest {
+}

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/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 adafa69..5c07546 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
@@ -25,6 +25,7 @@ import java.io.PrintWriter;
 import java.io.StringWriter;
 import java.util.Properties;
 
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import junit.framework.AssertionFailedError;
 
 import org.xml.sax.SAXException;
@@ -96,6 +97,8 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
     setXmlFile(nonExistent);
 //    System.out.println("testNonExistentFile - set: " + 
System.currentTimeMillis());
 
+    ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.
+        
GemFireCache_DECLARATIVE_CACHE_XML_FILERESOURCE_0_DOES_NOT_EXIST.toLocalizedString(nonExistent.getPath()));
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
@@ -103,6 +106,8 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase {
     } catch (CacheXmlException ex) {
 //      System.out.println("testNonExistentFile - caught: " + 
System.currentTimeMillis());
       // pass...
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -115,12 +120,16 @@ public class CacheXml30DUnitTest extends CacheXmlTestCase 
{
     dir.deleteOnExit();
     setXmlFile(dir);
 
+    ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.
+        
GemFireCache_DECLARATIVE_XML_FILE_0_IS_NOT_A_FILE.toLocalizedString(dir));
     try {
       getCache();
       fail("Should have thrown a CacheXmlException");
 
     } catch (CacheXmlException ex) {
       // pass...
+    } finally {
+      expectedException.remove();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/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 5a41d31..2e9f9cc 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 com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import dunit.DistributedTestCase;
 import org.xml.sax.SAXException;
 
@@ -143,6 +144,7 @@ public class CacheXml41DUnitTest extends CacheXml40DUnitTest
   {
     setXmlFile(findFile("unknownNamedAttributes.xml"));
 
+    ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.RegionAttributesCreation_CANNOT_REFERENCE_NONEXISTING_REGION_ATTRIBUTES_NAMED_0.toLocalizedString());
     try {
       getCache();
       fail("Should have thrown an IllegalStateException");
@@ -150,6 +152,8 @@ public class CacheXml41DUnitTest extends CacheXml40DUnitTest
     }
     catch (IllegalStateException ex) {
       // pass...
+    } finally {
+      expectedException.remove();
     }
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml57DUnitTest.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml57DUnitTest.java
 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml57DUnitTest.java
index 47bb612..6e5bf09 100644
--- 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml57DUnitTest.java
+++ 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml57DUnitTest.java
@@ -53,6 +53,7 @@ import 
com.gemstone.gemfire.internal.cache.xmlcache.Declarable2;
 import com.gemstone.gemfire.internal.cache.xmlcache.RegionAttributesCreation;
 import com.gemstone.gemfire.internal.cache.xmlcache.RegionCreation;
 
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import dunit.Host;
 import dunit.SerializableCallable;
 import dunit.VM;
@@ -326,10 +327,13 @@ public class CacheXml57DUnitTest extends 
CacheXml55DUnitTest
     RegionAttributesCreation attrs = new RegionAttributesCreation(cache);
     attrs.setPoolName("mypool");
     cache.createVMRegion("rootNORMAL", attrs);
+    ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.AbstractRegion_THE_CONNECTION_POOL_0_HAS_NOT_BEEN_CREATED.toLocalizedString("mypool"));
     try {
       testXml(cache);
       fail("expected IllegalStateException");
     } catch (IllegalStateException expected) {
+    } finally {
+      expectedException.remove();
     }
   }
   public void testAlreadyExistingPool() throws CacheException {
@@ -341,10 +345,13 @@ public class CacheXml57DUnitTest extends 
CacheXml55DUnitTest
       // now make sure declarative cache can't create the same pool
       CacheCreation cache = new CacheCreation();
       cache.createPoolFactory().addLocator(ALIAS2, 12345).create("mypool");
+      ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.PoolManagerImpl_POOL_NAMED_0_ALREADY_EXISTS.toLocalizedString("mypool"));
       try {
         testXml(cache);
         fail("expected IllegalStateException");
       } catch (IllegalStateException expected) {
+      } finally {
+        expectedException.remove();
       }
     } finally {
       PoolManager.close();

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/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 8699a05..ac78127 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
@@ -32,6 +32,7 @@ import 
com.gemstone.gemfire.internal.cache.xmlcache.RegionAttributesCreation;
 import com.gemstone.gemfire.internal.cache.xmlcache.ResourceManagerCreation;
 import com.gemstone.gemfire.internal.cache.xmlcache.SerializerCreation;
 
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 import dunit.DistributedTestCase;
 
 import java.io.DataInput;
@@ -192,11 +193,13 @@ public class CacheXml60DUnitTest extends 
CacheXml58DUnitTest
     rmc.setEvictionHeapPercentage(high);
     rmc.setCriticalHeapPercentage(low);
     cache.setResourceManagerCreation(rmc);
+    ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.MemoryMonitor_EVICTION_PERCENTAGE_LTE_CRITICAL_PERCENTAGE.toLocalizedString());
     try {
       testXml(cache);
       assertTrue(false);
     } catch (IllegalArgumentException expected) {
     } finally {
+      expectedException.remove();
       closeCache();
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml66DUnitTest.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml66DUnitTest.java
 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml66DUnitTest.java
index e531405..ce07ecb 100644
--- 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml66DUnitTest.java
+++ 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml66DUnitTest.java
@@ -40,6 +40,7 @@ import 
com.gemstone.gemfire.internal.cache.xmlcache.CacheTransactionManagerCreat
 import com.gemstone.gemfire.internal.cache.xmlcache.CacheXml;
 import com.gemstone.gemfire.internal.cache.xmlcache.ClientCacheCreation;
 import com.gemstone.gemfire.internal.cache.xmlcache.RegionAttributesCreation;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 
 /**
  * Tests 7.0 cache.xml feature : Fixed Partitioning.
@@ -352,11 +353,13 @@ public class CacheXml66DUnitTest extends 
CacheXml65DUnitTest{
     CacheTransactionManagerCreation txMgrCreation = new 
CacheTransactionManagerCreation();
     txMgrCreation.setWriter(new TestTransactionWriter());
     cc.addCacheTransactionManagerCreation(txMgrCreation);
+    ExpectedException expectedException = 
addExpectedException(LocalizedStrings.TXManager_NO_WRITER_ON_CLIENT.toLocalizedString());
     try {
-      addExpectedException("Connection refused: connect");
       testXml(cc);
       fail("expected exception not thrown");
     } catch (IllegalStateException e) {
+    } finally {
+      expectedException.remove();
     }
   }
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml90DUnitTest.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml90DUnitTest.java
 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml90DUnitTest.java
index 7fd2016..a3df9e9 100644
--- 
a/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml90DUnitTest.java
+++ 
b/gemfire-core/src/test/java/com/gemstone/gemfire/cache30/CacheXml90DUnitTest.java
@@ -28,6 +28,7 @@ import 
com.gemstone.gemfire.internal.cache.xmlcache.CacheCreation;
 import com.gemstone.gemfire.internal.cache.xmlcache.CacheXml;
 import com.gemstone.gemfire.internal.cache.xmlcache.RegionAttributesCreation;
 import com.gemstone.gemfire.internal.cache.xmlcache.ResourceManagerCreation;
+import com.gemstone.gemfire.internal.i18n.LocalizedStrings;
 
 
 public class CacheXml90DUnitTest extends CacheXml81DUnitTest {
@@ -89,12 +90,16 @@ public class CacheXml90DUnitTest extends 
CacheXml81DUnitTest {
     assertNotNull(regionBefore);
     assertEquals(true, regionBefore.getAttributes().getOffHeap());
 
+    ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.
+        
LocalRegion_THE_REGION_0_WAS_CONFIGURED_TO_USE_OFF_HEAP_MEMORY_BUT_OFF_HEAP_NOT_CONFIGURED.toLocalizedString("/"+regionName));
     try {
       testXml(cache);
     } catch (IllegalStateException e) {
       // expected
-      String msg = "The region /" + regionName + " was configured to use off 
heap memory but no off heap memory was configured.";
+      String msg = 
LocalizedStrings.LocalRegion_THE_REGION_0_WAS_CONFIGURED_TO_USE_OFF_HEAP_MEMORY_BUT_OFF_HEAP_NOT_CONFIGURED.toLocalizedString("/"+regionName);
       assertEquals(msg, e.getMessage());
+    } finally {
+      expectedException.remove();
     }
   }
   
@@ -119,13 +124,17 @@ public class CacheXml90DUnitTest extends 
CacheXml81DUnitTest {
     assertNotNull(subRegionBefore);
     assertEquals(true, subRegionBefore.getAttributes().getOffHeap());
 
+    ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.
+        
LocalRegion_THE_REGION_0_WAS_CONFIGURED_TO_USE_OFF_HEAP_MEMORY_BUT_OFF_HEAP_NOT_CONFIGURED.toLocalizedString("/"+rootRegionName+"/"+subRegionName));
     try {
       testXml(cache);
     } catch (IllegalStateException e) {
       // expected
-      final String msg = "The region /" + rootRegionName + "/" + subRegionName 
+
-          " was configured to use off heap memory but no off heap memory was 
configured.";
+      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());
+    } finally {
+      expectedException.remove();
     }
   }
 
@@ -172,11 +181,13 @@ public class CacheXml90DUnitTest extends 
CacheXml81DUnitTest {
       rmc.setEvictionOffHeapPercentage(high);
       rmc.setCriticalOffHeapPercentage(low);
       cache.setResourceManagerCreation(rmc);
+      ExpectedException expectedException = 
CacheTestCase.addExpectedException(LocalizedStrings.MemoryMonitor_EVICTION_PERCENTAGE_LTE_CRITICAL_PERCENTAGE.toLocalizedString());
       try {
         testXml(cache);
         assertTrue(false);
       } catch (IllegalArgumentException expected) {
       } finally {
+        expectedException.remove();
         closeCache();
       }
   

http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/22f31f8c/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/GemFireCacheImplTest.java
----------------------------------------------------------------------
diff --git 
a/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/GemFireCacheImplTest.java
 
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/GemFireCacheImplTest.java
new file mode 100644
index 0000000..9d62cfc
--- /dev/null
+++ 
b/gemfire-core/src/test/java/com/gemstone/gemfire/internal/cache/GemFireCacheImplTest.java
@@ -0,0 +1,7 @@
+package com.gemstone.gemfire.internal.cache;
+
+/**
+ * Created by sbawaskar on 1/18/16.
+ */
+public class GemFireCacheImplTest {
+}

Reply via email to