You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by ag...@apache.org on 2017/11/21 23:57:54 UTC

[geode] branch develop updated: GEODE-3038: A server process shuts down quietly when path to cache.xml is incorrect (#677)

This is an automated email from the ASF dual-hosted git repository.

agingade pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode.git


The following commit(s) were added to refs/heads/develop by this push:
     new f429e9a  GEODE-3038: A server process shuts down quietly when path to cache.xml is incorrect (#677)
f429e9a is described below

commit f429e9a7eb5bad1ddb2b5eca81228887d87028b3
Author: Anton Mironenko <30...@users.noreply.github.com>
AuthorDate: Wed Nov 22 03:57:52 2017 +0400

    GEODE-3038: A server process shuts down quietly when path to cache.xml is incorrect (#677)
    
    Exception is thrown and logged when cache.xml is not found during cache creation
---
 .../geode/internal/cache/GemFireCacheImpl.java     |  3 +
 .../cache30/CacheXmlNotFoundRegressionTest.java    | 76 ++++++++++++++++++++++
 2 files changed, 79 insertions(+)

diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
index af525e8..fd8625c 100755
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/GemFireCacheImpl.java
@@ -1207,6 +1207,9 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
           this.system.getConfig().getGroups());
       initializeDeclarativeCache();
       completedCacheXml = true;
+    } catch (RuntimeException e) {
+      logger.error("Cache initialization failed because: " + e.toString()); // fix GEODE-3038
+      throw e;
     } finally {
       if (!completedCacheXml) {
         // so initializeDeclarativeCache threw an exception
diff --git a/geode-core/src/test/java/org/apache/geode/cache30/CacheXmlNotFoundRegressionTest.java b/geode-core/src/test/java/org/apache/geode/cache30/CacheXmlNotFoundRegressionTest.java
new file mode 100644
index 0000000..dc0d26a
--- /dev/null
+++ b/geode-core/src/test/java/org/apache/geode/cache30/CacheXmlNotFoundRegressionTest.java
@@ -0,0 +1,76 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License. You may obtain a
+ * copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
+ * or implied. See the License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package org.apache.geode.cache30;
+
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.CacheXmlException;
+import org.apache.geode.distributed.ConfigurationProperties;
+import org.apache.geode.test.junit.categories.IntegrationTest;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import java.io.File;
+import java.util.Properties;
+import java.util.Scanner;
+
+import static junit.framework.TestCase.assertTrue;
+import static org.junit.Assert.fail;
+
+@Category(IntegrationTest.class)
+public class CacheXmlNotFoundRegressionTest {
+
+  /**
+   * unit test for <a href="https://issues.apache.org/jira/browse/GEODE-3038">GEODE-3038</a> Tests
+   * that an error about missing cache-xml file is indeed printed in the text log file. The test
+   * {@link CacheXml66DUnitTest#testNonExistentFile()} is supposed to test the same, but is not
+   * enough. It only checks for an CacheXmlException exception to be thrown. Also in that test a log
+   * is printed into STDOUT, and we do see our error there, but that is not the case when we work
+   * with the real text log, specified via "log-file" param.
+   */
+  @Test
+  public void testCacheXmlNotFoundInRealLog() throws Exception {
+
+    String CACHE_SERVER_LOG = "cacheXmlNotFoundUnitTest.log";
+    Properties props = new Properties();
+    props.put(ConfigurationProperties.MCAST_PORT, "0");
+    props.put(ConfigurationProperties.LOG_FILE, CACHE_SERVER_LOG);
+    props.put(ConfigurationProperties.CACHE_XML_FILE, "non-existing-cache-xml");
+
+    CacheFactory factory = new CacheFactory(props);
+
+    String errorMessage = "";
+
+    try {
+      factory.create();
+      fail("Should have thrown a CacheXmlException");
+    } catch (CacheXmlException e) {
+      errorMessage = e.toString();
+    }
+
+    // looking for an error in the text log file
+    Scanner scanner = new Scanner(new File(CACHE_SERVER_LOG));
+
+    boolean found = false;
+    while (scanner.hasNextLine() && !found) {
+      found = scanner.nextLine().contains(errorMessage);
+    }
+    scanner.close();
+    assertTrue("there should be a line about cache-xml-not-found in a log file", found);
+
+    // deleting a log file
+    File logFile = new File(CACHE_SERVER_LOG);
+    logFile.delete();
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
['"commits@geode.apache.org" <co...@geode.apache.org>'].