xmemcached with TestContainers

153 views
Skip to first unread message

Sean Carroll

unread,
Nov 11, 2018, 11:55:21 PM11/11/18
to xmemcached
Has anyone had success setting up memcached with TestContainers? There is no official memcached TestContainer so I've attempted to use the GenericContainer but haven't had much success

I've been attempting to use the `GenericContainer` but have been unsuccessful. I'm using `testcontainers:1.10.1` with `xmemcached:2.4.5`

I have a class rule

@ClassRule
public static GenericContainer memcached = new GenericContainer("memcached:alpine")
 
.withExposedPorts(11211);

with the following setup

List<InetSocketAddress> SERVERS = Collections.unmodifiableList(Collections.singletonList(new InetSocketAddress("localhost", 11211)));
XMemcachedClientBuilder builder = new XMemcachedClientBuilder(SERVERS);
MemcachedClient memcachedClient = builder.build();

and when calling memcachedClient.get(key) a `connection refused` with the following stack trace

2018-11-11 22:43:04,670 INFO  🐳 [memcached:alpine] - Creating container for image: memcached:alpine
2018-11-11 22:43:04,711 INFO  org.testcontainers.utility.RegistryAuthLocator - Credentials not found for host (index.docker.io) when using credential helper/store (docker-credential-osxkeychain)
2018-11-11 22:43:04,875 INFO  🐳 [memcached:alpine] - Starting container with ID: aa3b1b10ed8f6c85813f7f61a273e5827964fbcfc9f6b63c8120d66b2994da32
2018-11-11 22:43:05,487 INFO  🐳 [memcached:alpine] - Container memcached:alpine is starting: aa3b1b10ed8f6c85813f7f61a273e5827964fbcfc9f6b63c8120d66b2994da32
2018-11-11 22:43:05,960 INFO  🐳 [memcached:alpine] - Container memcached:alpine started
2018-11-11 22:43:14,644 INFO  net.rubyeye.xmemcached.XMemcachedClient - XMemcachedClient is using Text protocol
2018-11-11 22:43:14,817 INFO  com.google.code.yanf4j.nio.impl.SelectorManager - Creating 4 reactors...
2018-11-11 22:43:14,833 INFO  com.google.code.yanf4j.core.impl.AbstractController - The Controller started at localhost/127.0.0.1:0 ...
2018-11-11 22:43:14,867 ERROR net.rubyeye.xmemcached.XMemcachedClient - connect to 127.0.0.1:11211 error
java.util.concurrent.ExecutionException: java.net.ConnectException: Connection refused
at com.google.code.yanf4j.core.impl.FutureImpl.get(FutureImpl.java:138)
at net.rubyeye.xmemcached.XMemcachedClient.connect(XMemcachedClient.java:552)
at net.rubyeye.xmemcached.XMemcachedClient.<init>(XMemcachedClient.java:813)
at net.rubyeye.xmemcached.XMemcachedClientBuilder.build(XMemcachedClientBuilder.java:324)

Sean Carroll

unread,
Nov 12, 2018, 1:05:52 PM11/12/18
to xmemcached
TestContainers uses random ports and I needed to use memcached.getMappedPort(11211)
Reply all
Reply to author
Forward
0 new messages