Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

545: Move to JUnit5 #547

Merged
merged 1 commit into from
Mar 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 12 additions & 0 deletions jetcd-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,18 @@
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-migrationsupport</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
Expand Down
16 changes: 8 additions & 8 deletions jetcd-core/src/test/java/io/etcd/jetcd/AuthClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
import io.etcd.jetcd.auth.AuthRoleListResponse;
import io.etcd.jetcd.auth.Permission;
import io.etcd.jetcd.auth.Permission.Type;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.etcd.jetcd.launcher.junit5.EtcdClusterExtension;

import java.net.URI;
import java.util.List;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* test etcd auth
*/
public class AuthClientTest {

@ClassRule
public static final EtcdClusterResource clusterResource = new EtcdClusterResource("auth-etcd", 1, false);
@RegisterExtension
public static final EtcdClusterExtension cluster = new EtcdClusterExtension("auth-etcd", 1, false);

private final ByteSequence rootRoleKey = bytesOf("root");
private final ByteSequence rootRoleValue = bytesOf("b");
Expand Down Expand Up @@ -71,9 +71,9 @@ public class AuthClientTest {
/**
* Build etcd client to create role, permission
*/
@BeforeClass
@BeforeAll
public static void setupEnv() {
endpoints = clusterResource.cluster().getClientEndpoints();
endpoints = cluster.getClientEndpoints();
Client client = Client.builder().endpoints(endpoints).build();

authDisabledKVClient = client.getKVClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import io.etcd.jetcd.kv.PutResponse;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.etcd.jetcd.launcher.junit5.EtcdClusterExtension;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
Expand All @@ -31,19 +31,21 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import org.junit.Rule;
import org.junit.Test;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

public class ClientConnectionManagerTest {
@Rule
public final EtcdClusterResource clusterResource = new EtcdClusterResource("connection-manager-etcd", 1);

@RegisterExtension
public static final EtcdClusterExtension cluster = new EtcdClusterExtension("connection-manager-etcd", 1);

@Test
public void test() throws InterruptedException, ExecutionException {
final CountDownLatch latch = new CountDownLatch(1);

final ClientBuilder builder = Client.builder()
.endpoints(clusterResource.cluster().getClientEndpoints())
.endpoints(cluster.getClientEndpoints())
.header("MyHeader1", "MyHeaderVal1")
.header("MyHeader2", "MyHeaderVal2")
.interceptor(new ClientInterceptor() {
Expand Down
18 changes: 9 additions & 9 deletions jetcd-core/src/test/java/io/etcd/jetcd/ClusterClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.etcd.jetcd.cluster.Member;
import io.etcd.jetcd.cluster.MemberAddResponse;
import io.etcd.jetcd.cluster.MemberListResponse;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.etcd.jetcd.launcher.junit5.EtcdClusterExtension;

import java.net.URI;
import java.util.List;
Expand All @@ -29,17 +29,17 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* test etcd cluster client
*/
public class ClusterClientTest {

@ClassRule
public static EtcdClusterResource clusterResource = new EtcdClusterResource("cluster-client", 3 ,false);
@RegisterExtension
public static EtcdClusterExtension cluster = new EtcdClusterExtension("cluster-client", 3 ,false);

private static List<URI> endpoints;
private static List<URI> peerUrls;
Expand All @@ -48,10 +48,10 @@ public class ClusterClientTest {
* test list cluster function
*/

@BeforeClass
@BeforeAll
public static void setUp() throws InterruptedException {
endpoints = clusterResource.cluster().getClientEndpoints();
peerUrls = clusterResource.cluster().getPeerEndpoints();
endpoints = cluster.getClientEndpoints();
peerUrls = cluster.getPeerEndpoints();
TimeUnit.SECONDS.sleep(5);
}

Expand Down
34 changes: 11 additions & 23 deletions jetcd-core/src/test/java/io/etcd/jetcd/KVNamespaceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,20 @@
import io.etcd.jetcd.kv.GetResponse;
import io.etcd.jetcd.kv.PutResponse;
import io.etcd.jetcd.kv.TxnResponse;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import io.etcd.jetcd.launcher.junit5.EtcdClusterExtension;
import io.etcd.jetcd.op.Cmp;
import io.etcd.jetcd.op.CmpTarget;
import io.etcd.jetcd.op.Op;
import io.etcd.jetcd.options.DeleteOption;
import io.etcd.jetcd.options.GetOption;
import io.etcd.jetcd.options.PutOption;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand All @@ -52,24 +49,15 @@
public class KVNamespaceTest {
private static final ByteSequence END_KEY = ByteSequence.from(new byte[] {0});

public static final EtcdCluster CLUSTER = EtcdClusterFactory.buildCluster(
@RegisterExtension
public static final EtcdClusterExtension cluster = new EtcdClusterExtension(
"etcd-kv-namespace-test", 3 ,false);
private KV kvClient;
private KV kvClientWithNamespace;
private KV kvClientWithNamespace2;

private static Integer keyIndex = -1;

@BeforeAll
public static void setUp() {
CLUSTER.start();
}

@AfterAll
public static void tearDown() throws IOException {
CLUSTER.close();
}

@AfterEach
public void cleanUpCase() {
if (kvClient != null) {
Expand Down Expand Up @@ -136,16 +124,16 @@ public void testPrefixNamespace(
@Test
public void testKV() throws Exception {
// kvClient without namespace used as the judge for the final result
kvClient = Client.builder().endpoints(CLUSTER.getClientEndpoints()).build().getKVClient();
kvClient = Client.builder().endpoints(cluster.getClientEndpoints()).build().getKVClient();
// kvClient with one namespace used to test operations with namespace
ByteSequence namespace = ByteSequence.from(TestUtil.randomByteSequence().getByteString()
.concat(ByteSequence.NAMESPACE_DELIMITER.getByteString()));
kvClientWithNamespace = Client.builder().endpoints(CLUSTER.getClientEndpoints())
kvClientWithNamespace = Client.builder().endpoints(cluster.getClientEndpoints())
.namespace(namespace).build().getKVClient();
// kvClient with another namespace used to test keyed segregation based on namespace
ByteSequence namespace2 = ByteSequence.from(TestUtil.randomByteSequence().getByteString()
.concat(ByteSequence.NAMESPACE_DELIMITER.getByteString()));
kvClientWithNamespace2 = Client.builder().endpoints(CLUSTER.getClientEndpoints())
kvClientWithNamespace2 = Client.builder().endpoints(cluster.getClientEndpoints())
.namespace(namespace2).build().getKVClient();

// test single key
Expand Down Expand Up @@ -255,11 +243,11 @@ public void testKV() throws Exception {
@Test
public void testTxn() throws Exception {
// kvClient without namespace used as the judge for the final result
kvClient = Client.builder().endpoints(CLUSTER.getClientEndpoints()).build().getKVClient();
kvClient = Client.builder().endpoints(cluster.getClientEndpoints()).build().getKVClient();
// kvClient with one namespace used to test operations with namespace
ByteSequence namespace = ByteSequence.from(TestUtil.randomByteSequence().getByteString()
.concat(ByteSequence.NAMESPACE_DELIMITER.getByteString()));
kvClientWithNamespace = Client.builder().endpoints(CLUSTER.getClientEndpoints())
kvClientWithNamespace = Client.builder().endpoints(cluster.getClientEndpoints())
.namespace(namespace).build().getKVClient();

// put a key in root namespace, assert that it cannot be seen using kvClient with namespace
Expand Down Expand Up @@ -330,11 +318,11 @@ public void testTxn() throws Exception {
@Test
public void testNestedTxn() throws Exception {
// kvClient without namespace used as the judge for the final result
kvClient = Client.builder().endpoints(CLUSTER.getClientEndpoints()).build().getKVClient();
kvClient = Client.builder().endpoints(cluster.getClientEndpoints()).build().getKVClient();
// kvClient with one namespace used to test operations with namespace
ByteSequence namespace = ByteSequence.from(TestUtil.randomByteSequence().getByteString()
.concat(ByteSequence.NAMESPACE_DELIMITER.getByteString()));
kvClientWithNamespace = Client.builder().endpoints(CLUSTER.getClientEndpoints())
kvClientWithNamespace = Client.builder().endpoints(cluster.getClientEndpoints())
.namespace(namespace).build().getKVClient();

ByteSequence cmpKey1 = getNonexistentKey();
Expand Down
17 changes: 9 additions & 8 deletions jetcd-core/src/test/java/io/etcd/jetcd/KVTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import io.etcd.jetcd.kv.DeleteResponse;
import io.etcd.jetcd.kv.GetResponse;
import io.etcd.jetcd.kv.PutResponse;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.etcd.jetcd.launcher.junit5.EtcdClusterExtension;
import io.etcd.jetcd.op.Cmp;
import io.etcd.jetcd.op.CmpTarget;
import io.etcd.jetcd.op.Op;
Expand All @@ -35,17 +35,18 @@
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import org.assertj.core.api.Assertions;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;

import org.junit.jupiter.api.BeforeAll;
yb172 marked this conversation as resolved.
Show resolved Hide resolved
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* KV service test cases.
*/
public class KVTest {

@ClassRule
public static EtcdClusterResource clusterResource = new EtcdClusterResource("etcd-kv", 3 ,false);
@RegisterExtension
public static EtcdClusterExtension cluster = new EtcdClusterExtension("etcd-kv", 3 ,false);
private static KV kvClient;

private static final ByteSequence SAMPLE_KEY = bytesOf("sample_key");
Expand All @@ -54,9 +55,9 @@ public class KVTest {
private static final ByteSequence SAMPLE_VALUE_2 = bytesOf("sample_value2");
private static final ByteSequence SAMPLE_KEY_3 = bytesOf("sample_key3");

@BeforeClass
@BeforeAll
public static void setUp() throws Exception {
kvClient = Client.builder().endpoints(clusterResource.cluster().getClientEndpoints()).build().getKVClient();
kvClient = Client.builder().endpoints(cluster.getClientEndpoints()).build().getKVClient();
}

@Test
Expand Down
23 changes: 12 additions & 11 deletions jetcd-core/src/test/java/io/etcd/jetcd/LeaseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static org.assertj.core.api.Assertions.assertThat;

import com.google.common.base.Charsets;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.etcd.jetcd.launcher.junit5.EtcdClusterExtension;
import io.etcd.jetcd.lease.LeaseKeepAliveResponse;
import io.etcd.jetcd.lease.LeaseTimeToLiveResponse;
import io.etcd.jetcd.options.LeaseOption;
Expand All @@ -28,17 +28,18 @@
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

/**
* Lease service test cases.
*/
public class LeaseTest {
@ClassRule
public static EtcdClusterResource clusterResource = new EtcdClusterResource("etcd-lease", 3 ,false);

@RegisterExtension
public static final EtcdClusterExtension cluster = new EtcdClusterExtension("etcd-lease", 3 ,false);

private KV kvClient;
private Client client;
Expand All @@ -49,14 +50,14 @@ public class LeaseTest {
private static final ByteSequence VALUE = ByteSequence.from("bar", Charsets.UTF_8);


@Before
@BeforeEach
public void setUp() {
client = Client.builder().endpoints(clusterResource.cluster().getClientEndpoints()).build();
client = Client.builder().endpoints(cluster.getClientEndpoints()).build();
kvClient = client.getKVClient();
leaseClient = client.getLeaseClient();
}

@After
@AfterEach
public void tearDown() {
if (client != null) {
client.close();
Expand All @@ -74,7 +75,7 @@ public void testGrant() throws Exception {
assertThat(kvClient.get(KEY).get().getCount()).isEqualTo(0);
}

@Test//(dependsOnMethods = "testGrant")
@Test
public void testRevoke() throws Exception {
long leaseID = leaseClient.grant(5).get().getID();
kvClient.put(KEY, VALUE, PutOption.newBuilder().withLeaseId(leaseID).build()).get();
Expand Down