This is an automated email from the ASF dual-hosted git repository.
xyuanlu pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/helix.git
The following commit(s) were added to refs/heads/master by this push:
new 2ebe87f0e Refactor TestRoutingTableProvider (#2476)
2ebe87f0e is described below
commit 2ebe87f0e59d611e7ab748ac97159fa3e3384489
Author: xyuanlu <[email protected]>
AuthorDate: Tue May 9 08:24:57 2023 -0700
Refactor TestRoutingTableProvider (#2476)
Refactor TestRoutingTableProvider
---
.../spectator/TestRoutingTableProvider.java | 35 ++++++++--------------
1 file changed, 13 insertions(+), 22 deletions(-)
diff --git
a/helix-core/src/test/java/org/apache/helix/integration/spectator/TestRoutingTableProvider.java
b/helix-core/src/test/java/org/apache/helix/integration/spectator/TestRoutingTableProvider.java
index 93c73fbc5..d79ca0be1 100644
---
a/helix-core/src/test/java/org/apache/helix/integration/spectator/TestRoutingTableProvider.java
+++
b/helix-core/src/test/java/org/apache/helix/integration/spectator/TestRoutingTableProvider.java
@@ -29,7 +29,8 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.concurrent.atomic.AtomicBoolean;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
import org.apache.helix.AccessOption;
import org.apache.helix.HelixException;
@@ -82,8 +83,6 @@ public class TestRoutingTableProvider extends ZkTestBase {
private boolean _listenerTestResult = true;
- private static final AtomicBoolean customizedViewChangeCalled = new
AtomicBoolean(false);
-
class MockRoutingTableChangeListener implements RoutingTableChangeListener {
boolean routingTableChangeReceived = false;
@@ -108,19 +107,6 @@ public class TestRoutingTableProvider extends ZkTestBase {
}
}
- class MockRoutingTableProvider extends RoutingTableProvider {
- MockRoutingTableProvider(HelixManager helixManager, Map<PropertyType,
List<String>> sourceDataTypes) {
- super(helixManager, sourceDataTypes);
- }
-
- @Override
- public void onCustomizedViewChange(List<CustomizedView> customizedViewList,
- NotificationContext changeContext){
- customizedViewChangeCalled.getAndSet(true);
- super.onCustomizedViewChange(customizedViewList, changeContext);
- }
- }
-
@BeforeClass
public void beforeClass() throws Exception {
System.out.println(
@@ -298,21 +284,26 @@ public class TestRoutingTableProvider extends ZkTestBase {
public void testCustomizedViewCorrectConstructor() throws Exception {
Map<PropertyType, List<String>> sourceDataTypes = new HashMap<>();
sourceDataTypes.put(PropertyType.CUSTOMIZEDVIEW, Arrays.asList("typeA"));
- MockRoutingTableProvider routingTableProvider =
- new MockRoutingTableProvider(_spectator, sourceDataTypes);
+ CountDownLatch countDownLatch = new CountDownLatch(1);
+ RoutingTableProvider routingTableProvider =
+ new RoutingTableProvider(_spectator, sourceDataTypes) {
+ @Override
+ public void onCustomizedViewChange(List<CustomizedView>
customizedViewList,
+ NotificationContext changeContext){
+ countDownLatch.countDown();
+ super.onCustomizedViewChange(customizedViewList, changeContext);
+ }
+ };
CustomizedView customizedView = new CustomizedView(TEST_DB);
customizedView.setState("p1", "h1", "testState");
// Clear the flag before writing to the Customized View Path
- customizedViewChangeCalled.getAndSet(false);
String customizedViewPath =
PropertyPathBuilder.customizedView(CLUSTER_NAME, "typeA", TEST_DB);
_spectator.getHelixDataAccessor().getBaseDataAccessor().set(customizedViewPath,
customizedView.getRecord(), AccessOption.PERSISTENT);
- boolean onCustomizedViewChangeCalled =
- TestHelper.verify(() -> customizedViewChangeCalled.get(),
WAIT_DURATION);
- Assert.assertTrue(onCustomizedViewChangeCalled);
+ Assert.assertTrue(countDownLatch.await(WAIT_DURATION,
TimeUnit.MILLISECONDS));
_spectator.getHelixDataAccessor().getBaseDataAccessor().remove(customizedViewPath,
AccessOption.PERSISTENT);