You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@curator.apache.org by ti...@apache.org on 2023/09/14 18:07:09 UTC
[curator] 01/02: speed up tests
This is an automated email from the ASF dual-hosted git repository.
tison pushed a commit to branch CURATOR-690.-CuratorCache-fails-to-load-the-cache-if-there-are-more-than-64K-child-ZNodes
in repository https://gitbox.apache.org/repos/asf/curator.git
commit 929a89f6f09329c8597f0483c4b035ebc6525d48
Author: tison <wa...@gmail.com>
AuthorDate: Fri Sep 15 01:48:48 2023 +0800
speed up tests
Signed-off-by: tison <wa...@gmail.com>
---
.../framework/recipes/cache/CuratorCacheImpl.java | 8 ++++--
.../framework/recipes/cache/TestCuratorCache.java | 33 ++++++++++++++++------
.../org/apache/curator/test/BaseClassForTests.java | 2 +-
3 files changed, 30 insertions(+), 13 deletions(-)
diff --git a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/CuratorCacheImpl.java b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/CuratorCacheImpl.java
index 99913f4d..50760dd2 100644
--- a/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/CuratorCacheImpl.java
+++ b/curator-recipes/src/main/java/org/apache/curator/framework/recipes/cache/CuratorCacheImpl.java
@@ -19,7 +19,9 @@
package org.apache.curator.framework.recipes.cache;
-import static org.apache.curator.framework.recipes.cache.CuratorCacheListener.Type.*;
+import static org.apache.curator.framework.recipes.cache.CuratorCacheListener.Type.NODE_CHANGED;
+import static org.apache.curator.framework.recipes.cache.CuratorCacheListener.Type.NODE_CREATED;
+import static org.apache.curator.framework.recipes.cache.CuratorCacheListener.Type.NODE_DELETED;
import static org.apache.zookeeper.KeeperException.Code.NONODE;
import static org.apache.zookeeper.KeeperException.Code.OK;
import com.google.common.annotations.VisibleForTesting;
@@ -64,8 +66,8 @@ class CuratorCacheImpl implements CuratorCache, CuratorCacheBridge {
protected boolean onAdvance(int phase, int registeredParties) {
callListeners(CuratorCacheListener::initialized);
synchronized (CuratorCacheImpl.this) {
- currentChildPhaser = rootPhaser;
- }
+ currentChildPhaser = rootPhaser;
+ }
return true;
}
};
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestCuratorCache.java b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestCuratorCache.java
index adfc0e41..fe37d674 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestCuratorCache.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/cache/TestCuratorCache.java
@@ -23,11 +23,14 @@ import static org.apache.curator.framework.recipes.cache.CuratorCache.Options.DO
import static org.apache.curator.framework.recipes.cache.CuratorCacheListener.builder;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
+import java.util.ArrayList;
+import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Semaphore;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
+import org.apache.curator.framework.api.transaction.CuratorOp;
import org.apache.curator.retry.RetryOneTime;
import org.apache.curator.test.compatibility.CuratorTestBase;
import org.junit.jupiter.api.Tag;
@@ -186,7 +189,10 @@ public class TestCuratorCache extends CuratorTestBase {
final CuratorCacheStorage storage = new StandardCuratorCacheStorage(false);
// Phaser has a hard-limit of 64k registrants; we need to create more than that to trigger the initial problem.
- final int zNodeCount = 0xffff + 5;
+ final int zNodeCount = 0xFFFF + 5;
+
+ // Bulk creations in multiOp for (1) speed up creations (2) not exceed jute.maxbuffer size.
+ final int bulkSize = 10000;
try (CuratorFramework client = CuratorFrameworkFactory.newClient(
server.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1))) {
@@ -194,20 +200,29 @@ public class TestCuratorCache extends CuratorTestBase {
final CountDownLatch initializedLatch = new CountDownLatch(1);
client.create().creatingParentsIfNeeded().forPath("/test");
-
+ final List<CuratorOp> creations = new ArrayList<>();
for (int i = 0; i < zNodeCount; i++) {
- client.create().forPath("/test/node_" + i);
+ creations.add(client.transactionOp().create().forPath("/test/node_" + i));
+ if (creations.size() > bulkSize) {
+ client.transaction().forOperations(creations);
+ creations.clear();
+ }
}
+ client.transaction().forOperations(creations);
+ creations.clear();
- try (CuratorCache cache = CuratorCache.builder(client, "/test").withStorage(storage).build()) {
- cache.listenable()
- .addListener(builder()
- .forInitialized(() -> initializedLatch.countDown())
- .build());
+ try (CuratorCache cache =
+ CuratorCache.builder(client, "/test").withStorage(storage).build()) {
+ final CuratorCacheListener listener =
+ builder().forInitialized(initializedLatch::countDown).build();
+ cache.listenable().addListener(listener);
cache.start();
assertTrue(timing.awaitLatch(initializedLatch));
- assertEquals(zNodeCount + 1, cache.size(), "Cache size should be equal to the number of zNodes created plus the root");
+ assertEquals(
+ zNodeCount + 1,
+ cache.size(),
+ "Cache size should be equal to the number of zNodes created plus the root");
}
}
}
diff --git a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
index 76a87ad8..b66a7e52 100644
--- a/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
+++ b/curator-test/src/main/java/org/apache/curator/test/BaseClassForTests.java
@@ -30,7 +30,7 @@ import org.slf4j.LoggerFactory;
public class BaseClassForTests {
protected volatile TestingServer server;
- private final Logger log = LoggerFactory.getLogger(getClass());
+ protected final Logger log = LoggerFactory.getLogger(getClass());
private final AtomicBoolean isRetrying = new AtomicBoolean(false);
private static final String INTERNAL_PROPERTY_DONT_LOG_CONNECTION_ISSUES;