Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replaced emdedded RedisServer with testcontainers. #2221

Merged
merged 6 commits into from
Nov 8, 2021
Merged
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 CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ to `mssql` to align with other agents.
* Add `-download-agent-version` to the agent <<setup-attach-cli-usage-options, attach CLI tool options>>, allowing the
user to configure an arbitrary agent version that will be downloaded from maven and attached - {pull}1959[#1959]
* Add extra check to detect improper agent setup - {pull}2076[#2076]
* In redis tests - embedded RedisServer is replaced by testcontainers - {pull}2221[#2221]

[float]
===== Performance improvements
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

class Jedis2InstrumentationTest extends Jedis1InstrumentationTest {
class Jedis2InstrumentationIT extends Jedis1InstrumentationIT {

private ShardedJedis shardedJedis;
private BinaryJedis binaryJedis;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@
*/
package co.elastic.apm.agent.jedis;

class Jedis3InstrumentationTest extends Jedis2InstrumentationTest {
class Jedis3InstrumentationIT extends Jedis2InstrumentationIT {

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

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

class Jedis1InstrumentationTest extends AbstractRedisInstrumentationTest {
class Jedis1InstrumentationIT extends AbstractRedisInstrumentationTest {

protected Jedis jedis;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

public class Lettuce3InstrumentationTest extends AbstractRedisInstrumentationTest {
public class Lettuce3InstrumentationIT extends AbstractRedisInstrumentationTest {

private RedisClient client;
private RedisConnection<String, String> connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Lettuce3VersionsIT {

public Lettuce3VersionsIT(List<String> dependencies) throws Exception {
System.setProperty("io.lettuce.core.kqueue", "false");
runner = new TestClassWithDependencyRunner(dependencies, Lettuce3InstrumentationTest.class);
runner = new TestClassWithDependencyRunner(dependencies, Lettuce3InstrumentationIT.class);
}

@Parameterized.Parameters(name= "{0}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

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

public class Lettuce4InstrumentationTest extends AbstractRedisInstrumentationTest {
public class Lettuce4InstrumentationIT extends AbstractRedisInstrumentationTest {

private RedisClient client;
private StatefulRedisConnection<String, String> connection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Lettuce4VersionsIT {

public Lettuce4VersionsIT(List<String> dependencies) throws Exception {
System.setProperty("io.lettuce.core.kqueue", "false");
runner = new TestClassWithDependencyRunner(dependencies, Lettuce4InstrumentationTest.class);
runner = new TestClassWithDependencyRunner(dependencies, Lettuce4InstrumentationIT.class);
}

@Parameterized.Parameters(name= "{0}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

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

public class Lettuce5InstrumentationTest extends AbstractRedisInstrumentationTest {
public class Lettuce5InstrumentationIT extends AbstractRedisInstrumentationTest {

private StatefulRedisConnection<String, String> connection;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Lettuce5VersionsIT {

public Lettuce5VersionsIT(List<String> dependencies) throws Exception {
System.setProperty("io.lettuce.core.kqueue", "false");
runner = new TestClassWithDependencyRunner(dependencies, Lettuce5InstrumentationTest.class);
runner = new TestClassWithDependencyRunner(dependencies, Lettuce5InstrumentationIT.class);
}

@Parameterized.Parameters(name= "{0}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,19 @@
import org.junit.Before;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import redis.embedded.RedisServer;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.wait.strategy.Wait;

import javax.net.ServerSocketFactory;
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

public abstract class AbstractRedisInstrumentationTest extends AbstractInstrumentationTest {
protected RedisServer server;
protected int redisPort;
private String expectedAddress;
protected static GenericContainer redisContainer;

public AbstractRedisInstrumentationTest() {
this.expectedAddress = "localhost";
Expand All @@ -51,23 +49,13 @@ public AbstractRedisInstrumentationTest(String expectedAddress) {
this.expectedAddress = expectedAddress;
}

private static int getAvailablePort() throws IOException {
try (ServerSocket socket = ServerSocketFactory.getDefault().createServerSocket(0, 1, InetAddress.getByName("localhost"))) {
return socket.getLocalPort();
}
}

@Before
@BeforeEach
public final void initRedis() throws IOException {
redisPort = getAvailablePort();
server = RedisServer.builder()
// workaround https://github.com/kstyrc/embedded-redis/issues/51
.setting("maxmemory 128M")
.setting("bind 127.0.0.1")
.port(redisPort)
.build();
server.start();
redisContainer = new GenericContainer("redis:6.2.6").withExposedPorts(6379);
redisContainer.start();
redisContainer.waitingFor(Wait.forLogMessage("Started!", 1));
redisPort = redisContainer.getFirstMappedPort();
tracer.startRootTransaction(null).activate();
}

Expand All @@ -78,7 +66,7 @@ public final void stopRedis() {
if (transaction != null) {
transaction.deactivate().end();
}
server.stop();
redisContainer.stop();
}

public void assertTransactionWithRedisSpans(String... commands) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@

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

class RedissonInstrumentationTest extends AbstractRedisInstrumentationTest {
class RedissonInstrumentationIT extends AbstractRedisInstrumentationTest {

protected RedissonClient redisson;

public RedissonInstrumentationTest() {
public RedissonInstrumentationIT() {
super("127.0.0.1");
}

Expand Down
5 changes: 2 additions & 3 deletions apm-agent-plugins/apm-redis-plugin/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,8 @@

<dependencies>
<dependency>
<groupId>com.github.kstyrc</groupId>
<artifactId>embedded-redis</artifactId>
<version>0.6</version>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down