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

Adds redis-devservices it #17133

Merged
merged 1 commit into from
May 13, 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 integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
<module>native-config-profile</module>
<module>logging-min-level-unset</module>
<module>logging-min-level-set</module>
<module>redis-devservices</module>

<!-- gRPC tests -->
<module>grpc-tls</module>
Expand Down
91 changes: 91 additions & 0 deletions integration-tests/redis-devservices/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-integration-tests-parent</artifactId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<artifactId>quarkus-integration-test-redis-devservices</artifactId>
<name>Quarkus - Integration Tests - Redis DevService</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
<scope>test</scope>
</dependency>
<!-- Minimal test dependencies to *-deployment artifacts for consistent build order -->
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-redis-client-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-arc-deployment</artifactId>
<version>${project.version}</version>
<type>pom</type>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>*</groupId>
<artifactId>*</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#quarkus.redis.hosts=redis://localhost:6379
quarkus.redis.health.enabled=true
#quarkus.redis.devservices.image-name=redis:6.0-alpine
#quarkus.redis.devservices.port=6377
#quarkus.redis.devservices.enabled=true
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.redis.devservices.it;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.quarkus.redis.devservices.it.profiles.DevServicesCustomPortProfile;
import io.quarkus.redis.devservices.it.utils.SocketKit;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(DevServicesCustomPortProfile.class)
public class DevServicesRedisCustomPortITest {

@Test
@DisplayName("should start redis container with the given custom port")
public void shouldStartRedisContainer() {
Assertions.assertTrue(SocketKit.isPortAlreadyUsed(6371));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkus.redis.devservices.it;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.quarkus.redis.devservices.it.profiles.DevServicesDisabledProfile;
import io.quarkus.redis.devservices.it.utils.SocketKit;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(DevServicesDisabledProfile.class)
public class DevServicesRedisDisabledITest {

@Test
@DisplayName("should not start the redis container when devservices is disabled")
public void shouldStartRedisContainer() {
Assertions.assertFalse(SocketKit.isPortAlreadyUsed(6379));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package io.quarkus.redis.devservices.it;

import java.util.Arrays;

import javax.inject.Inject;

import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import io.quarkus.redis.client.RedisClient;
import io.quarkus.redis.devservices.it.profiles.DevServiceRedis;
import io.quarkus.redis.devservices.it.utils.SocketKit;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;

@QuarkusTest
@TestProfile(DevServiceRedis.class)
public class DevServicesRedisITest {

@Inject
RedisClient redisClient;

@BeforeEach
public void setUp() {
redisClient.set(Arrays.asList("anykey", "anyvalue"));
}

@Test
@DisplayName("given quarkus.redis.hosts disabled should start redis testcontainer")
public void shouldStartRedisContainer() {
Assertions.assertTrue(SocketKit.isPortAlreadyUsed(6379));
}

@Test
@DisplayName("given redis container must communicate with it and return value by key")
public void shouldReturnAllKeys() {
Assertions.assertEquals("anyvalue", redisClient.get("anykey").toString());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package io.quarkus.redis.devservices.it.profiles;

import java.util.Collections;
import java.util.Map;

import io.quarkus.test.junit.QuarkusTestProfile;

public class DevServiceRedis implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("quarkus.redis.devservices.port", "6379");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.redis.devservices.it.profiles;

import java.util.Collections;
import java.util.Map;

import io.quarkus.test.junit.QuarkusTestProfile;

public class DevServicesCustomPortProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("quarkus.redis.devservices.port", "6371");
}

@Override
public String getConfigProfile() {
return "test";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.redis.devservices.it.profiles;

import java.util.Collections;
import java.util.Map;

import io.quarkus.test.junit.QuarkusTestProfile;

public class DevServicesDisabledProfile implements QuarkusTestProfile {

@Override
public Map<String, String> getConfigOverrides() {
return Collections.singletonMap("quarkus.redis.devservices.enabled", "false");
}

@Override
public String getConfigProfile() {
return "test";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.quarkus.redis.devservices.it.utils;

import java.io.IOException;
import java.net.Socket;

public class SocketKit {

public static boolean isPortAlreadyUsed(Integer port) {
try (Socket ignored = new Socket("localhost", port)) {
ignored.close();
return true;
} catch (IOException ignored) {
return false;
}
}
}