Skip to content

Commit

Permalink
[test] add test check for otherConnectionStr.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhantomThief committed Mar 10, 2020
1 parent 8889680 commit e6976fa
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 40 deletions.
16 changes: 10 additions & 6 deletions core/src/test/java/com/github/phantomthief/zookeeper/BaseTest.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.phantomthief.zookeeper;

import static com.github.phantomthief.zookeeper.util.ZkUtils.removeFromZk;
import static org.apache.curator.framework.CuratorFrameworkFactory.newClient;

import java.io.IOException;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -23,10 +23,12 @@ public class BaseTest {

@BeforeAll
public static void init() throws Exception {
testingServer = new TestingServer(true);
curatorFramework = CuratorFrameworkFactory
.newClient(otherConnectionStr == null ? testingServer.getConnectString() : otherConnectionStr,
new RetryForever(1000));
if (otherConnectionStr == null) {
testingServer = new TestingServer(true);
curatorFramework = newClient(testingServer.getConnectString(), new RetryForever(1000));
} else {
curatorFramework = newClient(otherConnectionStr, new RetryForever(1000));
}
curatorFramework.start();
removeFromZk(curatorFramework, "/test", true);
curatorFramework.create().forPath("/test", "test1".getBytes());
Expand All @@ -41,6 +43,8 @@ public static void init() throws Exception {
@AfterAll
public static void destroy() throws IOException {
curatorFramework.close();
testingServer.close();
if (testingServer != null) {
testingServer.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static java.lang.Thread.currentThread;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.curator.framework.CuratorFrameworkFactory.newClient;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -17,8 +18,7 @@
import java.util.function.Function;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -41,10 +41,12 @@ class ZkNodeTest {

@BeforeAll
static void init() throws Exception {
testingServer = new TestingServer(true);
curatorFramework = CuratorFrameworkFactory
.newClient(otherConnectionStr == null ? testingServer.getConnectString() : otherConnectionStr,
new ExponentialBackoffRetry(10000, 20));
if (otherConnectionStr == null) {
testingServer = new TestingServer(true);
curatorFramework = newClient(testingServer.getConnectString(), new RetryForever(1000));
} else {
curatorFramework = newClient(otherConnectionStr, new RetryForever(1000));
}
curatorFramework.start();
removeFromZk(curatorFramework, "/test", true);
removeFromZk(curatorFramework, "/test2", true);
Expand All @@ -55,7 +57,9 @@ static void init() throws Exception {
@AfterAll
static void destroy() throws IOException {
curatorFramework.close();
testingServer.close();
if (testingServer != null) {
testingServer.close();
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.github.phantomthief.zookeeper.util.ZkUtils.getAllChildrenWithData;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static java.util.concurrent.TimeUnit.DAYS;
import static org.apache.curator.framework.CuratorFrameworkFactory.newClient;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
Expand All @@ -14,8 +15,7 @@
import java.util.concurrent.Executors;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -44,17 +44,21 @@ class ZkUtilsTest {
@BeforeAll
static void init() throws Exception {
mapper = new ObjectMapper();
testingServer = new TestingServer(true);
curatorFramework = CuratorFrameworkFactory
.newClient(otherConnectionStr == null ? testingServer.getConnectString() : otherConnectionStr,
new ExponentialBackoffRetry(10000, 20));
if (otherConnectionStr == null) {
testingServer = new TestingServer(true);
curatorFramework = newClient(testingServer.getConnectString(), new RetryForever(1000));
} else {
curatorFramework = newClient(otherConnectionStr, new RetryForever(1000));
}
curatorFramework.start();
}

@AfterAll
static void destroy() throws IOException {
curatorFramework.close();
testingServer.close();
if (testingServer != null) {
testingServer.close();
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.github.phantomthief.zookeeper;

import static com.github.phantomthief.zookeeper.util.ZkUtils.removeFromZk;
import static org.apache.curator.framework.CuratorFrameworkFactory.newClient;

import java.io.IOException;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterAll;
Expand All @@ -23,10 +23,12 @@ public class BaseTest {

@BeforeAll
public static void init() throws Exception {
testingServer = new TestingServer(true);
curatorFramework = CuratorFrameworkFactory
.newClient(otherConnectionStr == null ? testingServer.getConnectString() : otherConnectionStr,
new RetryForever(1000));
if (otherConnectionStr == null) {
testingServer = new TestingServer(true);
curatorFramework = newClient(testingServer.getConnectString(), new RetryForever(1000));
} else {
curatorFramework = newClient(otherConnectionStr, new RetryForever(1000));
}
curatorFramework.start();
removeFromZk(curatorFramework, "/test", true);
curatorFramework.create().forPath("/test", "test1".getBytes());
Expand All @@ -41,6 +43,8 @@ public static void init() throws Exception {
@AfterAll
public static void destroy() throws IOException {
curatorFramework.close();
testingServer.close();
if (testingServer != null) {
testingServer.close();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static java.lang.Thread.currentThread;
import static java.util.concurrent.Executors.newSingleThreadScheduledExecutor;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.curator.framework.CuratorFrameworkFactory.newClient;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
Expand All @@ -17,8 +18,7 @@
import java.util.function.Function;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand All @@ -41,10 +41,12 @@ class ZkNodeTest {

@BeforeAll
static void init() throws Exception {
testingServer = new TestingServer(true);
curatorFramework = CuratorFrameworkFactory
.newClient(otherConnectionStr == null ? testingServer.getConnectString() : otherConnectionStr,
new ExponentialBackoffRetry(10000, 20));
if (otherConnectionStr == null) {
testingServer = new TestingServer(true);
curatorFramework = newClient(testingServer.getConnectString(), new RetryForever(1000));
} else {
curatorFramework = newClient(otherConnectionStr, new RetryForever(1000));
}
curatorFramework.start();
removeFromZk(curatorFramework, "/test", true);
removeFromZk(curatorFramework, "/test2", true);
Expand All @@ -55,7 +57,9 @@ static void init() throws Exception {
@AfterAll
static void destroy() throws IOException {
curatorFramework.close();
testingServer.close();
if (testingServer != null) {
testingServer.close();
}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.github.phantomthief.zookeeper.util.ZkUtils.getAllChildrenWithData;
import static com.google.common.base.Throwables.throwIfUnchecked;
import static java.util.concurrent.TimeUnit.DAYS;
import static org.apache.curator.framework.CuratorFrameworkFactory.newClient;
import static org.junit.jupiter.api.Assertions.assertEquals;

import java.io.IOException;
Expand All @@ -14,8 +15,7 @@
import java.util.concurrent.Executors;

import org.apache.curator.framework.CuratorFramework;
import org.apache.curator.framework.CuratorFrameworkFactory;
import org.apache.curator.retry.ExponentialBackoffRetry;
import org.apache.curator.retry.RetryForever;
import org.apache.curator.test.TestingServer;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
Expand Down Expand Up @@ -44,17 +44,21 @@ class ZkUtilsTest {
@BeforeAll
static void init() throws Exception {
mapper = new ObjectMapper();
testingServer = new TestingServer(true);
curatorFramework = CuratorFrameworkFactory
.newClient(otherConnectionStr == null ? testingServer.getConnectString() : otherConnectionStr,
new ExponentialBackoffRetry(10000, 20));
if (otherConnectionStr == null) {
testingServer = new TestingServer(true);
curatorFramework = newClient(testingServer.getConnectString(), new RetryForever(1000));
} else {
curatorFramework = newClient(otherConnectionStr, new RetryForever(1000));
}
curatorFramework.start();
}

@AfterAll
static void destroy() throws IOException {
curatorFramework.close();
testingServer.close();
if (testingServer != null) {
testingServer.close();
}
}

@SuppressWarnings({ "rawtypes", "unchecked" })
Expand Down

0 comments on commit e6976fa

Please sign in to comment.