-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #43454 from mcruzdev/issue-43167
Add client parameter when creating Vertx Redis client
- Loading branch information
Showing
5 changed files
with
191 additions
and
7 deletions.
There are no files selected for viewing
64 changes: 64 additions & 0 deletions
64
...oyment/src/test/java/io/quarkus/redis/deployment/client/RedisConfigureClientNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package io.quarkus.redis.deployment.client; | ||
|
||
import jakarta.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import io.quarkus.redis.client.RedisClientName; | ||
import io.quarkus.redis.datasource.RedisDataSource; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
import io.quarkus.test.common.QuarkusTestResource; | ||
import io.vertx.mutiny.redis.client.Response; | ||
import io.vertx.redis.client.Command; | ||
|
||
@QuarkusTestResource(RedisTestResource.class) | ||
public class RedisConfigureClientNameTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest unitTest = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)) | ||
.overrideConfigKey("quarkus.redis.my-redis.hosts", "${quarkus.redis.tr}/1") | ||
.overrideConfigKey("quarkus.redis.my-redis.configure-client-name", "true") | ||
.overrideConfigKey("quarkus.redis.my-redis.client-name", "perfect-client-name") | ||
.overrideConfigKey("quarkus.redis.no-configure.hosts", "${quarkus.redis.tr}/2") | ||
.overrideConfigKey("quarkus.redis.no-configure.client-name", "i-am-not-applicable") | ||
.overrideConfigKey("quarkus.redis.no-configure.configure-client-name", "false") | ||
.overrideConfigKey("quarkus.redis.from-annotation.configure-client-name", "true") | ||
.overrideConfigKey("quarkus.redis.from-annotation.hosts", "${quarkus.redis.tr}/3"); | ||
|
||
@Inject | ||
@RedisClientName("my-redis") | ||
RedisDataSource myRedis; | ||
|
||
@Inject | ||
@RedisClientName("no-configure") | ||
RedisDataSource noConfigure; | ||
|
||
@Inject | ||
@RedisClientName("from-annotation") | ||
RedisDataSource fromAnnotation; | ||
|
||
@Test | ||
void shouldConfigureClientNameCorrectly() { | ||
Response executed = myRedis.execute(Command.CLIENT, "GETNAME"); | ||
Assertions.assertThat(executed).isNotNull(); | ||
Assertions.assertThat(executed.toString()).isEqualTo("perfect-client-name"); | ||
} | ||
|
||
@Test | ||
void shouldConfigureFromRedisClientNameAnnotation() { | ||
Response executed = fromAnnotation.execute(Command.CLIENT, "GETNAME"); | ||
Assertions.assertThat(executed).isNotNull(); | ||
Assertions.assertThat(executed.toString()).isEqualTo("from-annotation"); | ||
} | ||
|
||
@Test | ||
void shouldNotConfigureClientName() { | ||
Response executed = noConfigure.execute(Command.CLIENT, "GETNAME"); | ||
Assertions.assertThat(executed).isNull(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...nt/runtime/src/test/java/io/quarkus/redis/runtime/client/VertxRedisClientFactoryTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.quarkus.redis.runtime.client; | ||
|
||
import java.net.URI; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
class VertxRedisClientFactoryTest { | ||
|
||
@Test | ||
void shouldApplyQuery() { | ||
|
||
String applied = VertxRedisClientFactory.applyClientQueryParam( | ||
"quarkus-app", URI.create("redis://localhost:6379")); | ||
Assertions.assertThat(applied).isEqualTo("redis://localhost:6379?client=quarkus-app"); | ||
} | ||
|
||
@Test | ||
void shouldNotApplyQuery() { | ||
String applied = VertxRedisClientFactory.applyClientQueryParam( | ||
"quarkus-app", URI.create("redis://localhost:6379?client=quarkiverse-app")); | ||
Assertions.assertThat(applied).isEqualTo("redis://localhost:6379?client=quarkiverse-app"); | ||
} | ||
|
||
@Test | ||
void shouldApplyWithReservedURICharacters() { | ||
String applied = VertxRedisClientFactory.applyClientQueryParam( | ||
"quarkus&%$ app", URI.create("redis://localhost:6379")); | ||
Assertions.assertThat(applied).isEqualTo("redis://localhost:6379?client=quarkus&%25$%20app"); | ||
} | ||
|
||
@Test | ||
void shouldApplyWithQueryParams() { | ||
String applied = VertxRedisClientFactory.applyClientQueryParam( | ||
"quarkus-app", URI.create("redis://localhost:6379?someQueryParam=123456789")); | ||
Assertions.assertThat(applied).isEqualTo("redis://localhost:6379?someQueryParam=123456789&client=quarkus-app"); | ||
} | ||
|
||
} |