Search in sources :

Example 1 with PubSubMessageHandler

use of io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler in project lettuce-core by lettuce-io.

the class SentinelTopologyRefreshUnitTests method shouldProcessSlaveDown.

@Test
void shouldProcessSlaveDown() {
    PubSubMessageHandler adapter = getMessageHandler();
    sut.bind(refreshRunnable);
    adapter.handle("*", "+sdown", "replica 127.0.0.1:6483 127.0.0.1 6483-2020 @ mymaster 127.0.0.1 6482");
    verify(eventExecutors, times(1)).schedule(captor.capture(), anyLong(), any());
    captor.getValue().run();
    verify(refreshRunnable, times(1)).run();
}
Also used : PubSubMessageHandler(io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler) Test(org.junit.jupiter.api.Test)

Example 2 with PubSubMessageHandler

use of io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler in project lettuce-core by lettuce-io.

the class SentinelTopologyRefreshUnitTests method shouldProcessSwitchMaster.

@Test
void shouldProcessSwitchMaster() {
    PubSubMessageHandler adapter = getMessageHandler();
    sut.bind(refreshRunnable);
    adapter.handle("*", "+switch-master", "mymaster 127.0.0.1");
    verify(eventExecutors, times(1)).schedule(captor.capture(), anyLong(), any());
    captor.getValue().run();
    verify(refreshRunnable, times(1)).run();
}
Also used : PubSubMessageHandler(io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler) Test(org.junit.jupiter.api.Test)

Example 3 with PubSubMessageHandler

use of io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler in project lettuce-core by lettuce-io.

the class SentinelTopologyRefreshUnitTests method shouldProcessConvertToSlave.

@Test
void shouldProcessConvertToSlave() {
    PubSubMessageHandler adapter = getMessageHandler();
    sut.bind(refreshRunnable);
    adapter.handle("*", "+convert-to-slave", "@ mymaster 127.0.0.1");
    verify(eventExecutors, times(1)).schedule(captor.capture(), anyLong(), any());
    captor.getValue().run();
    verify(refreshRunnable, times(1)).run();
}
Also used : PubSubMessageHandler(io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler) Test(org.junit.jupiter.api.Test)

Example 4 with PubSubMessageHandler

use of io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler in project lettuce-core by lettuce-io.

the class SentinelTopologyRefreshUnitTests method shouldNotProcessIfExecutorIsShuttingDown.

@Test
void shouldNotProcessIfExecutorIsShuttingDown() {
    PubSubMessageHandler adapter = getMessageHandler();
    sut.bind(refreshRunnable);
    when(eventExecutors.isShuttingDown()).thenReturn(true);
    adapter.handle("*", "failover-end-for-timeout", "");
    verify(redisClient).connectPubSubAsync(any(), any());
    verify(eventExecutors, never()).schedule(any(Runnable.class), anyLong(), any());
}
Also used : PubSubMessageHandler(io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler) Test(org.junit.jupiter.api.Test)

Example 5 with PubSubMessageHandler

use of io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler in project lettuce-core by lettuce-io.

the class SentinelTopologyRefreshUnitTests method bindWithSentinelRecovery.

@Test
void bindWithSentinelRecovery() {
    StatefulRedisPubSubConnection<String, String> connection2 = mock(StatefulRedisPubSubConnection.class);
    RedisPubSubAsyncCommands<String, String> async2 = mock(RedisPubSubAsyncCommands.class);
    when(connection2.async()).thenReturn(async2);
    AsyncCommand<String, String, Void> command = new AsyncCommand<>(new Command<>(CommandType.PSUBSCRIBE, null));
    command.complete();
    when(async2.psubscribe(anyString())).thenReturn(command);
    sut = new SentinelTopologyRefresh(redisClient, "mymaster", Arrays.asList(host1, host2));
    when(redisClient.connectPubSubAsync(any(StringCodec.class), eq(host2))).thenReturn(ConnectionFuture.from(null, Futures.failed(new RedisConnectionException("err")))).thenReturn(ConnectionFuture.completed(null, connection2));
    sut.bind(refreshRunnable);
    verify(redisClient).connectPubSubAsync(any(), eq(host1));
    verify(redisClient).connectPubSubAsync(any(), eq(host2));
    Map<RedisURI, StatefulRedisPubSubConnection<String, String>> connections = (Map) ReflectionTestUtils.getField(sut, "pubSubConnections");
    PubSubMessageHandler adapter = getMessageHandler();
    adapter.handle("*", "+sentinel", "sentinel c14cc895bb0479c91312cee0e0440b7d99ad367b 127.0.0.1 26380 @ mymaster 127.0.0.1 6483");
    verify(eventExecutors, times(1)).schedule(captor.capture(), anyLong(), any());
    captor.getValue().run();
    verify(redisClient, times(2)).connectPubSubAsync(any(), eq(host2));
    assertThat(connections).containsKey(host1).containsKey(host2).hasSize(2);
    verify(refreshRunnable, never()).run();
}
Also used : RedisURI(io.lettuce.core.RedisURI) AsyncCommand(io.lettuce.core.protocol.AsyncCommand) PubSubMessageHandler(io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler) Mockito.anyString(org.mockito.Mockito.anyString) RedisConnectionException(io.lettuce.core.RedisConnectionException) Map(java.util.Map) StatefulRedisPubSubConnection(io.lettuce.core.pubsub.StatefulRedisPubSubConnection) Test(org.junit.jupiter.api.Test)

Aggregations

PubSubMessageHandler (io.lettuce.core.masterreplica.SentinelTopologyRefresh.PubSubMessageHandler)14 Test (org.junit.jupiter.api.Test)14 RedisConnectionException (io.lettuce.core.RedisConnectionException)1 RedisURI (io.lettuce.core.RedisURI)1 AsyncCommand (io.lettuce.core.protocol.AsyncCommand)1 StatefulRedisPubSubConnection (io.lettuce.core.pubsub.StatefulRedisPubSubConnection)1 Map (java.util.Map)1 Mockito.anyString (org.mockito.Mockito.anyString)1