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

wirebaron 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 b9a37ce  GEODE-4614: Handle case where unable to find region while 
handling put request. (#2002)
b9a37ce is described below

commit b9a37cecbc6ac853ac35715da00652c194b64184
Author: Brian Rowe <[email protected]>
AuthorDate: Tue May 29 15:51:42 2018 -0700

    GEODE-4614: Handle case where unable to find region while handling put 
request. (#2002)
    
    Signed-off-by: Sean Goller <[email protected]>
---
 .../internal/cache/partitioned/PutMessage.java     | 27 +++------
 .../partitioned/RemotePutMessageJUnitTest.java     | 68 ++++++++++++++++++++++
 2 files changed, 75 insertions(+), 20 deletions(-)

diff --git 
a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PutMessage.java
 
b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PutMessage.java
index 9f71920..6d90096 100644
--- 
a/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PutMessage.java
+++ 
b/geode-core/src/main/java/org/apache/geode/internal/cache/partitioned/PutMessage.java
@@ -309,10 +309,9 @@ public class PutMessage extends 
PartitionMessageWithDirectReply implements NewVa
         processor);
   }
 
-
-  private PutMessage(Set recipients, boolean notifyOnly, int regionId,
-      DirectReplyProcessor processor, EntryEventImpl event, final long 
lastModified, boolean ifNew,
-      boolean ifOld, Object expectedOldValue, boolean requireOldValue) {
+  PutMessage(Set recipients, boolean notifyOnly, int regionId, 
DirectReplyProcessor processor,
+      EntryEventImpl event, final long lastModified, boolean ifNew, boolean 
ifOld,
+      Object expectedOldValue, boolean requireOldValue) {
     super(recipients, regionId, processor, event);
     this.processor = processor;
     this.notificationOnly = notifyOnly;
@@ -390,15 +389,6 @@ public class PutMessage extends 
PartitionMessageWithDirectReply implements NewVa
     return processor;
   }
 
-  // public final boolean needsDirectAck()
-  // {
-  // return this.directAck;
-  // }
-
-  // public final int getProcessorType() {
-  // return DistributionManager.PARTITIONED_REGION_EXECUTOR;
-  // }
-
 
   /**
    * create a new EntryEvent to be used in notifying listeners, bridge 
servers, etc. Caller must
@@ -558,13 +548,6 @@ public class PutMessage extends 
PartitionMessageWithDirectReply implements NewVa
     return this.eventId;
   }
 
-  /*
-   * @Override public String toString() { StringBuilder buff = new 
StringBuilder(super.toString());
-   * buff.append("; has old value="+this.hasOldValue);
-   * buff.append("; isOldValueSerialized ="+this.oldValueIsSerialized);
-   * buff.append("; oldvalue bytes="+this.oldValBytes);
-   * buff.append("; oldvalue object="+this.oldValObj); buff.toString(); return 
buff.toString(); }
-   */
   @Override
   public void toData(DataOutput out) throws IOException {
     PartitionedRegion region = null;
@@ -616,6 +599,10 @@ public class PutMessage extends 
PartitionMessageWithDirectReply implements NewVa
       } catch (PRLocallyDestroyedException e) {
         throw new IOException("Delta can not be extracted as region is locally 
destroyed");
       }
+      if (region == null || region.getCachePerfStats() == null) {
+        throw new IOException(
+            "Delta can not be extracted as region can't be found or is in an 
invalid state");
+      }
       DataSerializer.writeByteArray(this.event.getDeltaBytes(), out);
       region.getCachePerfStats().incDeltasSent();
     } else {
diff --git 
a/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/RemotePutMessageJUnitTest.java
 
b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/RemotePutMessageJUnitTest.java
new file mode 100644
index 0000000..8b2e6f9
--- /dev/null
+++ 
b/geode-core/src/test/java/org/apache/geode/internal/cache/partitioned/RemotePutMessageJUnitTest.java
@@ -0,0 +1,68 @@
+/*
+ * 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.partitioned;
+
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.ByteArrayOutputStream;
+import java.io.DataOutputStream;
+import java.io.IOException;
+import java.util.HashSet;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+import org.junit.rules.ExpectedException;
+
+import org.apache.geode.cache.Operation;
+import org.apache.geode.distributed.internal.DistributionConfig;
+import org.apache.geode.distributed.internal.InternalDistributedSystem;
+import org.apache.geode.internal.cache.EntryEventImpl;
+import org.apache.geode.internal.cache.EventID;
+import org.apache.geode.test.junit.categories.UnitTest;
+
+@Category(UnitTest.class)
+public class RemotePutMessageJUnitTest {
+  static final int UNKNOWN_REGION = 234;
+
+  @Rule
+  public ExpectedException thrown = ExpectedException.none();
+
+  @Test
+  public void putThrowsIOExceptionOnMissingRegion() throws Exception {
+    thrown.expect(IOException.class);
+
+    // Mocks with minimal implementation to ensure code path through 
PutMessage.toData
+    EntryEventImpl mockEvent = mock(EntryEventImpl.class);
+    when(mockEvent.isPossibleDuplicate()).thenReturn(false);
+    when(mockEvent.getEventId()).thenReturn(mock(EventID.class));
+    when(mockEvent.getOperation()).thenReturn(Operation.UPDATE);
+    when(mockEvent.getDeltaBytes()).thenReturn(new byte[] {});
+
+    DistributionConfig mockDistributionConfig = mock(DistributionConfig.class);
+    when(mockDistributionConfig.getDeltaPropagation()).thenReturn(true);
+    InternalDistributedSystem mockInternalDistributedSystem = 
mock(InternalDistributedSystem.class);
+    
when(mockInternalDistributedSystem.getConfig()).thenReturn(mockDistributionConfig);
+
+    // Construct a put with minimum configuration needed to reach region check.
+    PutMessage put = new PutMessage(new HashSet(), false, UNKNOWN_REGION, 
null, mockEvent, 0, false,
+        false, null, false);
+    put.setSendDelta(true);
+    put.setInternalDs(mockInternalDistributedSystem);
+
+    put.toData(new DataOutputStream(new ByteArrayOutputStream()));
+  }
+}

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to