Exemple #1
0
  @Test
  public void testGetKeySpaceConsistencyLevel() throws HectorException {
    Keyspace k =
        client.getKeyspace(
            "Keyspace1", ConsistencyLevel.ALL, CassandraClient.DEFAULT_FAILOVER_POLICY);
    assertNotNull(k);
    assertEquals(ConsistencyLevel.ALL, k.getConsistencyLevel());

    k =
        client.getKeyspace(
            "Keyspace1", ConsistencyLevel.ZERO, CassandraClient.DEFAULT_FAILOVER_POLICY);
    assertNotNull(k);
    assertEquals(ConsistencyLevel.ZERO, k.getConsistencyLevel());
  }
Exemple #2
0
  @Test
  public void testGetKeySpaceString() throws HectorException {
    Keyspace k = client.getKeyspace("Keyspace1");
    assertNotNull(k);
    assertEquals(CassandraClient.DEFAULT_CONSISTENCY_LEVEL, k.getConsistencyLevel());

    // negative path
    try {
      k = client.getKeyspace("KeyspaceDoesntExist");
      fail("Should have thrown an exception IllegalArgumentException");
    } catch (IllegalArgumentException e) {
      // good
    }
  }
Exemple #3
0
 @Test
 public void testFramedTransport() throws HectorException {
   CassandraHost cassandraHost = new CassandraHost("localhost", 9170);
   cassandraHost.setUseThriftFramedTransport(true);
   client = new CassandraClientFactory(pools, cassandraHost, monitor).create();
   assertTrue(client.getCassandra().getInputProtocol().getTransport() instanceof TFramedTransport);
 }
Exemple #4
0
 @Test
 public void testGetKeyspaces() throws HectorException {
   List<String> spaces = client.getKeyspaces();
   assertNotNull(spaces);
   // There should be two spaces: Keyspace1 and system
   assertEquals(2, spaces.size());
   assertTrue("Keyspace1".equals(spaces.get(0)) || "Keyspace1".equals(spaces.get(1)));
 }
Exemple #5
0
 @Test
 public void testGetKeySpaceFailoverPolicy() throws HectorException {
   Keyspace k =
       client.getKeyspace(
           "Keyspace1", CassandraClient.DEFAULT_CONSISTENCY_LEVEL, FailoverPolicy.FAIL_FAST);
   assertNotNull(k);
   assertEquals(FailoverPolicy.FAIL_FAST, k.getFailoverPolicy());
 }
 @Override
 public Set<String> getHostNames() throws TTransportException, TException {
   Set<String> hostnames = new HashSet<String>();
   for (String keyspace : describeKeyspaces()) {
     if (!keyspace.equals("system")) {
       List<TokenRange> tokenRanges = cassandraClient.getCassandra().describe_ring(keyspace);
       for (TokenRange tokenRange : tokenRanges) {
         for (String host : tokenRange.getEndpoints()) {
           hostnames.add(host);
         }
       }
       break;
     }
   }
   return hostnames;
 }
 @Override
 public List<TokenRange> describeRing(Keyspace keyspace) throws TTransportException, TException {
   return cassandraClient.getCassandra().describe_ring(keyspace.getName());
 }
 @Override
 public String describeVersion() throws TTransportException, TException {
   return cassandraClient.getCassandra().describe_version();
 }
 @Override
 public String describeClusterName() throws TTransportException, TException {
   return cassandraClient.getCassandra().describe_cluster_name();
 }
 @Override
 public Set<String> describeKeyspaces() throws TTransportException, TException {
   return cassandraClient.getCassandra().describe_keyspaces();
 }
Exemple #11
0
 @Test
 public void testGetTokenMap() throws HectorException {
   List<String> hosts = client.getKnownHosts(false);
   assertNotNull(hosts);
   assertEquals("127.0.0.1", hosts.get(0));
 }
Exemple #12
0
 @Test
 public void testGetClusterName() throws HectorException {
   String name = client.getClusterName();
   assertEquals("Test Cluster", name);
 }