Skip to content

Commit

Permalink
INTERNAL: Remove all compile warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhm0311 authored and jhpark816 committed Jul 2, 2024
1 parent f01cf16 commit c8a5e9f
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 89 deletions.
33 changes: 15 additions & 18 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@
<configuration>
<source>8</source>
<target>8</target>
<encoding>UTF-8</encoding>
<debug>true</debug>
<showDeprecation>true</showDeprecation>
<showWarnings>true</showWarnings>
<compilerArgs>
<arg>-Xlint:all</arg>
<arg>-Xlint:-options</arg> <!-- For warning about old java version 8. -->
<arg>-Werror</arg>
</compilerArgs>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -53,24 +62,6 @@
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jam2in.arcus</groupId>
<artifactId>arcus-java-client</artifactId>
<version>1.13.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<version>1.19.8</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.apache.zookeeper</groupId>
<artifactId>zookeeper</artifactId>
<version>3.5.9</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand All @@ -90,5 +81,11 @@
<version>1.19.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jam2in.arcus</groupId>
<artifactId>arcus-java-client</artifactId>
<version>1.13.4</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.IOException;
import java.util.ArrayList;

import org.testcontainers.containers.ContainerState;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.utility.DockerImageName;
Expand Down Expand Up @@ -58,15 +59,16 @@ public class ArcusClusterContainer extends GenericContainer<ArcusClusterContaine
private static final String ZPATH_CLIENT_LIST = ZPATH_ARCUS + "/client_list";
private static final String ZPATH_CACHE_SERVER_MAPPING = ZPATH_ARCUS + "/cache_server_mapping";

private final Network network;
private final ZookeeperContainer zkContainer;
private final String serviceCode;

private final ArrayList<String> cacheNodes = new ArrayList<>();
private final ArrayList<ArcusContainer> containers = new ArrayList<>();

