From b57cbce1ac6f35d698a0f663a61ec0096981e431 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez=20Gonzales?= Date: Mon, 29 Aug 2022 10:51:21 -0600 Subject: [PATCH] Remove `disque-job-queue` and `mongodb-container` examples (#5782) Examples should provided useful usage of technologies. In this case, `disque-job-queue` seems to provide a not up-to-date image and `mongodb-container` already provides its own module. --- docs/examples.md | 1 - examples/disque-job-queue/build.gradle | 19 ---- .../java/DisqueBackedMailSenderService.java | 73 --------------- .../src/main/java/MailApiClient.java | 11 --- .../src/main/java/MailMessage.java | 12 --- .../src/main/java/MailSenderService.java | 45 ---------- .../test/java/DisqueBackedMailSenderTest.java | 89 ------------------- .../test/java/SingleDisqueInstanceTest.java | 61 ------------- .../src/test/resources/logback-test.xml | 14 --- examples/mongodb-container/build.gradle | 13 --- .../containers/MongoDbContainer.java | 64 ------------- .../containers/MongoDbContainerTest.java | 28 ------ examples/settings.gradle | 2 - 13 files changed, 432 deletions(-) delete mode 100644 examples/disque-job-queue/build.gradle delete mode 100644 examples/disque-job-queue/src/main/java/DisqueBackedMailSenderService.java delete mode 100644 examples/disque-job-queue/src/main/java/MailApiClient.java delete mode 100644 examples/disque-job-queue/src/main/java/MailMessage.java delete mode 100644 examples/disque-job-queue/src/main/java/MailSenderService.java delete mode 100644 examples/disque-job-queue/src/test/java/DisqueBackedMailSenderTest.java delete mode 100644 examples/disque-job-queue/src/test/java/SingleDisqueInstanceTest.java delete mode 100644 examples/disque-job-queue/src/test/resources/logback-test.xml delete mode 100644 examples/mongodb-container/build.gradle delete mode 100644 examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainer.java delete mode 100644 examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainerTest.java diff --git a/docs/examples.md b/docs/examples.md index abd5e410c21..2c6036ab2ea 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -4,7 +4,6 @@ Examples of different use cases provided by Testcontainers can be found below: - [Kafka Cluster with multiple brokers](https://github.com/testcontainers/testcontainers-java/tree/master/examples/kafka-cluster) - [Linked containers](https://github.com/testcontainers/testcontainers-java/tree/master/examples/linked-container) -- [MongoDB](https://github.com/testcontainers/testcontainers-java/tree/master/examples/mongodb-container) - [Neo4j](https://github.com/testcontainers/testcontainers-java/tree/master/examples/neo4j-container) - [Redis](https://github.com/testcontainers/testcontainers-java/tree/master/examples/redis-backed-cache) - [Selenium](https://github.com/testcontainers/testcontainers-java/tree/master/examples/cucumber) diff --git a/examples/disque-job-queue/build.gradle b/examples/disque-job-queue/build.gradle deleted file mode 100644 index 6c7a453c3e9..00000000000 --- a/examples/disque-job-queue/build.gradle +++ /dev/null @@ -1,19 +0,0 @@ -plugins { - id 'java' -} - -repositories { - mavenCentral() -} - -dependencies { - compileOnly "org.projectlombok:lombok:1.18.24" - annotationProcessor "org.projectlombok:lombok:1.18.24" - implementation 'biz.paluch.redis:spinach:0.3' - implementation 'com.google.code.gson:gson:2.9.1' - implementation 'com.google.guava:guava:23.0' - testImplementation 'ch.qos.logback:logback-classic:1.2.11' - testImplementation 'org.mockito:mockito-all:1.10.19' - testImplementation 'org.testcontainers:testcontainers' - testImplementation 'org.assertj:assertj-core:3.23.1' -} diff --git a/examples/disque-job-queue/src/main/java/DisqueBackedMailSenderService.java b/examples/disque-job-queue/src/main/java/DisqueBackedMailSenderService.java deleted file mode 100644 index d2096106500..00000000000 --- a/examples/disque-job-queue/src/main/java/DisqueBackedMailSenderService.java +++ /dev/null @@ -1,73 +0,0 @@ -import biz.paluch.spinach.DisqueClient; -import biz.paluch.spinach.api.Job; -import biz.paluch.spinach.api.sync.DisqueCommands; -import com.google.gson.Gson; - -import java.util.HashSet; -import java.util.List; -import java.util.Set; -import java.util.concurrent.TimeUnit; - -/** - * Simple example of how a mail service can be backed by a Disque job queue. - * - * It's assumed that for actual sending (SMTP, HTTP API, etc), this service calls a {@link MailApiClient}. - * However, this can be expected to be quite unreliable, so use of Disque as a backing store helps keep track - * of sent/failed state. - */ -public class DisqueBackedMailSenderService implements MailSenderService { - - private final DisqueCommands disque; - private final Gson gson; - private final MailApiClient mailApiClient; - - public DisqueBackedMailSenderService(DisqueClient client, MailApiClient mailApiClient) { - this.mailApiClient = mailApiClient; - - // Obtain a Disque connection from DisqueClient - disque = client.connect().sync(); - - gson = new Gson(); - } - - @Override - public String enqueueMessage(MailMessage message) { - String messageAsJson = gson.toJson(message); - - // Enqueue the message as JSON, setting a TTL of 1 day (will expire off the queue if not sent by then) - String jobId = disque.addjob("mail", messageAsJson, 1, TimeUnit.DAYS); - - return jobId; - } - - @Override - public Result doScheduledSend() { - - Set succeededJobIds = new HashSet<>(); - Set failedJobIds = new HashSet<>(); - - // Wait up to 100ms for new messages to arrive on the queue - // Retrieve up to 10 messages - // (Ordinarily we'd make these configurable!) - List> jobs = disque.getjobs(100, TimeUnit.MILLISECONDS, 10, "mail"); - - for (Job job : jobs) { - String jsonBody = job.getBody(); - MailMessage message = gson.fromJson(jsonBody, MailMessage.class); - - try { - mailApiClient.send(message); - succeededJobIds.add(job.getId()); - } catch (MailApiClient.MailSendException e) { - failedJobIds.add(job.getId()); - } - } - - // For any failed messages, proactively return to the queue - disque.nack(failedJobIds.toArray(new String[failedJobIds.size()])); - // For any successful jobs, mark as completed - disque.ackjob(succeededJobIds.toArray(new String[succeededJobIds.size()])); - - return new Result(succeededJobIds.size(), failedJobIds.size()); - } -} diff --git a/examples/disque-job-queue/src/main/java/MailApiClient.java b/examples/disque-job-queue/src/main/java/MailApiClient.java deleted file mode 100644 index 61a90112f32..00000000000 --- a/examples/disque-job-queue/src/main/java/MailApiClient.java +++ /dev/null @@ -1,11 +0,0 @@ -/** - * Created by rnorth on 03/01/2016. - */ -public interface MailApiClient { - - boolean send(MailMessage message) throws MailSendException; - - class MailSendException extends RuntimeException { - - } -} diff --git a/examples/disque-job-queue/src/main/java/MailMessage.java b/examples/disque-job-queue/src/main/java/MailMessage.java deleted file mode 100644 index de167199057..00000000000 --- a/examples/disque-job-queue/src/main/java/MailMessage.java +++ /dev/null @@ -1,12 +0,0 @@ -import lombok.AllArgsConstructor; -import lombok.Data; - -/** - * Created by rnorth on 03/01/2016. - */ -@Data @AllArgsConstructor -public class MailMessage { - public final String subject; - public final String recipient; - public final String body; -} diff --git a/examples/disque-job-queue/src/main/java/MailSenderService.java b/examples/disque-job-queue/src/main/java/MailSenderService.java deleted file mode 100644 index 95237bf2eec..00000000000 --- a/examples/disque-job-queue/src/main/java/MailSenderService.java +++ /dev/null @@ -1,45 +0,0 @@ -import lombok.Data; -import lombok.RequiredArgsConstructor; - -import java.util.concurrent.Callable; - -/** - * Created by rnorth on 03/01/2016. - */ -public interface MailSenderService extends Callable { - - /** - * Enqueue a message to be sent on a subsequent {@link DisqueBackedMailSenderService#doScheduledSend()} - * @param message mail message to be sent - * @return an ID for the enqueued message - */ - String enqueueMessage(MailMessage message); - - /** - * Trigger a scheduled send of mail messages. - * - * TODO: In a real implementation this could be called by a {@link java.util.concurrent.ScheduledExecutorService}, - * probably - * - * @return the result of sending queued messages. - */ - MailSenderService.Result doScheduledSend(); - - /** - * call() implementation to allow MailSenderService to be used as a Callable. Simply delegates to - * the {@link DisqueBackedMailSenderService#doScheduledSend()} method. - * - * @return the result of sending queued messages. - * @throws Exception - */ - default MailSenderService.Result call() throws Exception { - return doScheduledSend(); - } - - @Data - @RequiredArgsConstructor - class Result { - public final int successfulCount; - public final int failedCount; - } -} diff --git a/examples/disque-job-queue/src/test/java/DisqueBackedMailSenderTest.java b/examples/disque-job-queue/src/test/java/DisqueBackedMailSenderTest.java deleted file mode 100644 index dfbab3f9e6a..00000000000 --- a/examples/disque-job-queue/src/test/java/DisqueBackedMailSenderTest.java +++ /dev/null @@ -1,89 +0,0 @@ -import biz.paluch.spinach.DisqueClient; -import biz.paluch.spinach.DisqueURI; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.utility.DockerImageName; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.Matchers.eq; -import static org.mockito.Mockito.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; - -/** - * Created by rnorth on 03/01/2016. - */ -public class DisqueBackedMailSenderTest { - - @Rule - public GenericContainer container = new GenericContainer<>(DockerImageName.parse("richnorth/disque:1.0-rc1")) - .withExposedPorts(7711); - private DisqueClient disqueClient; - - private MailSenderService service; - private MailApiClient mockMailApiClient; - - private MailMessage dummyMessage1; - private MailMessage dummyMessage2; - private MailMessage dummyMessage3; - - @Before - public void setup() { - disqueClient = new DisqueClient(DisqueURI.create(container.getHost(), container.getMappedPort(7711))); - mockMailApiClient = mock(MailApiClient.class); - - service = new DisqueBackedMailSenderService(disqueClient, mockMailApiClient); - - dummyMessage1 = new MailMessage("Dummy Message 1", "bob@example.com", "Test body"); - dummyMessage2 = new MailMessage("Dummy Message 2", "bob@example.com", "Test body"); - dummyMessage3 = new MailMessage("Dummy Message 3", "bob@example.com", "Test body"); - } - - @Test - public void testSimpleSuccessfulSending() throws Exception { - service.enqueueMessage(dummyMessage1); - service.enqueueMessage(dummyMessage2); - service.enqueueMessage(dummyMessage3); - - when(mockMailApiClient.send(any(MailMessage.class))).thenReturn(true); - - service.doScheduledSend(); - - verify(mockMailApiClient).send(eq(dummyMessage1)); - verify(mockMailApiClient).send(eq(dummyMessage2)); - verify(mockMailApiClient).send(eq(dummyMessage3)); - } - - @Test - public void testRetryOnFailure() throws Exception { - service.enqueueMessage(dummyMessage1); - service.enqueueMessage(dummyMessage2); - service.enqueueMessage(dummyMessage3); - - when(mockMailApiClient.send(eq(dummyMessage1))).thenThrow(MailApiClient.MailSendException.class).thenReturn(true); - when(mockMailApiClient.send(eq(dummyMessage2))).thenReturn(true); - when(mockMailApiClient.send(eq(dummyMessage3))).thenReturn(true); - - MailSenderService.Result result; - - result = service.doScheduledSend(); - assertThat(result.successfulCount).as("2 messages were 'sent' successfully").isEqualTo(2); - assertThat(result.failedCount).as("1 messages failed").isEqualTo(1); - - result = service.doScheduledSend(); - assertThat(result.successfulCount).as("1 message was 'sent' successfully").isEqualTo(1); - assertThat(result.failedCount).as("0 messages failed").isZero(); - - result = service.doScheduledSend(); - assertThat(result.successfulCount).as("0 messages were 'sent' successfully").isZero(); - assertThat(result.failedCount).as("0 messages failed").isZero(); - - verify(mockMailApiClient, times(2)).send(eq(dummyMessage1)); - verify(mockMailApiClient).send(eq(dummyMessage2)); - verify(mockMailApiClient).send(eq(dummyMessage3)); - } -} diff --git a/examples/disque-job-queue/src/test/java/SingleDisqueInstanceTest.java b/examples/disque-job-queue/src/test/java/SingleDisqueInstanceTest.java deleted file mode 100644 index 09830614eb0..00000000000 --- a/examples/disque-job-queue/src/test/java/SingleDisqueInstanceTest.java +++ /dev/null @@ -1,61 +0,0 @@ -import biz.paluch.spinach.DisqueClient; -import biz.paluch.spinach.DisqueURI; -import biz.paluch.spinach.api.AddJobArgs; -import biz.paluch.spinach.api.Job; -import biz.paluch.spinach.api.sync.DisqueCommands; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.testcontainers.containers.GenericContainer; -import org.testcontainers.utility.DockerImageName; - -import java.util.concurrent.TimeUnit; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * Created by rnorth on 03/01/2016. - */ -public class SingleDisqueInstanceTest { - - @Rule - public GenericContainer container = new GenericContainer<>(DockerImageName.parse("richnorth/disque:1.0-rc1")) - .withExposedPorts(7711); - private DisqueCommands connection; - private AddJobArgs retryAfter1Second; - - @Before - public void setup() { - DisqueClient client = new DisqueClient(DisqueURI.create(container.getHost(), container.getMappedPort(7711))); - connection = client.connect().sync(); - retryAfter1Second = AddJobArgs.builder().retry(1, TimeUnit.SECONDS).build(); - } - - @Test - public void testJobStoreAndRetrieve() { - connection.addjob("main_queue", "body", 1, TimeUnit.MINUTES); - - Job job = connection.getjob("main_queue"); - - assertThat(job.getBody()).as("The retrieved job is the same as the one that was added").isEqualTo("body"); - - connection.ackjob(job.getId()); - } - - @Test - public void testFailureToAckJobBeforeTimeout() throws InterruptedException { - connection.addjob("main_queue", "body", 1, TimeUnit.MINUTES, retryAfter1Second); - - Job job = connection.getjob("main_queue"); - - assertThat(job.getBody()).as("The retrieved job is the same as the one that was added").isEqualTo("body"); - - TimeUnit.SECONDS.sleep(2); - - // The timeout specified here is how long the command will wait for a job to appear - Job job2 = connection.getjob(5, TimeUnit.SECONDS, "main_queue"); - - assertThat(job2).as("After re-getting the original job is back on the queue").isNotNull(); - assertThat(job2.getBody()).as("The retrieved job is the same as the one that was added").isEqualTo("body"); - } -} diff --git a/examples/disque-job-queue/src/test/resources/logback-test.xml b/examples/disque-job-queue/src/test/resources/logback-test.xml deleted file mode 100644 index be4ebaed2c8..00000000000 --- a/examples/disque-job-queue/src/test/resources/logback-test.xml +++ /dev/null @@ -1,14 +0,0 @@ - - - - - - %d{HH:mm:ss.SSS} %-5level %logger - %msg%n - - - - - - - diff --git a/examples/mongodb-container/build.gradle b/examples/mongodb-container/build.gradle deleted file mode 100644 index 1ae43055790..00000000000 --- a/examples/mongodb-container/build.gradle +++ /dev/null @@ -1,13 +0,0 @@ -plugins { - id 'java' -} - -repositories { - mavenCentral() -} - -dependencies { - testImplementation 'org.testcontainers:testcontainers' - testImplementation 'junit:junit:4.13.2' - testCompileClasspath 'org.jetbrains:annotations:23.0.0' -} diff --git a/examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainer.java b/examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainer.java deleted file mode 100644 index c4c07c1f601..00000000000 --- a/examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainer.java +++ /dev/null @@ -1,64 +0,0 @@ -package org.testcontainers.containers; - -import org.jetbrains.annotations.NotNull; -import org.testcontainers.utility.DockerImageName; - - -/** - * This {@link Container} is based on the official MongoDb ({@code mongo}) image from - * DockerHub. If you need to use a custom MongoDB - * image, you can provide the full image name as well. - * - * @author Stefan Ludwig - */ -public class MongoDbContainer extends GenericContainer { - - /** - * This is the internal port on which MongoDB is running inside the container. - *

- * You can use this constant in case you want to map an explicit public port to it - * instead of the default random port. This can be done using methods like - * {@link #setPortBindings(java.util.List)}. - */ - public static final int MONGODB_PORT = 27017; - public static final String DEFAULT_IMAGE_AND_TAG = "mongo:4.0"; - - /** - * Creates a new {@link MongoDbContainer} with the {@value DEFAULT_IMAGE_AND_TAG} image. - * @deprecated use {@link MongoDbContainer(DockerImageName)} instead - */ - @Deprecated - public MongoDbContainer() { - this(DEFAULT_IMAGE_AND_TAG); - } - - /** - * Creates a new {@link MongoDbContainer} with the given {@code 'image'}. - * - * @param image the image (e.g. {@value DEFAULT_IMAGE_AND_TAG}) to use - * @deprecated use {@link MongoDbContainer(DockerImageName)} instead - */ - public MongoDbContainer(@NotNull String image) { - this(DockerImageName.parse(image)); - } - - /** - * Creates a new {@link MongoDbContainer} with the specified image. - */ - public MongoDbContainer(final DockerImageName dockerImageName) { - super(dockerImageName); - addExposedPort(MONGODB_PORT); - } - - /** - * Returns the actual public port of the internal MongoDB port ({@value MONGODB_PORT}). - * - * @return the public port of this container - * @see #getMappedPort(int) - */ - @NotNull - public Integer getPort() { - return getMappedPort(MONGODB_PORT); - } - -} diff --git a/examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainerTest.java b/examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainerTest.java deleted file mode 100644 index 5581c76e675..00000000000 --- a/examples/mongodb-container/src/test/java/org/testcontainers/containers/MongoDbContainerTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.testcontainers.containers; - -import org.junit.Test; -import org.testcontainers.utility.DockerImageName; - -import java.io.IOException; -import java.net.Socket; - - -public class MongoDbContainerTest { - - @Test - public void containerStartsAndPublicPortIsAvailable() { - try (MongoDbContainer container = new MongoDbContainer(DockerImageName.parse("mongo:4.0"))) { - container.start(); - assertThatPortIsAvailable(container); - } - } - - private void assertThatPortIsAvailable(MongoDbContainer container) { - try { - new Socket(container.getHost(), container.getPort()); - } catch (IOException e) { - throw new AssertionError("The expected port " + container.getPort() + " is not available!"); - } - } - -} diff --git a/examples/settings.gradle b/examples/settings.gradle index 9ed079cd7b8..7194134350d 100644 --- a/examples/settings.gradle +++ b/examples/settings.gradle @@ -19,10 +19,8 @@ rootProject.name = 'testcontainers-examples' includeBuild '..' // explicit include to allow Dependabot to autodiscover subprojects -include 'disque-job-queue' include 'kafka-cluster' include 'linked-container' -include 'mongodb-container' include 'neo4j-container' include 'redis-backed-cache' include 'redis-backed-cache-testng'