From b192e90444c12c4f5566ef286b1a143f34af0bff Mon Sep 17 00:00:00 2001 From: sampadawagde Date: Fri, 12 Jun 2020 12:11:48 +0530 Subject: [PATCH] JAVA-1848: Moved apache-curator to apache-libraries --- apache-curator/README.md | 7 -- apache-curator/pom.xml | 70 --------------- .../apache/curator/modeled/HostConfig.java | 31 ------- apache-curator/src/main/resources/logback.xml | 13 --- .../apache/curator/BaseManualTest.java | 22 ----- .../ConfigurationManagementManualTest.java | 89 ------------------- .../ConnectionManagementManualTest.java | 79 ---------------- .../modeled/ModelTypedExamplesManualTest.java | 49 ---------- .../curator/recipes/RecipesManualTest.java | 74 --------------- 9 files changed, 434 deletions(-) delete mode 100644 apache-curator/README.md delete mode 100644 apache-curator/pom.xml delete mode 100644 apache-curator/src/main/java/com/baeldung/apache/curator/modeled/HostConfig.java delete mode 100644 apache-curator/src/main/resources/logback.xml delete mode 100644 apache-curator/src/test/java/com/baeldung/apache/curator/BaseManualTest.java delete mode 100644 apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java delete mode 100644 apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java delete mode 100644 apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java delete mode 100644 apache-curator/src/test/java/com/baeldung/apache/curator/recipes/RecipesManualTest.java diff --git a/apache-curator/README.md b/apache-curator/README.md deleted file mode 100644 index 4fef6a138e..0000000000 --- a/apache-curator/README.md +++ /dev/null @@ -1,7 +0,0 @@ -## Apache Curator - -This module contains articles about Apache Curator - -### Relevant Articles: - -- [Introduction to Apache Curator](https://www.baeldung.com/apache-curator) diff --git a/apache-curator/pom.xml b/apache-curator/pom.xml deleted file mode 100644 index 5b249127d9..0000000000 --- a/apache-curator/pom.xml +++ /dev/null @@ -1,70 +0,0 @@ - - - 4.0.0 - apache-curator - 0.0.1-SNAPSHOT - apache-curator - jar - - - com.baeldung - parent-modules - 1.0.0-SNAPSHOT - - - - - - org.apache.curator - curator-x-async - ${curator.version} - - - org.apache.zookeeper - zookeeper - - - - - org.apache.curator - curator-recipes - ${curator.version} - - - org.apache.zookeeper - zookeeper - ${zookeeper.version} - - - - com.fasterxml.jackson.core - jackson-databind - ${jackson.version} - - - - org.assertj - assertj-core - ${assertj.version} - test - - - com.jayway.awaitility - awaitility - ${avaitility.version} - test - - - - - 4.0.1 - 3.4.11 - - 3.6.1 - 1.7.0 - - - \ No newline at end of file diff --git a/apache-curator/src/main/java/com/baeldung/apache/curator/modeled/HostConfig.java b/apache-curator/src/main/java/com/baeldung/apache/curator/modeled/HostConfig.java deleted file mode 100644 index bab7133742..0000000000 --- a/apache-curator/src/main/java/com/baeldung/apache/curator/modeled/HostConfig.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.baeldung.apache.curator.modeled; - -public class HostConfig { - private String hostname; - private int port; - - public HostConfig() { - - } - - public HostConfig(String hostname, int port) { - this.hostname = hostname; - this.port = port; - } - - public int getPort() { - return port; - } - - public void setPort(int port) { - this.port = port; - } - - public String getHostname() { - return hostname; - } - - public void setHostname(String hostname) { - this.hostname = hostname; - } -} diff --git a/apache-curator/src/main/resources/logback.xml b/apache-curator/src/main/resources/logback.xml deleted file mode 100644 index 7d900d8ea8..0000000000 --- a/apache-curator/src/main/resources/logback.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n - - - - - - - - \ No newline at end of file diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/BaseManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/BaseManualTest.java deleted file mode 100644 index 5722228b26..0000000000 --- a/apache-curator/src/test/java/com/baeldung/apache/curator/BaseManualTest.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.baeldung.apache.curator; - -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.RetryNTimes; -import org.junit.Before; - -public abstract class BaseManualTest { - - @Before - public void setup() { - org.apache.log4j.BasicConfigurator.configure(); - } - - protected CuratorFramework newClient() { - int sleepMsBetweenRetries = 100; - int maxRetries = 3; - RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries); - return CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy); - } -} diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java deleted file mode 100644 index 1a6fe6ccd0..0000000000 --- a/apache-curator/src/test/java/com/baeldung/apache/curator/configuration/ConfigurationManagementManualTest.java +++ /dev/null @@ -1,89 +0,0 @@ -package com.baeldung.apache.curator.configuration; - -import static com.jayway.awaitility.Awaitility.await; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.x.async.AsyncCuratorFramework; -import org.junit.Test; - -import com.baeldung.apache.curator.BaseManualTest; - -public class ConfigurationManagementManualTest extends BaseManualTest { - - private static final String KEY_FORMAT = "/%s"; - - @Test - public void givenPath_whenCreateKey_thenValueIsStored() throws Exception { - try (CuratorFramework client = newClient()) { - client.start(); - AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client); - String key = getKey(); - String expected = "my_value"; - - // Create key nodes structure - client.create() - .forPath(key); - - // Set data value for our key - async.setData() - .forPath(key, expected.getBytes()); - - // Get data value - AtomicBoolean isEquals = new AtomicBoolean(); - async.getData() - .forPath(key) - .thenAccept( - data -> isEquals.set(new String(data).equals(expected))); - - await().until(() -> assertThat(isEquals.get()).isTrue()); - } - } - - @Test - public void givenPath_whenWatchAKeyAndStoreAValue_thenWatcherIsTriggered() - throws Exception { - try (CuratorFramework client = newClient()) { - client.start(); - AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client); - String key = getKey(); - String expected = "my_value"; - - // Create key structure - async.create() - .forPath(key); - - List changes = new ArrayList<>(); - - // Watch data value - async.watched() - .getData() - .forPath(key) - .event() - .thenAccept(watchedEvent -> { - try { - changes.add(new String(client.getData() - .forPath(watchedEvent.getPath()))); - } catch (Exception e) { - // fail ... - } - }); - - // Set data value for our key - async.setData() - .forPath(key, expected.getBytes()); - - await().until(() -> assertThat(changes.size() > 0).isTrue()); - } - } - - private String getKey() { - return String.format(KEY_FORMAT, UUID.randomUUID() - .toString()); - } -} diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java deleted file mode 100644 index 61fa1c7c2c..0000000000 --- a/apache-curator/src/test/java/com/baeldung/apache/curator/connection/ConnectionManagementManualTest.java +++ /dev/null @@ -1,79 +0,0 @@ -package com.baeldung.apache.curator.connection; - -import static com.jayway.awaitility.Awaitility.await; -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.concurrent.atomic.AtomicBoolean; - -import org.apache.curator.RetryPolicy; -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.CuratorFrameworkFactory; -import org.apache.curator.retry.RetryNTimes; -import org.apache.curator.x.async.AsyncCuratorFramework; -import org.junit.Test; - -public class ConnectionManagementManualTest { - - @Test - public void givenRunningZookeeper_whenOpenConnection_thenClientIsOpened() - throws Exception { - int sleepMsBetweenRetries = 100; - int maxRetries = 3; - RetryPolicy retryPolicy = new RetryNTimes(maxRetries, - sleepMsBetweenRetries); - - try (CuratorFramework client = CuratorFrameworkFactory - .newClient("127.0.0.1:2181", retryPolicy)) { - client.start(); - - assertThat(client.checkExists() - .forPath("/")).isNotNull(); - } - } - - @Test - public void givenRunningZookeeper_whenOpenConnectionUsingAsyncNotBlocking_thenClientIsOpened() - throws InterruptedException { - int sleepMsBetweenRetries = 100; - int maxRetries = 3; - RetryPolicy retryPolicy = new RetryNTimes(maxRetries, - sleepMsBetweenRetries); - - try (CuratorFramework client = CuratorFrameworkFactory - .newClient("127.0.0.1:2181", retryPolicy)) { - client.start(); - AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client); - - AtomicBoolean exists = new AtomicBoolean(false); - - async.checkExists() - .forPath("/") - .thenAcceptAsync(s -> exists.set(s != null)); - - await().until(() -> assertThat(exists.get()).isTrue()); - } - } - - @Test - public void givenRunningZookeeper_whenOpenConnectionUsingAsyncBlocking_thenClientIsOpened() - throws InterruptedException { - int sleepMsBetweenRetries = 100; - int maxRetries = 3; - RetryPolicy retryPolicy = new RetryNTimes(maxRetries, - sleepMsBetweenRetries); - - try (CuratorFramework client = CuratorFrameworkFactory - .newClient("127.0.0.1:2181", retryPolicy)) { - client.start(); - AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client); - - AtomicBoolean exists = new AtomicBoolean(false); - - async.checkExists() - .forPath("/") - .thenAccept(s -> exists.set(s != null)); - - await().until(() -> assertThat(exists.get()).isTrue()); - } - } -} diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java deleted file mode 100644 index d7caa18ce9..0000000000 --- a/apache-curator/src/test/java/com/baeldung/apache/curator/modeled/ModelTypedExamplesManualTest.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.baeldung.apache.curator.modeled; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.fail; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.x.async.AsyncCuratorFramework; -import org.apache.curator.x.async.modeled.JacksonModelSerializer; -import org.apache.curator.x.async.modeled.ModelSpec; -import org.apache.curator.x.async.modeled.ModeledFramework; -import org.apache.curator.x.async.modeled.ZPath; -import org.junit.Test; - -import com.baeldung.apache.curator.BaseManualTest; - -public class ModelTypedExamplesManualTest extends BaseManualTest { - - @Test - public void givenPath_whenStoreAModel_thenNodesAreCreated() - throws InterruptedException { - - ModelSpec mySpec = ModelSpec - .builder(ZPath.parseWithIds("/config/dev"), - JacksonModelSerializer.build(HostConfig.class)) - .build(); - - try (CuratorFramework client = newClient()) { - client.start(); - AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client); - ModeledFramework modeledClient = ModeledFramework - .wrap(async, mySpec); - - modeledClient.set(new HostConfig("host-name", 8080)); - - modeledClient.read() - .whenComplete((value, e) -> { - if (e != null) { - fail("Cannot read host config", e); - } else { - assertThat(value).isNotNull(); - assertThat(value.getHostname()).isEqualTo("host-name"); - assertThat(value.getPort()).isEqualTo(8080); - } - - }); - } - - } -} diff --git a/apache-curator/src/test/java/com/baeldung/apache/curator/recipes/RecipesManualTest.java b/apache-curator/src/test/java/com/baeldung/apache/curator/recipes/RecipesManualTest.java deleted file mode 100644 index 0c5890ad59..0000000000 --- a/apache-curator/src/test/java/com/baeldung/apache/curator/recipes/RecipesManualTest.java +++ /dev/null @@ -1,74 +0,0 @@ -package com.baeldung.apache.curator.recipes; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.apache.curator.framework.CuratorFramework; -import org.apache.curator.framework.recipes.leader.LeaderSelector; -import org.apache.curator.framework.recipes.leader.LeaderSelectorListener; -import org.apache.curator.framework.recipes.locks.InterProcessSemaphoreMutex; -import org.apache.curator.framework.recipes.shared.SharedCount; -import org.apache.curator.framework.state.ConnectionState; -import org.junit.Test; - -import com.baeldung.apache.curator.BaseManualTest; - -public class RecipesManualTest extends BaseManualTest { - - @Test - public void givenRunningZookeeper_whenUsingLeaderElection_thenNoErrors() { - try (CuratorFramework client = newClient()) { - client.start(); - LeaderSelector leaderSelector = new LeaderSelector(client, "/mutex/select/leader/for/job/A", new LeaderSelectorListener() { - - @Override - public void stateChanged(CuratorFramework client, ConnectionState newState) { - - } - - @Override - public void takeLeadership(CuratorFramework client) throws Exception { - // I'm the leader of the job A ! - } - - }); - - leaderSelector.start(); - - // Wait until the job A is done among all the members - - leaderSelector.close(); - } - } - - @Test - public void givenRunningZookeeper_whenUsingSharedLock_thenNoErrors() throws Exception { - try (CuratorFramework client = newClient()) { - client.start(); - InterProcessSemaphoreMutex sharedLock = new InterProcessSemaphoreMutex(client, "/mutex/process/A"); - - sharedLock.acquire(); - - // Do process A - - sharedLock.release(); - } - } - - @Test - public void givenRunningZookeeper_whenUsingSharedCounter_thenCounterIsIncrement() throws Exception { - try (CuratorFramework client = newClient()) { - client.start(); - - try (SharedCount counter = new SharedCount(client, "/counters/A", 0)) { - counter.start(); - - counter.setCount(0); - counter.setCount(counter.getCount() + 1); - - assertThat(counter.getCount()).isEqualTo(1); - } - - } - } - -}