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 4 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 @@ -98,6 +98,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 @@ -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
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