From 19f76a34db1efb86923421eace28a47b7695dfe7 Mon Sep 17 00:00:00 2001 From: Tihomir Krasimirov Mateev Date: Wed, 30 Oct 2024 17:00:38 +0200 Subject: [PATCH] Implement missing method in the BooleanListOutput (#3033) --- .../core/output/BooleanListOutput.java | 5 + .../CommandInterfacesIntegrationTests.java | 110 ++++++++++++++++++ 2 files changed, 115 insertions(+) create mode 100644 src/test/java/io/lettuce/core/commands/CommandInterfacesIntegrationTests.java diff --git a/src/main/java/io/lettuce/core/output/BooleanListOutput.java b/src/main/java/io/lettuce/core/output/BooleanListOutput.java index 3170aabd08..e7694bceac 100644 --- a/src/main/java/io/lettuce/core/output/BooleanListOutput.java +++ b/src/main/java/io/lettuce/core/output/BooleanListOutput.java @@ -49,6 +49,11 @@ public void set(long integer) { subscriber.onNext(output, (integer == 1) ? Boolean.TRUE : Boolean.FALSE); } + @Override + public void set(boolean value) { + subscriber.onNext(output, value); + } + @Override public void multi(int count) { diff --git a/src/test/java/io/lettuce/core/commands/CommandInterfacesIntegrationTests.java b/src/test/java/io/lettuce/core/commands/CommandInterfacesIntegrationTests.java new file mode 100644 index 0000000000..88325440ac --- /dev/null +++ b/src/test/java/io/lettuce/core/commands/CommandInterfacesIntegrationTests.java @@ -0,0 +1,110 @@ +/* + * Copyright 2011-Present, Redis Ltd. and Contributors + * All rights reserved. + * + * Licensed under the MIT License. + * + * This file contains contributions from third-party contributors + * licensed 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 + * + * https://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 io.lettuce.core.commands; + +import io.lettuce.core.RedisClient; +import io.lettuce.core.RedisContainerIntegrationTests; +import io.lettuce.core.RedisURI; +import io.lettuce.core.TestSupport; +import io.lettuce.core.api.StatefulConnection; +import io.lettuce.core.api.StatefulRedisConnection; +import io.lettuce.core.api.sync.RedisCommands; +import io.lettuce.core.dynamic.Commands; +import io.lettuce.core.dynamic.RedisCommandFactory; +import io.lettuce.core.dynamic.annotation.Command; +import io.lettuce.core.dynamic.annotation.Param; +import io.lettuce.test.LettuceExtension; +import io.lettuce.test.condition.EnabledOnCommand; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.junit.jupiter.api.extension.ExtendWith; +import reactor.core.publisher.Flux; + +import javax.inject.Inject; +import java.lang.reflect.Proxy; +import java.util.List; + +import static io.lettuce.TestTags.INTEGRATION_TEST; +import static io.lettuce.core.SetArgs.Builder.ex; +import static io.lettuce.core.SetArgs.Builder.exAt; +import static io.lettuce.core.SetArgs.Builder.px; +import static io.lettuce.core.SetArgs.Builder.pxAt; +import static io.lettuce.core.StringMatchResult.Position; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; + +/** + * Integration tests for {@link io.lettuce.core.dynamic.annotation.Command}. + * + * @author Tihomir Mateev + */ +@Tag(INTEGRATION_TEST) +public class CommandInterfacesIntegrationTests extends RedisContainerIntegrationTests { + + protected static RedisClient client; + + protected static RedisCommands redis; + + protected CommandInterfacesIntegrationTests() { + RedisURI redisURI = RedisURI.Builder.redis("127.0.0.1").withPort(16379).build(); + + client = RedisClient.create(redisURI); + redis = client.connect().sync(); + } + + @BeforeEach + void setUp() { + this.redis.flushall(); + } + + @Test + void issue2612() { + CustomCommands commands = CustomCommands.instance(getConnection()); + + Flux flux = commands.insert("myBloomFilter", 10000, 0.01, new String[] { "1", "2", "3", }); + List res = flux.collectList().block(); + + assertThat(res).hasSize(3); + assertThat(res).contains(true, true, true); + } + + protected StatefulConnection getConnection() { + StatefulRedisConnection src = redis.getStatefulConnection(); + Assumptions.assumeFalse(Proxy.isProxyClass(src.getClass()), "Redis connection is proxy, skipping."); + return src; + } + + private interface CustomCommands extends Commands { + + @Command("BF.INSERT :filter CAPACITY :capacity ERROR :error ITEMS :items ") + Flux insert(@Param("filter") String filter, @Param("capacity") long capacity, @Param("error") double error, + @Param("items") String[] items); + + static CustomCommands instance(StatefulConnection conn) { + RedisCommandFactory factory = new RedisCommandFactory(conn); + return factory.getCommands(CustomCommands.class); + } + + } + +}