DATAREDIS-659 - Provide ReactiveServerCommands for basic server interaction.
Original Pull Request: #253
This commit is contained in:
committed by
Christoph Strobl
parent
772d412ba8
commit
1f2610ba91
@@ -104,7 +104,7 @@ public class LettuceClusterConnectionUnitTests {
|
||||
when(clusterMock.getPartitions()).thenReturn(partitions);
|
||||
|
||||
ClusterCommandExecutor executor = new ClusterCommandExecutor(
|
||||
new LettuceClusterConnection.LettuceClusterTopologyProvider(clusterMock), resourceProvider,
|
||||
new LettuceClusterTopologyProvider(clusterMock), resourceProvider,
|
||||
LettuceClusterConnection.exceptionConverter);
|
||||
|
||||
connection = new LettuceClusterConnection(clusterMock, executor) {
|
||||
|
||||
@@ -0,0 +1,170 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.springframework.data.redis.connection.ClusterTestVariables.*;
|
||||
import static org.springframework.data.redis.connection.lettuce.LettuceReactiveCommandsTestsBase.*;
|
||||
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.data.redis.connection.RedisClusterNode;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class LettuceReactiveClusterServerCommandsTests extends LettuceReactiveClusterCommandsTestsBase {
|
||||
|
||||
static final RedisClusterNode NODE1 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_1_PORT);
|
||||
static final RedisClusterNode NODE2 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_2_PORT);
|
||||
static final RedisClusterNode NODE3 = new RedisClusterNode(CLUSTER_HOST, MASTER_NODE_3_PORT);
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void pingShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.ping(NODE1)).expectNext("PONG").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void bgReWriteAofShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().bgReWriteAof(NODE1)).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void bgSaveShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().bgSave(NODE1)).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void lastSaveShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().lastSave(NODE1)).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void saveShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().save(NODE1)).expectNext("OK").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void dbSizeShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE1)).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void flushDbShouldRespondCorrectly() {
|
||||
|
||||
StepVerifier
|
||||
.create(connection.serverCommands().flushDb() //
|
||||
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) //
|
||||
.then(connection.stringCommands().set(KEY_2_BBUFFER, VALUE_2_BBUFFER))) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE1)).expectNext(1L).verifyComplete();
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE3)).expectNext(1L).verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().flushDb(NODE1)).expectNext("OK").verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE1)).expectNext(0L).verifyComplete();
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE3)).expectNext(1L).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void flushAllShouldRespondCorrectly() {
|
||||
|
||||
StepVerifier
|
||||
.create(connection.serverCommands().flushAll() //
|
||||
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER)) //
|
||||
.then(connection.stringCommands().set(KEY_2_BBUFFER, VALUE_2_BBUFFER))) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE1)).expectNext(1L).verifyComplete();
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE3)).expectNext(1L).verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().flushAll(NODE1)).expectNext("OK").verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE1)).expectNext(0L).verifyComplete();
|
||||
StepVerifier.create(connection.serverCommands().dbSize(NODE3)).expectNext(1L).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void infoShouldRespondCorrectly() {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().info(NODE1)) //
|
||||
.consumeNextWith(properties -> assertThat(properties).containsKey("tcp_port")) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void standaloneInfoWithSectionShouldRespondCorrectly() {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().info(NODE1, "server")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsKey("tcp_port").doesNotContainKey("role");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void getConfigShouldRespondCorrectly() {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().getConfig(NODE1, "*")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsEntry("databases", "16");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void setConfigShouldApplyConfiguration() throws InterruptedException {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().setConfig("maxclients", "10000")) //
|
||||
.expectNext("OK") //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().setConfig(NODE1, "maxclients", "9999")) //
|
||||
.expectNext("OK") //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().getConfig(NODE1, "maxclients")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsEntry("maxclients", "9999");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().getConfig(NODE2, "maxclients")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsEntry("maxclients", "10000");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void configResetstatShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().resetConfigStats(NODE1)).expectNext("OK").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void timeShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().time(NODE1)).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void getClientListShouldReportClient() {
|
||||
StepVerifier.create(connection.serverCommands().getClientList(NODE1)).expectNextCount(1).thenCancel().verify();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright 2017 the original author or authors.
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* http://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 org.springframework.data.redis.connection.lettuce;
|
||||
|
||||
import static org.assertj.core.api.Assertions.*;
|
||||
import static org.junit.Assume.*;
|
||||
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Mark Paluch
|
||||
*/
|
||||
public class LettuceReactiveServerCommandsTests extends LettuceReactiveCommandsTestsBase {
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void pingShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.ping()).expectNext("PONG").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void bgReWriteAofShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().bgReWriteAof()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void bgSaveShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().bgSave()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void lastSaveShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().lastSave()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void saveShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().save()).expectNext("OK").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void dbSizeShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().dbSize()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void flushDbShouldRespondCorrectly() {
|
||||
|
||||
StepVerifier
|
||||
.create(connection.serverCommands().flushDb() //
|
||||
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER))) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize()).expectNext(1L).verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().flushDb()).expectNext("OK").verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize()).expectNext(0L).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void flushAllShouldRespondCorrectly() {
|
||||
|
||||
StepVerifier
|
||||
.create(connection.serverCommands().flushAll() //
|
||||
.then(connection.stringCommands().set(KEY_1_BBUFFER, VALUE_1_BBUFFER))) //
|
||||
.expectNextCount(1) //
|
||||
.verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize()).expectNext(1L).verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().flushAll()).expectNext("OK").verifyComplete();
|
||||
|
||||
StepVerifier.create(connection.serverCommands().dbSize()).expectNext(0L).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void infoShouldRespondCorrectly() {
|
||||
|
||||
if (connection instanceof LettuceReactiveRedisClusterConnection) {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().info()) //
|
||||
.consumeNextWith(properties -> {
|
||||
|
||||
assertThat(properties) //
|
||||
.containsKey("127.0.0.1:7379.tcp_port") //
|
||||
.containsKey("127.0.0.1:7380.tcp_port");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
} else {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().info()) //
|
||||
.consumeNextWith(properties -> assertThat(properties).containsKey("tcp_port")) //
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void standaloneInfoWithSectionShouldRespondCorrectly() {
|
||||
|
||||
if (connection instanceof LettuceReactiveRedisClusterConnection) {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().info("server")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).isNotEmpty() //
|
||||
.containsKey("127.0.0.1:7379.tcp_port") //
|
||||
.doesNotContainKey("127.0.0.1:7379.role");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
} else {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().info("server")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsKey("tcp_port").doesNotContainKey("role");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void getConfigShouldRespondCorrectly() {
|
||||
|
||||
if (connection instanceof LettuceReactiveRedisClusterConnection) {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().getConfig("*")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsEntry("127.0.0.1:7379.databases", "16");
|
||||
|
||||
}) //
|
||||
.verifyComplete();
|
||||
} else {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().getConfig("*")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsEntry("databases", "16");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void setConfigShouldApplyConfiguration() {
|
||||
|
||||
StepVerifier.create(connection.serverCommands().setConfig("maxclients", "9999")) //
|
||||
.expectNext("OK") //
|
||||
.verifyComplete();
|
||||
|
||||
if (connection instanceof LettuceReactiveRedisClusterConnection) {
|
||||
StepVerifier.create(connection.serverCommands().getConfig("maxclients")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsEntry("127.0.0.1:7379.maxclients", "9999");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
} else {
|
||||
StepVerifier.create(connection.serverCommands().getConfig("maxclients")) //
|
||||
.consumeNextWith(properties -> {
|
||||
assertThat(properties).containsEntry("maxclients", "9999");
|
||||
}) //
|
||||
.verifyComplete();
|
||||
}
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void configResetstatShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().resetConfigStats()).expectNext("OK").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void timeShouldRespondCorrectly() {
|
||||
StepVerifier.create(connection.serverCommands().time()).expectNextCount(1).verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void setClientNameShouldSetName() {
|
||||
|
||||
// see lettuce-io/lettuce-core#563
|
||||
assumeFalse(connection instanceof LettuceReactiveRedisClusterConnection);
|
||||
|
||||
StepVerifier.create(connection.serverCommands().setClientName("foo")).expectNextCount(1).verifyComplete();
|
||||
StepVerifier.create(connection.serverCommands().getClientName()).expectNext("foo").verifyComplete();
|
||||
}
|
||||
|
||||
@Test // DATAREDIS-659
|
||||
public void getClientListShouldReportClient() {
|
||||
StepVerifier.create(connection.serverCommands().getClientList()).expectNextCount(1).thenCancel().verify();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user