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



##########
File path: 
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/RebalanceWhileCreatingRegionDistributedTest.java
##########
@@ -0,0 +1,193 @@
+/*
+ * 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 java.io.Serializable;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+import org.apache.logging.log4j.Logger;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.DistributionMessage;
+import org.apache.geode.distributed.internal.DistributionMessageObserver;
+import org.apache.geode.internal.cache.partitioned.RemoveBucketMessage;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.test.dunit.rules.ClientVM;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.DistributedBlackboard;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.SecurityTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+@Category({SecurityTest.class})
+public class RebalanceWhileCreatingRegionDistributedTest implements 
Serializable {
+
+  @Rule
+  public ClusterStartupRule cluster = new ClusterStartupRule();
+
+  @Rule
+  public SerializableTestName testName = new SerializableTestName();
+
+  @Rule
+  public DistributedBlackboard blackboard = new DistributedBlackboard();
+
+  private static final Logger logger = LogService.getLogger();
+
+  @Test
+  public void testRebalanceDuringRegionCreation() throws Exception {
+    // Init Blackboard
+    blackboard.initBlackboard();
+
+    // Start Locator
+    MemberVM locator = cluster.startLocatorVM(0);
+
+    // Start servers
+    int locatorPort = locator.getPort();
+    MemberVM server1 = cluster.startServerVM(1, locatorPort);
+    MemberVM server2 = cluster.startServerVM(2, locatorPort);
+    MemberVM accessor = cluster.startServerVM(4, locatorPort);
+
+    // Add DistributionMessageObserver
+    String regionName = testName.getMethodName();
+    Stream.of(server1, server2, accessor)
+        .forEach(server -> server.invoke(() -> 
addDistributionMessageObserver(regionName)));
+
+    // Create regions in each server
+    server1.invoke(() -> createRegion(regionName, RegionShortcut.PARTITION));
+    server2.invoke(() -> createRegion(regionName, RegionShortcut.PARTITION));
+
+    // Asynchronously wait to create the proxy region in the accessor
+    accessor.invokeAsync(() -> waitToCreateProxyRegion(regionName));
+
+    // Connect client1
+    ClientVM client1 =
+        cluster.startClientVM(5, c -> 
c.withServerConnection(server1.getPort(), server2.getPort()));
+
+    // Do puts
+    client1.invoke(() -> {
+      Region<Integer, Integer> region =
+          ClusterStartupRule.clientCacheRule.createProxyRegion(regionName);
+      IntStream.range(0, 3).forEach(i -> region.put(i, i));
+    });
+
+    // Start server3
+    MemberVM server3 = cluster.startServerVM(3, locatorPort);
+
+    // Create region in server3
+    server3.invoke(() -> createRegion(regionName, RegionShortcut.PARTITION));
+
+    // Add DistributionMessageObserver to server3
+    server3.invoke(() -> addDistributionMessageObserver(regionName));
+
+    // Rebalance
+    server1.invoke(() -> 
ClusterStartupRule.getCache().getResourceManager().createRebalanceFactory()
+        .start().getResults());
+
+    // Stop server3
+    server3.invoke(() -> ClusterStartupRule.getCache().close());
+
+    // Connect client to accessor
+    ClientVM client2 =
+        cluster.startClientVM(6, c -> 
c.withServerConnection(accessor.getPort())
+            .withCacheSetup(cf -> cf.setPoolReadTimeout(20000)));
+
+    // Do puts
+    client2.invoke(() -> {
+      Region<Integer, Integer> region =
+          ClusterStartupRule.clientCacheRule.createProxyRegion(regionName);
+      IntStream.range(0, 3).forEach(i -> region.put(i, i));
+    });
+  }
+
+  private void createRegion(String regionName, RegionShortcut shortcut) {
+    PartitionAttributesFactory<Integer, Integer> paf = new 
PartitionAttributesFactory<>();
+    paf.setRedundantCopies(0);
+    paf.setTotalNumBuckets(3);
+    if (shortcut.isProxy()) {
+      paf.setLocalMaxMemory(0);
+    }
+
+    RegionFactory<Integer, Integer> rf =
+        ClusterStartupRule.getCache().createRegionFactory(shortcut);
+    rf.setPartitionAttributes(paf.create());
+
+    rf.create(regionName);
+  }
+
+  private void waitToCreateProxyRegion(String regionName) throws Exception {
+    logger.info(
+        "RebalanceWhileCreatingRegionDistributedTest.waitToCreateRegion about 
to wait for Before_RemoveBucketMessage gate");
+    blackboard.waitForGate("Before_RemoveBucketMessage");

Review comment:
       Could the gate names in this test be extracted to constants please? It 
makes following the flow of events through the test easier if you can see each 
place a constant is used vs. having to search for a specific String.

##########
File path: 
geode-core/src/distributedTest/java/org/apache/geode/internal/cache/RebalanceWhileCreatingRegionDistributedTest.java
##########
@@ -0,0 +1,193 @@
+/*
+ * 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 java.io.Serializable;
+import java.util.stream.IntStream;
+import java.util.stream.Stream;
+
+import org.apache.logging.log4j.Logger;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.experimental.categories.Category;
+
+import org.apache.geode.cache.PartitionAttributesFactory;
+import org.apache.geode.cache.Region;
+import org.apache.geode.cache.RegionFactory;
+import org.apache.geode.cache.RegionShortcut;
+import org.apache.geode.distributed.internal.ClusterDistributionManager;
+import org.apache.geode.distributed.internal.DistributionMessage;
+import org.apache.geode.distributed.internal.DistributionMessageObserver;
+import org.apache.geode.internal.cache.partitioned.RemoveBucketMessage;
+import org.apache.geode.logging.internal.log4j.api.LogService;
+import org.apache.geode.test.dunit.rules.ClientVM;
+import org.apache.geode.test.dunit.rules.ClusterStartupRule;
+import org.apache.geode.test.dunit.rules.DistributedBlackboard;
+import org.apache.geode.test.dunit.rules.MemberVM;
+import org.apache.geode.test.junit.categories.SecurityTest;
+import org.apache.geode.test.junit.rules.serializable.SerializableTestName;
+
+@Category({SecurityTest.class})

Review comment:
       It's not clear to me why this test is related to security. Should this 
category be changed, or removed?




-- 
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.

To unsubscribe, e-mail: notifications-unsubscr...@geode.apache.org

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


Reply via email to