Skip to content
Open
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
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ body:
- LDAP
- LocalStack
- MariaDB
- Memcached
- Milvus
- MinIO
- MockServer
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/enhancement.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ body:
- LDAP
- LocalStack
- MariaDB
- Memcached
- Milvus
- MinIO
- MockServer
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ body:
- LDAP
- LocalStack
- MariaDB
- Memcached
- Milvus
- MinIO
- MockServer
Expand Down
5 changes: 5 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ updates:
ignore:
- dependency-name: "org.mariadb:r2dbc-mariadb"
update-types: [ "version-update:semver-minor" ]
- package-ecosystem: "gradle"
directory: "/modules/memcached"
schedule:
interval: "monthly"
open-pull-requests-limit: 10
- package-ecosystem: "gradle"
directory: "/modules/milvus"
schedule:
Expand Down
4 changes: 4 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,10 @@
- changed-files:
- any-glob-to-any-file:
- modules/mariadb/**/*
"modules/memcached":
- changed-files:
- any-glob-to-any-file:
- modules/memcached/**/*
"modules/milvus":
- changed-files:
- any-glob-to-any-file:
Expand Down
31 changes: 31 additions & 0 deletions docs/modules/memcached.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Memcached Module

Memcached is an in-memory key-value cache.

## Usage example

<!--codeinclude-->
[Creating a Memcached container](../../modules/memcached/src/test/java/org/testcontainers/memcached/MemcachedContainerTest.java) inside_block:creatingContainer
<!--/codeinclude-->

<!--codeinclude-->
[Connect and operate](../../modules/memcached/src/test/java/org/testcontainers/memcached/MemcachedContainerTest.java) inside_block:connectAndOperate
<!--/codeinclude-->

## Adding this module to your project dependencies

Add the following dependency to your `pom.xml`/`build.gradle` file:

=== "Gradle"
```groovy
testImplementation "org.testcontainers:testcontainers-memcached:{{latest_version}}"
```
=== "Maven"
```xml
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers-memcached</artifactId>
<version>{{latest_version}}</version>
<scope>test</scope>
</dependency>
```
1 change: 1 addition & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ nav:
- modules/kafka.md
- modules/ldap.md
- modules/localstack.md
- modules/memcached.md
- modules/milvus.md
- modules/minio.md
- modules/mockserver.md
Expand Down
7 changes: 7 additions & 0 deletions modules/memcached/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
description = "Testcontainers :: Memcached"

dependencies {
api project(':testcontainers')

testImplementation 'net.spy:spymemcached:2.12.3'
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.testcontainers.memcached;

import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;
import org.testcontainers.utility.DockerImageName;

public class MemcachedContainer extends GenericContainer<MemcachedContainer> {

private static final int DEFAULT_PORT = 11211;

private static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("memcached");

public MemcachedContainer(String dockerImageName) {
this(DockerImageName.parse(dockerImageName));
}

public MemcachedContainer(DockerImageName dockerImageName) {
super(dockerImageName);
dockerImageName.assertCompatibleWith(DEFAULT_IMAGE_NAME);
withExposedPorts(DEFAULT_PORT);
waitingFor(Wait.forListeningPort());
}

public String getHostPort() {
return getHost() + ":" + getMappedPort(DEFAULT_PORT);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package org.testcontainers.memcached;

import net.spy.memcached.MemcachedClient;
import org.junit.jupiter.api.Test;
import org.testcontainers.utility.DockerImageName;

import java.net.InetSocketAddress;
import java.util.concurrent.TimeUnit;

import static org.assertj.core.api.Assertions.assertThat;

class MemcachedContainerTest {

private static final DockerImageName MEMCACHED_IMAGE = DockerImageName.parse("memcached:1.6-alpine");

@Test
void testSimple() throws Exception {
try (
// creatingContainer {
MemcachedContainer memcached = new MemcachedContainer(MEMCACHED_IMAGE)
// }
) {
memcached.start();

// connectAndOperate {
MemcachedClient client = new MemcachedClient(
new InetSocketAddress(memcached.getHost(), memcached.getMappedPort(11211))
);
try {
client.set("hello", 60, "world").get(5, TimeUnit.SECONDS);
assertThat(client.get("hello")).isEqualTo("world");
} finally {
client.shutdown();
}
// }
}
}
}
16 changes: 16 additions & 0 deletions modules/memcached/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} %-5level %logger - %msg%n</pattern>
</encoder>
</appender>

<root level="INFO">
<appender-ref ref="STDOUT"/>
</root>

<logger name="org.testcontainers" level="INFO"/>
</configuration>