2013-07-30 2 views
0

내 Java-Spring 기반 웹 응용 프로그램에서 Hector and Spring을 사용하여 Cassandra DB에 연결하고 있습니다.Test Hector Spring Cassandra connection

연결이 제대로 작동하지만 연결을 테스트 할 수 있기를 바랍니다.

ERROR connection.HConnectionManager: Could not start connection pool for host <myhost:myport> 

물론 괜찮 :

그래서 내가 의도적으로 CassandraHostConfigurator에 잘못된 호스트를 제공하는 경우 오류가 발생합니다. 하지만이 연결을 어떻게 테스트 할 수 있습니까?

스프링 컨텍스트가 아닌 실제 연결을 정의하면 스프링 컨텍스트를 통해 테스트하는 방법이 명확하지 않습니다.

아이디어를 생각해 볼 수 있습니까?

답변

0

내가 생각해도 나는 실용적으로 내 연결을 정의하기로 결정 만족스러운 답을 찾아 간단한 쿼리를 사용하지 않을 수 있기 때문에 :

private ColumnFamilyResult<String, String> readFromDb(Keyspace keyspace) { 
ColumnFamilyTemplate<String, String> template = new ThriftColumnFamilyTemplate<String, String>(keyspace, tableName, StringSerializer.get(), 
    StringSerializer.get()); 
// It doesn't matter if the column actually exists or not since we only check the 
// connection. In case of connection failure an exception is thrown, 
// else something comes back. 
return template.queryColumns("some_column"); 
} 

그리고 내 시험 검사를하는 null이 아닌에 반환 된 객체. 잘 작동

또 다른 방법 :

public boolean isConnected() { 
List<KeyspaceDefinition> keyspaces = null; 
try { 
    keyspaces = cluster.describeKeyspaces(); 
} catch (HectorException e) { 
    return false; 
} 
return (!CollectionUtils.isEmpty(keyspaces)); 
} 
관련 문제