private ArcusClusterContainer(DockerImageName imageName, ArcusContainerProps props) {
this.network = Network.newNetwork();
super(imageName);

final Network network = Network.newNetwork();
this.zkContainer = new ZookeeperContainer(network);
this.serviceCode = props.getServiceCode();

Expand Down Expand Up @@ -131,43 +133,36 @@ public Integer getFirstMappedPort() {
return zkContainer.getFirstMappedPort();
}

@Override
public String getDockerImageName() {
return containers.get(0).getDockerImageName();
}

@Override
public void start() {
zkContainer.start();
try {
createZnode();
} catch (IOException e) {
throw new RuntimeException(e);
} catch (InterruptedException e) {
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
containers.stream().forEach(ac -> ac.start());
containers.forEach(ArcusContainer::start);
}

@Override
public boolean isRunning() {
return containers.stream().allMatch(c -> c.isRunning()) && zkContainer.isRunning();
return containers.stream().allMatch(ContainerState::isRunning) && zkContainer.isRunning();
}

@Override
public void stop() {
containers.stream().forEach(ac -> ac.stop());
containers.forEach(ArcusContainer::stop);
zkContainer.stop();
}

@Override
public boolean isCreated() {
return containers.stream().allMatch(c -> c.isCreated()) && zkContainer.isCreated();
return containers.stream().allMatch(ContainerState::isCreated) && zkContainer.isCreated();
}

@Override
public boolean isHealthy() {
return containers.stream().allMatch(c -> c.isHealthy()) && zkContainer.isHealthy();
return containers.stream().allMatch(ContainerState::isHealthy) && zkContainer.isHealthy();
}

private void createZnode() throws IOException, InterruptedException {
Expand All @@ -192,12 +187,13 @@ private static class ZookeeperContainer extends GenericContainer<ZookeeperContai

public ZookeeperContainer(Network network) {
super(DEFAULT_ZK_IMAGE_NAME);
withNetwork(network);
withEnv("ZOO_MY_ID", "1");
withCreateContainerCmdModifier(cmd -> {

this.withNetwork(network);
this.withEnv("ZOO_MY_ID", "1");
this.withCreateContainerCmdModifier(cmd -> {
cmd.withHostName("zoo1");
});
withExposedPorts(DEFAULT_ZK_CONTAINER_PORT);
this.withExposedPorts(DEFAULT_ZK_CONTAINER_PORT);
}
}
}
19 changes: 11 additions & 8 deletions src/main/java/com/jam2in/arcus/testcontainers/ArcusContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.github.dockerjava.api.model.Ports;
import com.github.dockerjava.api.model.RestartPolicy;

import java.util.Objects;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.utility.DockerImageName;
Expand Down Expand Up @@ -100,25 +102,26 @@ private void setupContainer(int port, int memSize) {
}

private void setupContainer(int port, String host, Network network, int memorySize) {
withCreateContainerCmdModifier(cmd -> {
this.withCreateContainerCmdModifier(cmd -> {
if (host != null) {
cmd.withHostName(host);
}
cmd.getHostConfig().withRestartPolicy(RestartPolicy.alwaysRestart());
cmd.getHostConfig().withPortBindings(new PortBinding(Ports.Binding.bindPort(port), new ExposedPort(port)));
Objects.requireNonNull(cmd.getHostConfig())
.withRestartPolicy(RestartPolicy.alwaysRestart())
.withPortBindings(new PortBinding(Ports.Binding.bindPort(port), new ExposedPort(port)));
});
withExposedPorts(port);
withCommand(buildContainerCommand(port, network, memorySize));
this.withExposedPorts(port);
this.withCommand(buildContainerCommand(port, network, memorySize));
}

private String buildContainerCommand(int port, Network network, int memorySize) {
StringBuilder sb = new StringBuilder();
sb.append("-m " + memorySize + " ");
sb.append("-p " + port);
sb.append("-m ").append(memorySize).append(" ");
sb.append("-p ").append(port);

if (network != null) {
sb.append(" -z zoo1:2181");
withEnv("ARCUS_CACHE_PUBLIC_IP", "127.0.0.1");
this.withEnv("ARCUS_CACHE_PUBLIC_IP", "127.0.0.1");
}
return sb.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,21 @@ void createArcusContainerSingle() throws ExecutionException, InterruptedExceptio
assertThat(set.get()).isTrue();
}

@Test
void createArcusContainerSingle2() throws ExecutionException, InterruptedException {
//given
ArcusClientPool arcusClient = ArcusClient.createArcusClientPool(ARCUS_CLUSTER_CONTAINER.getHostPorts(),
"test", new ConnectionFactoryBuilder(), 2);

//when
OperationFuture<Boolean> set = arcusClient.set("test2", 10, "testValue2");

//then
assertThat(ARCUS_CLUSTER_CONTAINER.isCreated()).isTrue();
assertThat(ARCUS_CLUSTER_CONTAINER.isRunning()).isTrue();
assertThat(set.get()).isTrue();
}

@Test
void createNotSharedClusterTest() throws ExecutionException, InterruptedException {
//given
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,10 @@ void createArcusContainerWithPropsTest() {
.build();

//when
ArcusContainer arcusContainer = ArcusContainer.create(props);

//then
assertThat(arcusContainer.getDockerImageName())
.isEqualTo(ArcusContainer.DEFAULT_ARCUS_IMAGE_NAME.toString());
try (ArcusContainer arcusContainer = ArcusContainer.create(props)) {
//then
assertThat(arcusContainer.getDockerImageName())
.isEqualTo(ArcusContainer.DEFAULT_ARCUS_IMAGE_NAME.toString());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.concurrent.ExecutionException;

import net.spy.memcached.ArcusClient;
Expand All @@ -29,10 +28,8 @@ void createArcusContainerSingle() throws IOException, ExecutionException, Interr
//given
ArcusClient arcusClient = new ArcusClient(
new DefaultConnectionFactory(),
new ArrayList<>(Arrays.asList(
new InetSocketAddress(
"127.0.0.1",
arcusContainer.getFirstMappedPort()))));
Collections.singletonList(
new InetSocketAddress("127.0.0.1", arcusContainer.getFirstMappedPort())));
//when
Boolean b = arcusClient.set("test", 10, "singleTestValue").get();

Expand Down

0 comments on commit c8a5e9f

Please sign in to comment.