Skip to content

Commit

Permalink
test: Switched to Redis Enterprise container for cluster tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Jul 30, 2022
1 parent c579fd7 commit 3a3d882
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import picocli.CommandLine;

public abstract class AbstractDatabaseTests extends AbstractRiotIntegrationTests {
public abstract class AbstractDatabaseIntegrationTests extends AbstractRiotIntegrationTests {

@Override
protected RiotDb app() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@

@Testcontainers
@SuppressWarnings({ "rawtypes", "unchecked" })
public class PostgresTests extends AbstractDatabaseTests {
public class PostgresIntegrationTests extends AbstractDatabaseIntegrationTests {

private static final DockerImageName POSTGRE_DOCKER_IMAGE_NAME = DockerImageName.parse(PostgreSQLContainer.IMAGE)
.withTag(PostgreSQLContainer.DEFAULT_TAG);
Expand All @@ -51,7 +51,7 @@ public static void setupAll() throws SQLException, IOException {
scriptRunner.setAutoCommit(false);
scriptRunner.setStopOnError(true);
String file = "northwind.sql";
InputStream inputStream = PostgresTests.class.getClassLoader().getResourceAsStream(file);
InputStream inputStream = PostgresIntegrationTests.class.getClassLoader().getResourceAsStream(file);
if (inputStream == null) {
throw new FileNotFoundException(file);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.riot.file.test;
package com.redis.riot.file;

import java.io.IOException;
import java.nio.file.Files;
Expand Down Expand Up @@ -28,10 +28,6 @@
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.redis.lettucemod.api.sync.RedisModulesCommands;
import com.redis.riot.AbstractRiotIntegrationTests;
import com.redis.riot.file.DumpFileImportCommand;
import com.redis.riot.file.FileExportCommand;
import com.redis.riot.file.FileImportCommand;
import com.redis.riot.file.RiotFile;
import com.redis.riot.file.resource.XmlItemReader;
import com.redis.riot.file.resource.XmlItemReaderBuilder;
import com.redis.riot.file.resource.XmlObjectReader;
Expand All @@ -49,15 +45,15 @@
import picocli.CommandLine;

@SuppressWarnings("unchecked")
public class RiotFileIntegrationTests extends AbstractRiotIntegrationTests {
class FileIntegrationTests extends AbstractRiotIntegrationTests {

protected final static int COUNT = 2410;

private static Path tempDir;

@BeforeAll
public static void setupAll() throws IOException {
tempDir = Files.createTempDirectory(RiotFileIntegrationTests.class.getName());
public void setupAll() throws IOException {
tempDir = Files.createTempDirectory(FileIntegrationTests.class.getName());
}

private String replace(String file) {
Expand Down Expand Up @@ -319,7 +315,7 @@ private void configureExportCommand(CommandLine.ParseResult parseResult) {

@ParameterizedTest
@RedisTestContextsSource
void importJsonElastic(RedisTestContext redis) throws Exception {
void importJSONElastic(RedisTestContext redis) throws Exception {
execute("import-json-elastic", redis);
RedisKeyCommands<String, String> sync = redis.sync();
Assertions.assertEquals(2, sync.keys("estest:*").size());
Expand All @@ -330,7 +326,7 @@ void importJsonElastic(RedisTestContext redis) throws Exception {

@ParameterizedTest
@RedisTestContextsSource
void importJson(RedisTestContext redis) throws Exception {
void importJSON(RedisTestContext redis) throws Exception {
execute("import-json", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("beer:*");
Expand All @@ -341,7 +337,7 @@ void importJson(RedisTestContext redis) throws Exception {

@ParameterizedTest
@RedisTestContextsSource
void importXml(RedisTestContext redis) throws Exception {
void importXML(RedisTestContext redis) throws Exception {
execute("import-xml", redis);
RedisKeyCommands<String, String> sync = redis.sync();
List<String> keys = sync.keys("trade:*");
Expand All @@ -362,7 +358,7 @@ void exportJSON(RedisTestContext redis) throws Exception {
@SuppressWarnings("rawtypes")
@ParameterizedTest
@RedisTestContextsSource
void exportJsonGz(RedisTestContext redis) throws Exception {
void exportJSONGz(RedisTestContext redis) throws Exception {
Path file = tempFile("beers.json.gz");
execute("import-json", redis);
execute("export-json-gz", redis, this::configureExportCommand);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.riot.file.test;
package com.redis.riot.file;

import java.util.Iterator;
import java.util.Map;
Expand All @@ -9,13 +9,10 @@
import org.springframework.batch.item.ParseException;
import org.springframework.batch.item.UnexpectedInputException;

import com.redis.riot.file.FileImportCommand;
import com.redis.riot.file.FileImportOptions;

class RiotFileTests {
class FileTests {

@Test
void testJSONImport() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
void importJSON() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
FileImportCommand command = FileImportCommand.builder().build();
Iterator<Map<String, Object>> iterator = command.read("https://storage.googleapis.com/jrx/beers.json");
Assertions.assertTrue(iterator.hasNext());
Expand All @@ -30,7 +27,7 @@ void testJSONImport() throws UnexpectedInputException, ParseException, NonTransi
}

@Test
void testCSVImport() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
void importCSV() throws UnexpectedInputException, ParseException, NonTransientResourceException, Exception {
FileImportCommand command = FileImportCommand.builder()
.options(FileImportOptions.builder().header(true).build()).build();
Iterator<Map<String, Object>> iterator = command.read("https://storage.googleapis.com/jrx/beers.csv");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.riot.file.test;
package com.redis.riot.file;

import java.util.Arrays;
import java.util.Collection;
Expand All @@ -12,14 +12,13 @@
import com.redis.lettucemod.search.Suggestion;
import com.redis.lettucemod.search.SuggetOptions;
import com.redis.riot.AbstractRiotTests;
import com.redis.riot.file.RiotFile;
import com.redis.testcontainers.RedisModulesContainer;
import com.redis.testcontainers.RedisServer;
import com.redis.testcontainers.junit.RedisTestContext;
import com.redis.testcontainers.junit.RedisTestContextsSource;

@SuppressWarnings("unchecked")
class RiotFileModulesTests extends AbstractRiotTests {
class ModulesTests extends AbstractRiotTests {

@Override
protected Collection<RedisServer> redisServers() {
Expand All @@ -44,7 +43,7 @@ void importSugadd(RedisTestContext redis) throws Exception {

@ParameterizedTest
@RedisTestContextsSource
void importJsonElasticJsonSet(RedisTestContext redis) throws Exception {
void importElasticJSON(RedisTestContext redis) throws Exception {
execute("import-json-elastic-jsonset", redis);
RedisModulesCommands<String, String> sync = redis.sync();
Assertions.assertEquals(2, sync.keys("elastic:*").size());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.redis.riot.file.test;
package com.redis.riot.file;

import java.nio.file.Files;
import java.nio.file.Path;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
import io.lettuce.core.api.sync.RedisStreamCommands;

@SuppressWarnings("unchecked")
class RiotGenTests extends AbstractRiotIntegrationTests {
class GenIntegrationTests extends AbstractRiotIntegrationTests {

private final RedisModulesContainer redisMod = new RedisModulesContainer(
RedisModulesContainer.DEFAULT_IMAGE_NAME.withTag(RedisModulesContainer.DEFAULT_TAG));
Expand Down Expand Up @@ -135,7 +135,7 @@ void fakerTsAddWithOptions() throws Exception {
MRangeOptions.<String, String>filters("character1=Einstein").build());
Assertions.assertFalse(results.isEmpty());
}

@Test
void ds() throws Exception {
RedisTestContext redis = getContext(redisMod);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

@Testcontainers
@SuppressWarnings("unchecked")
class TestReplicate extends AbstractRiotIntegrationTests {
class RedisIntegrationTests extends AbstractRiotIntegrationTests {

private static final Duration IDLE_TIMEOUT = Duration.ofSeconds(10);

Expand Down Expand Up @@ -115,6 +115,7 @@ void replicateDSLive(RedisTestContext container) throws Exception {
}

private void runLiveReplication(String filename, RedisTestContext source) throws Exception {
source.sync().configSet("notify-keyspace-events", "AK");
generate(DataStructureGeneratorItemReader.builder().count(3000).build(), source);
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
executor.schedule(() -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import picocli.CommandLine.Command;

@Deprecated
@Command(name = "riot-stream", subcommands = { StreamImportCommand.class, StreamExportCommand.class })
public class RiotStream extends RiotApp {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.params.ParameterizedTest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -46,9 +47,10 @@
import picocli.CommandLine;

@SuppressWarnings("unchecked")
class TestKafka extends AbstractRiotIntegrationTests {
@Disabled
class StreamIntegrationTests extends AbstractRiotIntegrationTests {

private static final Logger log = LoggerFactory.getLogger(TestKafka.class);
private static final Logger log = LoggerFactory.getLogger(StreamIntegrationTests.class);

@Container
private static final KafkaContainer KAFKA = new KafkaContainer(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,32 @@
import java.util.UUID;

import org.springframework.batch.item.ItemReader;
import org.springframework.util.unit.DataSize;

import com.redis.enterprise.Database;
import com.redis.spring.batch.DataStructure;
import com.redis.spring.batch.RedisItemWriter;
import com.redis.spring.batch.reader.DataStructureGeneratorItemReader;
import com.redis.spring.batch.support.JobRunner;
import com.redis.testcontainers.RedisClusterContainer;
import com.redis.testcontainers.RedisContainer;
import com.redis.testcontainers.RedisEnterpriseContainer;
import com.redis.testcontainers.RedisServer;
import com.redis.testcontainers.junit.RedisTestContext;

public abstract class AbstractRiotIntegrationTests extends AbstractRiotTests {

private static final int DEFAULT_BATCH_SIZE = 50;

private final RedisContainer redis = new RedisContainer(
RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG)).withKeyspaceNotifications();
private final RedisClusterContainer redisCluster = new RedisClusterContainer(
RedisClusterContainer.DEFAULT_IMAGE_NAME.withTag(RedisClusterContainer.DEFAULT_TAG))
.withKeyspaceNotifications();
private final RedisContainer redisContainer = new RedisContainer(
RedisContainer.DEFAULT_IMAGE_NAME.withTag(RedisContainer.DEFAULT_TAG));

private final RedisEnterpriseContainer redisEnterpriseContainer = new RedisEnterpriseContainer(
RedisEnterpriseContainer.DEFAULT_IMAGE_NAME.withTag("latest"))
.withDatabase(Database.name("RiotTests").memory(DataSize.ofMegabytes(90)).ossCluster(true).build());

@Override
protected Collection<RedisServer> redisServers() {
return Arrays.asList(redis, redisCluster);
return Arrays.asList(redisContainer, redisEnterpriseContainer);
}

protected void generate(RedisTestContext redis) throws Exception {
Expand Down

0 comments on commit 3a3d882

Please sign in to comment.