/** * If CassandraHost was not null we use {@link CassandraHost#getCassandraThriftSocketTimeout()} * if it was greater than zero. Otherwise look for an environment * variable name CASSANDRA_THRIFT_SOCKET_TIMEOUT value. * If doesn't exist, returns 0. * @param cassandraHost */ private int getTimeout(CassandraHost cassandraHost) { int timeoutVar = 0; if ( cassandraHost != null && cassandraHost.getCassandraThriftSocketTimeout() > 0 ) { timeoutVar = cassandraHost.getCassandraThriftSocketTimeout(); } else { String timeoutStr = System.getProperty( SystemProperties.CASSANDRA_THRIFT_SOCKET_TIMEOUT.toString()); if (timeoutStr != null && timeoutStr.length() > 0) { try { timeoutVar = Integer.parseInt(timeoutStr); } catch (NumberFormatException e) { log.error("Invalid value for CASSANDRA_THRIFT_SOCKET_TIMEOUT", e); } } } return timeoutVar; }
@Test public void testConfigValuesPropogated() { CassandraHostConfigurator cassandraHostConfigurator = new CassandraHostConfigurator("localhost:9170,localhost:9171,localhost:9172"); cassandraHostConfigurator.setMaxActive(20); cassandraHostConfigurator.setCassandraThriftSocketTimeout(3000); cassandraHostConfigurator.setMaxWaitTimeWhenExhausted(4000); cassandraHostConfigurator.setMaxExhaustedTimeBeforeMarkingAsDown(5000); CassandraHost[] cassandraHosts = cassandraHostConfigurator.buildCassandraHosts(); // no need to test all, just a smattering assertEquals(20, cassandraHosts[1].getMaxActive()); assertEquals(20, cassandraHosts[0].getMaxActive()); assertEquals(4000, cassandraHosts[1].getMaxWaitTimeWhenExhausted()); assertEquals(5000, cassandraHosts[0].getMaxExhaustedTimeBeforeMarkingAsDown()); assertEquals(3000, cassandraHosts[2].getCassandraThriftSocketTimeout()); assertEquals(3000, cassandraHosts[0].getCassandraThriftSocketTimeout()); }
/** * If CassandraHost was not null we use {@link CassandraHost#getCassandraThriftSocketTimeout()} * if it was greater than zero. Otherwise look for an environment * variable name CASSANDRA_THRIFT_SOCKET_TIMEOUT value. * If doesn't exist, returns 0. * @param cassandraHost */ private int getTimeout(CassandraHost cassandraHost) { int timeoutVar = 0; if ( cassandraHost != null && cassandraHost.getCassandraThriftSocketTimeout() > 0 ) { timeoutVar = cassandraHost.getCassandraThriftSocketTimeout(); } else { String timeoutStr = System.getProperty( SystemProperties.CASSANDRA_THRIFT_SOCKET_TIMEOUT.toString()); if (timeoutStr != null && timeoutStr.length() > 0) { try { timeoutVar = Integer.parseInt(timeoutStr); } catch (NumberFormatException e) { log.error("Invalid value for CASSANDRA_THRIFT_SOCKET_TIMEOUT", e); } } } return timeoutVar; }
/** * If CassandraHost was not null we use {@link CassandraHost#getCassandraThriftSocketTimeout()} * if it was greater than zero. Otherwise look for an environment * variable name CASSANDRA_THRIFT_SOCKET_TIMEOUT value. * If doesn't exist, returns 0. * @param cassandraHost */ private int getTimeout(CassandraHost cassandraHost) { int timeoutVar = 0; if ( cassandraHost != null && cassandraHost.getCassandraThriftSocketTimeout() > 0 ) { timeoutVar = cassandraHost.getCassandraThriftSocketTimeout(); } else { String timeoutStr = System.getProperty( SystemProperties.CASSANDRA_THRIFT_SOCKET_TIMEOUT.toString()); if (timeoutStr != null && timeoutStr.length() > 0) { try { timeoutVar = Integer.parseInt(timeoutStr); } catch (NumberFormatException e) { log.error("Invalid value for CASSANDRA_THRIFT_SOCKET_TIMEOUT", e); } } } return timeoutVar; }