Skip to content

Commit

Permalink
move jetcd.internal.infrastructure into new launcher/ artifact (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger authored and lburgazzoli committed Sep 6, 2018
1 parent 89a03c7 commit 21c87c2
Show file tree
Hide file tree
Showing 19 changed files with 144 additions and 90 deletions.
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,8 @@
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.etcd.jetcd.launcher.TestConstants;
import io.grpc.netty.GrpcSslContexts;
import java.io.File;
import java.io.FileInputStream;
Expand Down
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,20 +14,18 @@
* 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();

Expand All @@ -36,6 +34,7 @@ public interface EtcdCluster extends AutoCloseable {

interface LifecycleListener {
void started(EtcdContainer container);

void stopped(EtcdContainer container);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,10 @@
* limitations under the License.
*/

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

import static java.util.stream.Collectors.toList;

import io.etcd.jetcd.Client;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
Expand All @@ -44,7 +43,9 @@ public void stopped(EtcdContainer container) {
};

final List<String> endpoints = IntStream.range(0, nodes).mapToObj(i -> "etcd" + i).collect(toList());
final List<EtcdContainer> containers = endpoints.stream().map(e -> new EtcdContainer(network, listener, ssl, clusterName, e, endpoints)).collect(toList());

final List<EtcdContainer> containers = endpoints.stream()
.map(e -> new EtcdContainer(network, listener, ssl, clusterName, e, endpoints)).collect(toList());

return new EtcdCluster() {
@Override
Expand All @@ -65,12 +66,6 @@ public void close() {
containers.forEach(EtcdContainer::close);
}

@Nonnull
@Override
public Client getClient() {
return Client.builder().endpoints(getClientEndpoints()).build();
}

@Nonnull
@Override
public List<String> getClientEndpoints() {
Expand Down
Loading

0 comments on commit 21c87c2

Please sign in to comment.