You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by bs...@apache.org on 2019/04/16 15:32:29 UTC

[geode] branch develop updated: GEODE-6651: Fixed NPE

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

bschuchardt 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 1726669  GEODE-6651: Fixed NPE
     new c3fb776  Merge pull request #3459 from Nordix/feature/GEODE-6651
1726669 is described below

commit 1726669bf1a0d304d962071da6cc69b7455c2f10
Author: Mario Ivanac <ma...@est.tech>
AuthorDate: Mon Apr 15 10:13:05 2019 +0200

    GEODE-6651: Fixed NPE
---
 .../cache/TXDetectReadConflictJUnitTest.java       | 105 +++++++++++++++++++++
 .../apache/geode/internal/cache/BucketRegion.java  |   3 +
 2 files changed, 108 insertions(+)

diff --git a/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/TXDetectReadConflictJUnitTest.java b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/TXDetectReadConflictJUnitTest.java
new file mode 100644
index 0000000..810f148
--- /dev/null
+++ b/geode-core/src/integrationTest/java/org/apache/geode/internal/cache/TXDetectReadConflictJUnitTest.java
@@ -0,0 +1,105 @@
+/*
+ * 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;
+
+import static org.apache.geode.distributed.ConfigurationProperties.LOCATORS;
+import static org.apache.geode.distributed.ConfigurationProperties.MCAST_PORT;
+import static org.junit.Assert.assertEquals;
+
+import java.util.Properties;
+
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.contrib.java.lang.system.RestoreSystemProperties;
+import org.junit.rules.TestName;
+
+import org.apache.geode.cache.Cache;
+import org.apache.geode.cache.CacheFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.distributed.internal.DistributionConfig;
+
+
+/**
+ * junit test for detecting read conflicts
+ */
+public class TXDetectReadConflictJUnitTest {
+
+  @Rule
+  public RestoreSystemProperties restoreSystemProperties = new RestoreSystemProperties();
+
+  @Rule
+  public TestName name = new TestName();
+
+  protected Cache cache = null;
+  protected Region region = null;
+  protected Region regionpr = null;
+
+
+  @Before
+  public void setUp() throws Exception {
+    System.setProperty(DistributionConfig.GEMFIRE_PREFIX + "detectReadConflicts", "true");
+    createCache();
+  }
+
+  protected void createCache() {
+    Properties props = new Properties();
+    props.put(MCAST_PORT, "0");
+    props.put(LOCATORS, "");
+    cache = new CacheFactory(props).create();
+    region = cache.createRegionFactory(RegionShortcut.REPLICATE).create("testRegionRR");
+  }
+
+  protected void createCachePR() {
+    Properties props = new Properties();
+    props.put(MCAST_PORT, "0");
+    props.put(LOCATORS, "");
+    cache = new CacheFactory(props).create();
+    regionpr = cache.createRegionFactory(RegionShortcut.PARTITION).create("testRegionPR");
+  }
+
+  @After
+  public void tearDown() throws Exception {
+    cache.close();
+  }
+
+  @Test
+  public void testReadConflictsRR() throws Exception {
+    cache.close();
+    createCache();
+    region.put("key", "value");
+    region.put("key1", "value1");
+    TXManagerImpl mgr = (TXManagerImpl) cache.getCacheTransactionManager();
+    mgr.begin();
+    assertEquals("value", region.get("key"));
+    assertEquals("value1", region.get("key1"));
+    mgr.commit();
+  }
+
+  @Test
+  public void testReadConflictsPR() throws Exception {
+    cache.close();
+    createCachePR();
+    regionpr.put("key", "value");
+    regionpr.put("key1", "value1");
+    TXManagerImpl mgr = (TXManagerImpl) cache.getCacheTransactionManager();
+    mgr.begin();
+    assertEquals("value", regionpr.get("key"));
+    assertEquals("value1", regionpr.get("key1"));
+    mgr.commit();
+  }
+}
diff --git a/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRegion.java b/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRegion.java
index f1c7018..4853090 100644
--- a/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRegion.java
+++ b/geode-core/src/main/java/org/apache/geode/internal/cache/BucketRegion.java
@@ -1882,6 +1882,9 @@ public class BucketRegion extends DistributedRegion implements Bucket {
       Set<InternalDistributedMember> cacheOpReceivers, Set<InternalDistributedMember> twoMessages,
       FilterRoutingInfo routing) {
     Operation op = event.getOperation();
+    if (op == null) {
+      return Collections.emptySet();
+    }
     if (op.isUpdate() || op.isCreate() || op.isDestroy() || op.isInvalidate()) {
       // this method can safely assume that the operation is being distributed from
       // the primary bucket holder to other nodes