This is an automated email from the ASF dual-hosted git repository.
eshu11 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 a441757 GEODE-6477: Reply with exception if exception occurred during
processing the message. (#3258)
a441757 is described below
commit a441757759819afa1fcfc3a36e10d4f22e762abe
Author: pivotal-eshu <[email protected]>
AuthorDate: Mon Mar 4 09:25:25 2019 -0800
GEODE-6477: Reply with exception if exception occurred during processing
the message. (#3258)
---
.../PrepareNewPersistentMemberMessage.java | 8 ++-
.../PrepareNewPersistentMemberMessageTest.java | 62 ++++++++++++++++++++++
2 files changed, 69 insertions(+), 1 deletion(-)
diff --git
a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/PrepareNewPersistentMemberMessage.java
b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/PrepareNewPersistentMemberMessage.java
index 2325cd0..82e6719 100644
---
a/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/PrepareNewPersistentMemberMessage.java
+++
b/geode-core/src/main/java/org/apache/geode/internal/cache/persistence/PrepareNewPersistentMemberMessage.java
@@ -105,8 +105,10 @@ public class PrepareNewPersistentMemberMessage extends
HighPriorityDistributionM
} catch (RegionDestroyedException e) {
logger.debug("<RegionDestroyed> {}", this);
+ exception = new ReplyException(e);
} catch (CancelException e) {
logger.debug("<CancelException> {}", this);
+ exception = new ReplyException(e);
} catch (VirtualMachineError e) {
SystemFailure.initiateFailure(e);
throw e;
@@ -115,7 +117,7 @@ public class PrepareNewPersistentMemberMessage extends
HighPriorityDistributionM
exception = new ReplyException(t);
} finally {
LocalRegion.setThreadInitLevelRequirement(oldLevel);
- ReplyMessage replyMsg = new ReplyMessage();
+ ReplyMessage replyMsg = createReplyMessage();
replyMsg.setRecipient(getSender());
replyMsg.setProcessorId(processorId);
if (exception != null) {
@@ -125,6 +127,10 @@ public class PrepareNewPersistentMemberMessage extends
HighPriorityDistributionM
}
}
+ ReplyMessage createReplyMessage() {
+ return new ReplyMessage();
+ }
+
@Override
public int getDSFID() {
return PREPARE_NEW_PERSISTENT_MEMBER_REQUEST;
diff --git
a/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/PrepareNewPersistentMemberMessageTest.java
b/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/PrepareNewPersistentMemberMessageTest.java
new file mode 100644
index 0000000..78377d3
--- /dev/null
+++
b/geode-core/src/test/java/org/apache/geode/internal/cache/persistence/PrepareNewPersistentMemberMessageTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.internal.cache.persistence;
+
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.doReturn;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
+
+import org.junit.Test;
+
+import org.apache.geode.cache.CacheClosedException;
+import org.apache.geode.cache.RegionDestroyedException;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.ReplyMessage;
+import org.apache.geode.internal.cache.InternalCache;
+
+public class PrepareNewPersistentMemberMessageTest {
+ private final ClusterDistributionManager manager =
mock(ClusterDistributionManager.class);
+ private final ReplyMessage replyMessage = mock(ReplyMessage.class);
+ private final InternalCache cache = mock(InternalCache.class);
+ private final String regionPath = "regionPath";
+
+ @Test
+ public void
processMessageSendReplyWithExceptionIfFailedWithCancelledException() {
+ PrepareNewPersistentMemberMessage message = spy(new
PrepareNewPersistentMemberMessage());
+ when(manager.getExistingCache()).thenThrow(new CacheClosedException());
+ doReturn(replyMessage).when(message).createReplyMessage();
+
+ message.process(manager);
+
+ verify(replyMessage).setException(any());
+ }
+
+ @Test
+ public void
processMessageSendReplyWithExceptionIfFailedWithRegionDestroyedException() {
+ PrepareNewPersistentMemberMessage message =
+ spy(new PrepareNewPersistentMemberMessage(regionPath, null, null, 1));
+ when(manager.getExistingCache()).thenReturn(cache);
+ when(cache.getRegion(regionPath)).thenThrow(new
RegionDestroyedException("", ""));
+ doReturn(replyMessage).when(message).createReplyMessage();
+
+ message.process(manager);
+
+ verify(replyMessage).setException(any());
+ }
+
+}