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

Experiment Apache Kvrocks to back our tests #2660

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
/****************************************************************
* Licensed to the Apache Software Foundation (ASF) under one *
* or more contributor license agreements. See the NOTICE file *
* distributed with this work for additional information *
* regarding copyright ownership. The ASF licenses this file *
* to you under the Apache License, Version 2.0 (the *
* "License"); you may not use this file except in compliance *
* with the License. You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, *
* software distributed under the License is distributed on an *
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
* KIND, either express or implied. See the License for the *
* specific language governing permissions and limitations *
* under the License. *
****************************************************************/

package org.apache.james.backends.redis;

import static java.lang.Boolean.TRUE;

import java.net.URI;
import java.time.Duration;
import java.util.UUID;

import org.apache.http.client.utils.URIBuilder;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.Network;
import org.testcontainers.containers.wait.strategy.DockerHealthcheckWaitStrategy;
import org.testcontainers.utility.DockerImageName;

import com.github.fge.lambdas.Throwing;

import io.lettuce.core.RedisClient;
import io.lettuce.core.api.sync.RedisCommands;

public class DockerKvrocks extends DockerRedis {
public static final DockerImageName DEFAULT_IMAGE_NAME = DockerImageName.parse("apache/kvrocks").withTag("2.11.1");
public static final int DEFAULT_PORT = 6666;

private final GenericContainer<?> container;

public DockerKvrocks() {
this.container = getContainer();
}

public DockerKvrocks(Network network) {
this.container = getContainer()
.withNetwork(network);
}

private GenericContainer<?> getContainer() {
return new GenericContainer<>(DEFAULT_IMAGE_NAME)
.withExposedPorts(DEFAULT_PORT)
.withCreateContainerCmdModifier(createContainerCmd -> createContainerCmd.withName("james-kvrocks-test-" + UUID.randomUUID()))
.withNetworkAliases("redis")
.waitingFor(new DockerHealthcheckWaitStrategy()
.withStartupTimeout(Duration.ofMinutes(2)));
}

@Override
public URI redisURI() {
return Throwing.supplier(() -> new URIBuilder()
.setScheme("redis")
.setHost(container.getHost())
.setPort(container.getMappedPort(DEFAULT_PORT))
.build()).get();
}

@Override
public void start() {
if (!container.isRunning()) {
container.start();
}
}

@Override
public void stop() {
container.stop();
}

@Override
public void pause() {
container.getDockerClient().pauseContainerCmd(container.getContainerId()).exec();
}

@Override
public void unPause() {
container.getDockerClient().unpauseContainerCmd(container.getContainerId()).exec();
}

@Override
public boolean isPaused() {
return TRUE.equals(container.getDockerClient().inspectContainerCmd(container.getContainerId())
.exec()
.getState()
.getPaused());
}

public RedisCommands<String, String> createClient() {
return RedisClient.create(redisURI().toString())
.connect().sync();
}

public void flushAll() {
createClient().flushall();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import com.google.inject.Provides;

public class RedisExtension implements GuiceModuleTestExtension {
private static final DockerRedis DOCKER_REDIS_SINGLETON = new DockerRedis();
private static final DockerKvrocks DOCKER_REDIS_SINGLETON = new DockerKvrocks();

@Override
public void beforeAll(ExtensionContext extensionContext) {
Expand Down Expand Up @@ -59,7 +59,7 @@ public RedisConfiguration provideConfig() {
};
}

public DockerRedis dockerRedis() {
public DockerKvrocks dockerRedis() {
return DOCKER_REDIS_SINGLETON;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ public class RspamdExtension implements GuiceModuleTestExtension {
public static final String PASSWORD = "admin";

private static final DockerImageName RSPAMD_IMAGE = DockerImageName.parse("rspamd/rspamd").withTag("3.9.1");
private static final DockerImageName REDIS_IMAGE = DockerImageName.parse("redis").withTag("7.2.5");
private static final DockerImageName REDIS_IMAGE = DockerImageName.parse("apache/kvrocks").withTag("2.11.1");
private static final DockerImageName CLAMAV_IMAGE = DockerImageName.parse("clamav/clamav").withTag("1.3");
private static final int RSPAMD_DEFAULT_PORT = 11334;
private static final int REDIS_DEFAULT_PORT = 6379;
private static final int REDIS_DEFAULT_PORT = 6666;
private static final int CLAMAV_DEFAULT_PORT = 3310;

private final GenericContainer<?> rspamdContainer;
Expand Down Expand Up @@ -80,7 +80,7 @@ public void beforeEach(ExtensionContext extensionContext) {
public GenericContainer<?> rspamdContainer(Network network) {
return new GenericContainer<>(RSPAMD_IMAGE)
.withExposedPorts(RSPAMD_DEFAULT_PORT)
.withEnv("RSPAMD_REDIS_SERVERS", "redis")
.withEnv("RSPAMD_REDIS_SERVERS", "redis:6666")
.withEnv("RSPAMD_CLAMAV_SERVERS", "clamav")
.withEnv("RSPAMD_PASSWORD", PASSWORD)
.withCopyFileToContainer(MountableFile.forClasspathResource("rspamd-config/antivirus.conf"), "/etc/rspamd/override.d/antivirus.conf")
Expand Down Expand Up @@ -119,7 +119,7 @@ public GenericContainer<?> clamAVContainer(Network network) {

public void redisFlushAll() {
try {
redisContainer.execInContainer("redis-cli", "flushall");
redisContainer.execInContainer("redis-cli", "-p", "6666", "flushall");
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
Expand Down