@Test public void testDescribeKeyspaces() throws Exception { List<KeyspaceDefinition> keyspaces = cassandraCluster.describeKeyspaces(); // System // Keyspace1 // system_traces assertEquals(3,keyspaces.size()); }
@Before public void setup() { cassandraHostConfigurator = new CassandraHostConfigurator("localhost"); connectionManager = Mockito.mock(HConnectionManager.class); cluster = Mockito.mock(ThriftCluster.class); Mockito.when(cluster.getConfigurator()).thenReturn(cassandraHostConfigurator); final KeyspaceDefinition kdef = Mockito.mock(KeyspaceDefinition.class); Mockito.when(kdef.getName()).thenReturn("TestKeyspace"); Mockito.when(cluster.describeKeyspaces()).thenReturn(new LinkedList<KeyspaceDefinition>() {{ add(kdef); }}); }
private Set<CassandraHost> buildRingInfo() { ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(connectionManager.getClusterName()); // ThriftCluster is not exclusively created & cached by HFactory. E.g. Some users instantiate directly via Spring. if(cluster != null) { Set<CassandraHost> ringInfo = new HashSet<CassandraHost>(); for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName()); for (TokenRange tokenRange : tokenRanges) { for (String host : tokenRange.getRpc_endpoints()) { CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort()); if (!ringInfo.contains(aHost) ) { ringInfo.add(aHost); } } } break; } } return ringInfo; } else { return null; } } }
@Test public void testDescribeKeyspaces() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1Credentials); List<KeyspaceDefinition> keyspaces = cassandraCluster.describeKeyspaces(); assertEquals(2,keyspaces.size()); }
@Test public void testDescribeKeyspacesBadAuth() throws Exception { ThriftCluster cassandraCluster = new ThriftCluster("Test Cluster", cassandraHostConfigurator, user1CredentialsBad); try { cassandraCluster.describeKeyspaces(); fail("Should have gotten a wrapped AuthenticationException"); } catch (HectorException he) { assertTrue(he.getCause() instanceof AuthenticationException); } }
private Set<CassandraHost> buildRingInfo() { ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(connectionManager.getClusterName()); // ThriftCluster is not exclusively created & cached by HFactory. E.g. Some users instantiate directly via Spring. if(cluster != null) { Set<CassandraHost> ringInfo = new HashSet<CassandraHost>(); for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName()); for (TokenRange tokenRange : tokenRanges) { for (String host : tokenRange.getRpc_endpoints()) { CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort()); if (!ringInfo.contains(aHost) ) { ringInfo.add(aHost); } } } break; } } return ringInfo; } else { return null; } } }
private Set<CassandraHost> buildRingInfo() { ThriftCluster cluster = (ThriftCluster) HFactory.getCluster(connectionManager.getClusterName()); // ThriftCluster is not exclusively created & cached by HFactory. E.g. Some users instantiate directly via Spring. if(cluster != null) { Set<CassandraHost> ringInfo = new HashSet<CassandraHost>(); for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName()); for (TokenRange tokenRange : tokenRanges) { for (String host : tokenRange.getEndpoints()) { CassandraHost aHost = new CassandraHost(host, cassandraHostConfigurator.getPort()); if (!ringInfo.contains(aHost) ) { ringInfo.add(aHost); } } } break; } } return ringInfo; } else { return null; } } }
for(KeyspaceDefinition keyspaceDefinition: cluster.describeKeyspaces()) { if (!keyspaceDefinition.getName().equals(Keyspace.KEYSPACE_SYSTEM)) { List<TokenRange> tokenRanges = cluster.describeRing(keyspaceDefinition.getName());