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

Launcher (see #384) #386

Merged
merged 3 commits into from
Sep 6, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jetcd-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<groupId>${project.groupId}</groupId>
<artifactId>jetcd-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import io.etcd.jetcd.auth.Permission;
import io.etcd.jetcd.auth.Permission.Type;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.internal.infrastructure.EtcdCluster;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterFactory;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import java.io.IOException;
import java.util.List;
import java.util.concurrent.ExecutionException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.etcd.jetcd.Client;
import io.etcd.jetcd.ClientBuilder;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterResource;
import io.etcd.jetcd.kv.PutResponse;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.grpc.CallOptions;
import io.grpc.Channel;
import io.grpc.ClientCall;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import io.etcd.jetcd.cluster.Member;
import io.etcd.jetcd.cluster.MemberAddResponse;
import io.etcd.jetcd.cluster.MemberListResponse;
import io.etcd.jetcd.internal.infrastructure.EtcdCluster;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterFactory;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CompletableFuture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@
import static org.junit.Assert.assertTrue;

import com.google.common.base.Charsets;
import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.Txn;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.internal.infrastructure.EtcdCluster;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterFactory;
import io.etcd.jetcd.kv.DeleteResponse;
import io.etcd.jetcd.kv.GetResponse;
import io.etcd.jetcd.kv.PutResponse;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import io.etcd.jetcd.op.Cmp;
import io.etcd.jetcd.op.CmpTarget;
import io.etcd.jetcd.op.Op;
Expand Down Expand Up @@ -62,7 +63,7 @@ public class KVTest {
public static void setUp() throws Exception {
CLUSTER.start();

kvClient = CLUSTER.getClient().getKVClient();
kvClient = Client.builder().endpoints(CLUSTER.getClientEndpoints()).build().getKVClient();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
import io.etcd.jetcd.KV;
import io.etcd.jetcd.Lease;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.internal.infrastructure.EtcdCluster;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterFactory;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import io.etcd.jetcd.lease.LeaseKeepAliveResponse;
import io.etcd.jetcd.lease.LeaseTimeToLiveResponse;
import io.etcd.jetcd.options.LeaseOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.data.Response;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterResource;
import io.etcd.jetcd.kv.PutResponse;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.grpc.PickFirstBalancerFactory;
import io.grpc.util.RoundRobinLoadBalancerFactory;
import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
import io.etcd.jetcd.Lease;
import io.etcd.jetcd.Lock;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.internal.infrastructure.EtcdCluster;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterFactory;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import io.etcd.jetcd.lease.LeaseGrantResponse;
import io.etcd.jetcd.lock.LockResponse;
import java.io.IOException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import io.etcd.jetcd.Client;
import io.etcd.jetcd.Maintenance;
import io.etcd.jetcd.internal.infrastructure.EtcdCluster;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterFactory;
import io.etcd.jetcd.launcher.EtcdCluster;
import io.etcd.jetcd.launcher.EtcdClusterFactory;
import io.etcd.jetcd.maintenance.SnapshotResponse;
import io.etcd.jetcd.maintenance.StatusResponse;
import io.grpc.stub.StreamObserver;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import io.etcd.jetcd.Client;
import io.etcd.jetcd.KV;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterResource;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.grpc.netty.GrpcSslContexts;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -31,20 +31,24 @@
import org.junit.Test;

public class SslTest {

@Rule
public final EtcdClusterResource clusterResource = new EtcdClusterResource("etcd-ssl", 1, true);

private static final String DEFAULT_SSL_AUTHORITY = "etcd0";
private static final String DEFAULT_SSL_CA_PATH = "/ssl/cert/ca.pem";

@Test(timeout = 5000)
public void testSimpleSllSetup() throws Exception {
final ByteSequence key = ByteSequence.from(TestUtil.randomString(), Charsets.UTF_8);
final ByteSequence val = ByteSequence.from(TestUtil.randomString(), Charsets.UTF_8);
final String capath = System.getProperty("ssl.cert.capath");
final String authority = System.getProperty("ssl.cert.authority", TestConstants.DEFAULT_SSL_AUTHORITY);
final String authority = System.getProperty("ssl.cert.authority", DEFAULT_SSL_AUTHORITY);
final String endpoints = System.getProperty("ssl.cert.endpoints", clusterResource.cluster().getClientEndpoints().get(0));

try (InputStream is = Objects.nonNull(capath)
? new FileInputStream(new File(capath))
: getClass().getResourceAsStream(TestConstants.DEFAULT_SSL_CA_PATH)) {
: getClass().getResourceAsStream(DEFAULT_SSL_CA_PATH)) {

Client client = Client.builder()
.endpoints(endpoints)
Expand Down

This file was deleted.

30 changes: 0 additions & 30 deletions jetcd-core/src/test/java/io/etcd/jetcd/internal/impl/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@
import io.etcd.jetcd.data.ByteSequence;
import java.io.IOException;
import java.net.ServerSocket;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import org.testcontainers.containers.GenericContainer;

public class TestUtil {

Expand All @@ -39,30 +35,4 @@ public static int findNextAvailablePort() throws IOException {
return socket.getLocalPort();
}
}

public static String buildClientEndpoint(GenericContainer container) {
return buildEndpoint(container, "http", TestConstants.ETCD_CLIENT_PORT);
}

public static List<String> buildClientEndpoints(GenericContainer... etcdContainers) {
return Arrays.stream(etcdContainers)
.map(TestUtil::buildClientEndpoint)
.collect(Collectors.toList());
}

public static String buildPeerEndpoint(GenericContainer container) {
return buildEndpoint(container, "http", TestConstants.ETCD_PEER_PORT);
}

public static List<String> buildPeerEndpoints(GenericContainer... etcdContainers) {
return Arrays.stream(etcdContainers)
.map(TestUtil::buildPeerEndpoint)
.collect(Collectors.toList());
}

public static String buildEndpoint(GenericContainer container, String scheme, int port) {
String nodeAddress = container.getContainerIpAddress();
Integer nodePort = container.getMappedPort(port);
return scheme + "://" + nodeAddress + ":" + nodePort;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package io.etcd.jetcd.internal.impl;


import static com.google.common.base.Charsets.UTF_8;
import static org.assertj.core.api.Assertions.assertThat;

Expand All @@ -24,7 +23,7 @@
import io.etcd.jetcd.Watch;
import io.etcd.jetcd.Watch.Watcher;
import io.etcd.jetcd.data.ByteSequence;
import io.etcd.jetcd.internal.infrastructure.EtcdClusterResource;
import io.etcd.jetcd.launcher.junit.EtcdClusterResource;
import io.etcd.jetcd.watch.WatchEvent;
import io.etcd.jetcd.watch.WatchEvent.EventType;
import io.etcd.jetcd.watch.WatchResponse;
Expand Down
80 changes: 80 additions & 0 deletions jetcd-launcher/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Copyright 2017 The jetcd authors

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>io.etcd</groupId>
<artifactId>jetcd-parent</artifactId>
<version>0.3.0-SNAPSHOT</version>
</parent>

<artifactId>jetcd-launcher</artifactId>
<packaging>bundle</packaging>

<properties>
<checkstyle.config.location>${basedir}/../etc/checkstyle.xml</checkstyle.config.location>
<checkstyle.header.file>${basedir}../etc/checkstyle-header-java.txt</checkstyle.header.file>
</properties>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<!-- EtcdClusterResource is in src/main, but everyone depending on this launcher should be
forced to transitively inherit a JUnit dependency; it's optional - if they already have it anyway. -->
<scope>compile</scope>
<optional>true</optional>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<instructions>
<Bundle-SymbolicName>${project.groupId}.${project.artifactId}</Bundle-SymbolicName>
<Bundle-Name>etcd :: ${project.artifactId}</Bundle-Name>
</instructions>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,21 @@
* limitations under the License.
*/

package io.etcd.jetcd.internal.infrastructure;
package io.etcd.jetcd.launcher;

import io.etcd.jetcd.Client;
import java.util.List;
import javax.annotation.Nonnull;

public interface EtcdCluster extends AutoCloseable {

void start();

@Override
void close();

@Nonnull
Client getClient();

@Nonnull
List<String> getClientEndpoints();

@Nonnull
List<String> getPeerEndpoints();

interface LifecycleListener {
void started(EtcdContainer container);
void stopped(EtcdContainer container);
}
}
Loading