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

Command interface - issues with async array results #2612 #3033

Merged
merged 1 commit into from
Oct 30, 2024
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
5 changes: 5 additions & 0 deletions src/main/java/io/lettuce/core/output/BooleanListOutput.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Expand Down
Original file line number Diff line number Diff line change
@@ -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<String, String> 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<Boolean> flux = commands.insert("myBloomFilter", 10000, 0.01, new String[] { "1", "2", "3", });
List<Boolean> res = flux.collectList().block();

assertThat(res).hasSize(3);
assertThat(res).contains(true, true, true);
}

protected StatefulConnection<String, String> getConnection() {
StatefulRedisConnection<String, String> 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<Boolean> insert(@Param("filter") String filter, @Param("capacity") long capacity, @Param("error") double error,
@Param("items") String[] items);

static CustomCommands instance(StatefulConnection<String, String> conn) {
RedisCommandFactory factory = new RedisCommandFactory(conn);
return factory.getCommands(CustomCommands.class);
}

}

}
Loading