[ 
https://issues.apache.org/jira/browse/GEODE-8647?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17221806#comment-17221806
 ] 

ASF GitHub Bot commented on GEODE-8647:
---------------------------------------

DonalEvans commented on a change in pull request #5667:
URL: https://github.com/apache/geode/pull/5667#discussion_r513070717



##########
File path: 
geode-dunit/src/distributedTest/java/org/apache/geode/test/dunit/rules/tests/DistributedMapTest.java
##########
@@ -491,4 +495,162 @@ public void getReturnsSameValueInEveryVmAsPutInOtherVm() {
       });
     }
   }
+
+  @Test
+  public void accessesDistributedMapInEachVm() {
+    runTestWithValidation(HasDistributedMap.class);
+  }
+
+  @Test
+  public void tearsDownDistributedMapInEachVm() {
+    runTestWithValidation(HasDistributedMap.class);
+
+    getController().invoke(() -> {
+      assertThat(HasDistributedMap.map.get()).isEmpty();
+    });
+  }
+
+  @Test
+  public void accessesTwoDistributedMapsInEachVm() {
+    runTestWithValidation(HasTwoDistributedMaps.class);
+  }
+
+  @Test
+  public void tearsDownTwoDistributedMapsInEachVm() {
+    runTestWithValidation(HasTwoDistributedMaps.class);
+
+    getController().invoke(() -> {
+      assertThat(HasTwoDistributedMaps.map1.get()).isEmpty();
+      assertThat(HasTwoDistributedMaps.map2.get()).isEmpty();
+    });
+  }
+
+  @Test
+  public void accessesManyDistributedMapsInEachVm() {
+    runTestWithValidation(HasManyDistributedMaps.class);
+  }
+
+  @Test
+  public void tearsDownManyDistributedMapsInEachVm() {
+    runTestWithValidation(HasManyDistributedMaps.class);
+
+    getController().invoke(() -> {
+      assertThat(HasManyDistributedMaps.map1.get()).isEmpty();
+      assertThat(HasManyDistributedMaps.map2.get()).isEmpty();
+      assertThat(HasManyDistributedMaps.map3.get()).isEmpty();
+    });
+  }
+
+  public static class HasDistributedMap implements Serializable {
+
+    private static final AtomicReference<Map<Object, Object>> map = new 
AtomicReference<>();
+
+    @Rule
+    public DistributedMap<Object, Object> distributedMap = new 
DistributedMap<>();
+
+    @Before
+    public void setUp() {
+      getController().invoke(() -> {
+        map.set(distributedMap.map());
+        distributedMap.put("key1", "value1");
+      });
+    }
+
+    @Test
+    public void distributedMapIsAccessibleInEveryVm() {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+        vm.invoke(() -> {
+          assertThat(distributedMap.map()).isSameAs(map.get());
+          assertThat(distributedMap.get("key1")).isEqualTo("value1");
+        });
+      }
+    }
+  }
+
+  public static class HasTwoDistributedMaps implements Serializable {
+
+    private static final AtomicReference<Map<Object, Object>> map1 = new 
AtomicReference<>();
+    private static final AtomicReference<Map<Object, Object>> map2 = new 
AtomicReference<>();
+
+    @Rule
+    public DistributedMap<Object, Object> distributedMap1 = new 
DistributedMap<>();
+    @Rule
+    public DistributedMap<Object, Object> distributedMap2 = new 
DistributedMap<>();
+
+    @Before
+    public void setUp() {
+      getController().invoke(() -> {
+        map1.set(distributedMap1.map());
+        distributedMap1.put("key1", "value1");
+
+        map2.set(distributedMap2.map());
+        distributedMap2.put("key2", "value2");
+      });
+    }
+
+    @Test
+    public void twoDistributedMapsAreAccessibleInEveryVm() {
+      for (VM vm : asList(getVM(0), getVM(1), getVM(2), getVM(3), 
getController())) {
+        vm.invoke(() -> {
+          assertThat(distributedMap1.map()).isSameAs(map1.get());
+          assertThat(distributedMap1.get("key1")).isEqualTo("value1");
+          assertThat(distributedMap1.get("key2")).isNull();
+
+          assertThat(distributedMap2.map()).isSameAs(map2.get());
+          assertThat(distributedMap2.get("key1")).isNull();
+          assertThat(distributedMap2.get("key2")).isEqualTo("value2");
+        });
+      }
+    }
+  }
+
+  public static class HasManyDistributedMaps implements Serializable {
+
+    private static final AtomicReference<Map<Object, Object>> map1 = new 
AtomicReference<>();
+    private static final AtomicReference<Map<Object, Object>> map2 = new 
AtomicReference<>();
+    private static final AtomicReference<Map<Object, Object>> map3 = new 
AtomicReference<>();
+
+    @Rule
+    public DistributedMap<Object, Object> distributedMap1 = new 
DistributedMap<>();
+    @Rule
+    public DistributedMap<Object, Object> distributedMap2 = new 
DistributedMap<>();
+    @Rule
+    public DistributedMap<Object, Object> distributedMap3 = new 
DistributedMap<>();
+
+    @Before
+    public void setUp() {
+      getController().invoke(() -> {
+        map1.set(distributedMap1.map());
+        distributedMap1.put("key1", "value1");
+
+        map2.set(distributedMap2.map());
+        distributedMap2.put("key2", "value2");
+
+        map3.set(distributedMap3.map());
+        distributedMap3.put("key3", "value3");

Review comment:
       Might it be worth extracting the hardcoded string keys/values in this 
test to constants?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


> Support using multiple DistributedMap Rules in one test
> -------------------------------------------------------
>
>                 Key: GEODE-8647
>                 URL: https://issues.apache.org/jira/browse/GEODE-8647
>             Project: Geode
>          Issue Type: Wish
>          Components: tests
>            Reporter: Kirk Lund
>            Assignee: Kirk Lund
>            Priority: Major
>              Labels: pull-request-available
>
> Support using multiple DistributedMap Rules in one test. Right now the Rule 
> only supports having one instance in a test.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to