Example usage for org.springframework.data.redis RedisSystemException getCause

List of usage examples for org.springframework.data.redis RedisSystemException getCause

Introduction

In this page you can find the example usage for org.springframework.data.redis RedisSystemException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

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

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

    assumeThat(/*  w w w  .ja v a 2s  . c om*/
            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();
}