Example usage for org.springframework.data.redis.connection RedisStaticMasterReplicaConfiguration RedisStaticMasterReplicaConfiguration

List of usage examples for org.springframework.data.redis.connection RedisStaticMasterReplicaConfiguration RedisStaticMasterReplicaConfiguration

Introduction

In this page you can find the example usage for org.springframework.data.redis.connection RedisStaticMasterReplicaConfiguration RedisStaticMasterReplicaConfiguration.

Prototype

public RedisStaticMasterReplicaConfiguration(String hostName, int port) 

Source Link

Document

Create a new StaticMasterReplicaConfiguration given hostName and port .

Usage

From source file:org.springframework.data.redis.connection.lettuce.LettuceConnectionFactoryTests.java

@Test // DATAREDIS-762, DATAREDIS-869
public void factoryUsesElastiCacheMasterWithoutMaster() {

    assumeThat(//from  ww  w .  j a  v  a2 s  .com
            String.format("No replicas connected to %s:%s.", SettingsUtils.getHost(), SettingsUtils.getPort()),
            connection.info("replication").getProperty("connected_slaves", "0").compareTo("0") > 0, is(true));

    LettuceClientConfiguration configuration = LettuceTestClientConfiguration.builder()
            .readFrom(ReadFrom.MASTER).build();

    RedisStaticMasterReplicaConfiguration elastiCache = new RedisStaticMasterReplicaConfiguration(
            SettingsUtils.getHost(), SettingsUtils.getPort() + 1);

    LettuceConnectionFactory factory = new LettuceConnectionFactory(elastiCache, configuration);
    factory.afterPropertiesSet();

    RedisConnection connection = factory.getConnection();

    try {
        connection.ping();
        fail("Expected RedisException: Master is currently unknown");
    } catch (RedisSystemException e) {

        assertThat(e.getCause(), is(instanceOf(RedisException.class)));
        assertThat(e.getCause().getMessage(), containsString("Master is currently unknown"));
    } finally {
        connection.close();
    }

    factory.destroy();
}