You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jc...@apache.org on 2021/02/23 19:26:06 UTC
[geode] branch support/1.12 updated: GEODE-8815: Cache could close
with uncaught exception (#5882)
This is an automated email from the ASF dual-hosted git repository.
jchen21 pushed a commit to branch support/1.12
in repository https://gitbox.apache.org/repos/asf/geode.git
The following commit(s) were added to refs/heads/support/1.12 by this push:
new 313bc11 GEODE-8815: Cache could close with uncaught exception (#5882)
313bc11 is described below
commit 313bc1109631ed71be6473451f14d266385fbe2a
Author: Jianxia Chen <11...@users.noreply.github.com>
AuthorDate: Fri Jan 8 18:09:39 2021 -0800
GEODE-8815: Cache could close with uncaught exception (#5882)
* Catch and log all possible throwables before closing the cache
* Add a unit test
(cherry picked from commit 84f43e1ed75e670de4fe8663e4da7dfa952ffa87)
---
.../geode/internal/cache/GemFireCacheImpl.java | 6 +++---
.../geode/internal/cache/GemFireCacheImplTest.java | 24 ++++++++++++++++++++++
2 files changed, 27 insertions(+), 3 deletions(-)
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 78c0217..07524d4 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
@@ -1373,9 +1373,9 @@ public class GemFireCacheImpl implements InternalCache, InternalClientCache, Has
}
initializeDeclarativeCache();
completedCacheXml = true;
- } catch (RuntimeException e) {
- logger.error("Cache initialization for {} failed because: {}", this, e);
- throw e;
+ } catch (Throwable throwable) {
+ logger.error("Cache initialization for {} failed because: {}", this, throwable);
+ throw throwable;
} finally {
if (!completedCacheXml) {
// so initializeDeclarativeCache threw an exception
diff --git a/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java b/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
index a0e7f28..87914d3 100644
--- a/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
+++ b/geode-core/src/test/java/org/apache/geode/internal/cache/GemFireCacheImplTest.java
@@ -14,9 +14,11 @@
*/
package org.apache.geode.internal.cache;
+import static org.apache.geode.distributed.internal.ClusterDistributionManager.LOCATOR_DM_TYPE;
import static org.apache.geode.distributed.internal.InternalDistributedSystem.ALLOW_MULTIPLE_SYSTEMS_PROPERTY;
import static org.apache.geode.test.awaitility.GeodeAwaitility.await;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.assertj.core.api.Assertions.catchThrowable;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.mock;
@@ -24,6 +26,7 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.io.File;
import java.io.NotSerializableException;
import java.util.List;
import java.util.Properties;
@@ -50,6 +53,7 @@ import org.apache.geode.distributed.internal.DistributionConfig;
import org.apache.geode.distributed.internal.DistributionManager;
import org.apache.geode.distributed.internal.InternalDistributedSystem;
import org.apache.geode.distributed.internal.ReplyProcessor21;
+import org.apache.geode.distributed.internal.membership.InternalDistributedMember;
import org.apache.geode.internal.SystemTimer;
import org.apache.geode.internal.cache.GemFireCacheImpl.ReplyProcessor21Factory;
import org.apache.geode.internal.cache.control.InternalResourceManager;
@@ -620,6 +624,26 @@ public class GemFireCacheImplTest {
.isSameAs(gemFireCacheImpl.getCacheServers());
}
+ @Test
+ public void anythingThrownDuringInitializeDeclarativeCacheShouldBeCaughtAndFinallyCloseCache() {
+ InternalDistributedMember internalDistributedMember = mock(InternalDistributedMember.class);
+ when(internalDistributedSystem.getDistributedMember()).thenReturn(internalDistributedMember);
+ DistributionConfig distributionConfig = mock(DistributionConfig.class);
+ when(internalDistributedSystem.getConfig()).thenReturn(distributionConfig);
+ File file = mock(File.class);
+ when(distributionConfig.getDeployWorkingDir()).thenReturn(file);
+ when(file.canWrite()).thenReturn(true);
+ when(file.listFiles()).thenReturn(new File[0]);
+ when(file.list()).thenReturn(new String[0]);
+ when(internalDistributedMember.getVmKind()).thenReturn(LOCATOR_DM_TYPE);
+ when(internalDistributedSystem.getDistributedMember())
+ .thenThrow(new Error("Expected error by test."));
+ assertThat(gemFireCacheImpl.isClosed()).isFalse();
+ assertThatThrownBy(() -> gemFireCacheImpl.initialize()).isInstanceOf(Error.class)
+ .hasMessageContaining("Expected error by test.");
+ assertThat(gemFireCacheImpl.isClosed()).isTrue();
+ }
+
@SuppressWarnings({"LambdaParameterHidesMemberVariable", "OverlyCoupledMethod", "unchecked"})
private GemFireCacheImpl gemFireCacheImpl(boolean useAsyncEventListeners) {
return new GemFireCacheImpl(