|
@@ -27,6 +27,7 @@ import org.apache.curator.framework.CuratorFramework;
|
|
|
import org.apache.curator.framework.CuratorFrameworkFactory;
|
|
|
import org.apache.curator.framework.recipes.cache.CuratorCache;
|
|
|
import org.apache.curator.retry.RetryOneTime;
|
|
|
+import org.apache.curator.test.TestingCluster;
|
|
|
import org.apache.curator.test.TestingServer;
|
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
|
@@ -40,26 +41,38 @@ public class TestApacheCuratorCompatibility {
|
|
|
@Test
|
|
|
public void testBasicUsageOfApisAndRecipes() throws Exception {
|
|
|
try (TestingServer server = new TestingServer()) {
|
|
|
- RetryOneTime retryPolicy = new RetryOneTime(1);
|
|
|
- try (CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy)) {
|
|
|
- try (CuratorCache cache = CuratorCache.build(client, "/base/path")) {
|
|
|
- client.start();
|
|
|
- cache.start();
|
|
|
+ doTest(server.getConnectString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testBasicUsageOfApisAndRecipesInCluster() throws Exception {
|
|
|
+ try (TestingCluster cluster = new TestingCluster(3)) {
|
|
|
+ cluster.start();
|
|
|
+ doTest(cluster.getConnectString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void doTest(String connectionString) throws Exception {
|
|
|
+ RetryOneTime retryPolicy = new RetryOneTime(1);
|
|
|
+ try (CuratorFramework client = CuratorFrameworkFactory.newClient(connectionString, retryPolicy)) {
|
|
|
+ try (CuratorCache cache = CuratorCache.build(client, "/base/path")) {
|
|
|
+ client.start();
|
|
|
+ cache.start();
|
|
|
|
|
|
- BlockingQueue<String> paths = new LinkedBlockingQueue<>();
|
|
|
- cache.listenable().addListener((dummy1, dummy2, data) -> paths.add(data.getPath()));
|
|
|
+ BlockingQueue<String> paths = new LinkedBlockingQueue<>();
|
|
|
+ cache.listenable().addListener((dummy1, dummy2, data) -> paths.add(data.getPath()));
|
|
|
|
|
|
- client.create().creatingParentsIfNeeded().forPath("/base/path/1");
|
|
|
- client.create().creatingParentsIfNeeded().forPath("/base/path/2");
|
|
|
- client.create().creatingParentsIfNeeded().forPath("/base/path/1/a");
|
|
|
- client.create().creatingParentsIfNeeded().forPath("/base/path/2/a");
|
|
|
+ client.create().creatingParentsIfNeeded().forPath("/base/path/1");
|
|
|
+ client.create().creatingParentsIfNeeded().forPath("/base/path/2");
|
|
|
+ client.create().creatingParentsIfNeeded().forPath("/base/path/1/a");
|
|
|
+ client.create().creatingParentsIfNeeded().forPath("/base/path/2/a");
|
|
|
|
|
|
- assertEquals("/base/path", poll(paths));
|
|
|
- assertEquals("/base/path/1", poll(paths));
|
|
|
- assertEquals("/base/path/2", poll(paths));
|
|
|
- assertEquals("/base/path/1/a", poll(paths));
|
|
|
- assertEquals("/base/path/2/a", poll(paths));
|
|
|
- }
|
|
|
+ assertEquals("/base/path", poll(paths));
|
|
|
+ assertEquals("/base/path/1", poll(paths));
|
|
|
+ assertEquals("/base/path/2", poll(paths));
|
|
|
+ assertEquals("/base/path/1/a", poll(paths));
|
|
|
+ assertEquals("/base/path/2/a", poll(paths));
|
|
|
}
|
|
|
}
|
|
|
}
|