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 e78f932  GEODE-6497: Send failed message to image requester when 
provider is shutting down. (#3279)
e78f932 is described below

commit e78f932674ade7d774cbdd16f78cb24d646a8132
Author: pivotal-eshu <[email protected]>
AuthorDate: Fri Mar 8 10:08:35 2019 -0800

    GEODE-6497: Send failed message to image requester when provider is 
shutting down. (#3279)
---
 .../geode/internal/cache/InitialImageOperation.java  | 14 +++++++++-----
 .../internal/cache/InitialImageOperationTest.java    | 20 ++++++++++++++++++--
 2 files changed, 27 insertions(+), 7 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
index 635e8ee..81624f1 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/InitialImageOperation.java
@@ -1485,8 +1485,8 @@ public class InitialImageOperation {
         logger.debug("RequestImageMessage: attempting to get region reference 
for {}, initLevel={}",
             regionPath, initLevel);
       }
-      InternalCache cache = dm.getCache();
-      lclRgn = cache == null ? null : (LocalRegion) 
cache.getRegionByPath(regionPath);
+      InternalCache cache = dm.getExistingCache();
+      lclRgn = cache == null ? null : (LocalRegion) 
cache.getRegion(regionPath);
       // if this is a targeted getInitialImage after a region was initialized,
       // make sure this is the region that was reinitialized.
       if (lclRgn != null && !lclRgn.isUsedForPartitionedRegionBucket() && 
targetReinitialized
@@ -1875,9 +1875,7 @@ public class InitialImageOperation {
           if (thr != null) {
             rex = new ReplyException(thr);
           }
-          // null chunk signals receiver that we are aborting
-          ImageReplyMessage.send(getSender(), processorId, rex, dm, null, 0, 
0, 1, true, 0, false,
-              null, null);
+          sendFailureMessage(dm, rex);
         } // !success
 
         if (internalAfterSentImageReply != null
@@ -1887,6 +1885,12 @@ public class InitialImageOperation {
       }
     }
 
+    void sendFailureMessage(ClusterDistributionManager dm, ReplyException rex) 
{
+      // null chunk signals receiver that we are aborting
+      ImageReplyMessage.send(getSender(), processorId, rex, dm, null, 0, 0, 1, 
true, 0, false,
+          null, null);
+    }
+
 
     /**
      * Serialize the entries into byte[] chunks, calling proc for each one. 
proc args: the byte[]
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/InitialImageOperationTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/InitialImageOperationTest.java
index 840379a..64a09bb 100644
--- 
a/geode-core/src/test/java/org/apache/geode/internal/cache/InitialImageOperationTest.java
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/InitialImageOperationTest.java
@@ -15,12 +15,16 @@
 package org.apache.geode.internal.cache;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.eq;
 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.Before;
 import org.junit.Test;
 
+import org.apache.geode.cache.CacheClosedException;
 import org.apache.geode.cache.Scope;
 import org.apache.geode.distributed.internal.ClusterDistributionManager;
 
@@ -39,8 +43,8 @@ public class InitialImageOperationTest {
     dm = mock(ClusterDistributionManager.class);
     region = mock(LocalRegion.class);
 
-    when(dm.getCache()).thenReturn(cache);
-    when(cache.getRegionByPath(path)).thenReturn(region);
+    when(dm.getExistingCache()).thenReturn(cache);
+    when(cache.getRegion(path)).thenReturn(region);
     when(region.isInitialized()).thenReturn(true);
     when(region.getScope()).thenReturn(Scope.DISTRIBUTED_ACK);
   }
@@ -50,4 +54,16 @@ public class InitialImageOperationTest {
     LocalRegion value = InitialImageOperation.getGIIRegion(dm, path, false);
     assertThat(value).isSameAs(region);
   }
+
+  @Test
+  public void 
processRequestImageMessageWillSendFailureMessageIfGotCancelException() {
+    InitialImageOperation.RequestImageMessage message =
+        spy(new InitialImageOperation.RequestImageMessage());
+    message.regionPath = "regionPath";
+    when(dm.getExistingCache()).thenThrow(new CacheClosedException());
+
+    message.process(dm);
+
+    verify(message).sendFailureMessage(eq(dm), eq(null));
+  }
 }

Reply via email to