private CCMCluster(CCMBridge cassandraCluster, Cluster.Builder builder, int totalNodes) { this.cassandraCluster = cassandraCluster; try { String[] contactPoints = new String[totalNodes]; for (int i = 0; i < totalNodes; i++) contactPoints[i] = IP_PREFIX + (i + 1); try { Thread.sleep(1000); } catch (InterruptedException e) { Assert.fail("Unexpected interruption"); } this.cluster = builder.addContactPoints(contactPoints).build(); this.session = cluster.connect(); } catch (NoHostAvailableException e) { for (Map.Entry<InetSocketAddress, Throwable> entry : e.getErrors().entrySet()) logger.info("Error connecting to " + entry.getKey() + ": " + entry.getValue()); discard(); throw new RuntimeException(e); } }
/** @see <a href="https://jira.spring.io/browse/DATACASS-317">DATACASS-317</a> */ @Test public void shouldSetClusterNameWithClusterNameProperty() throws Exception { final Cluster.Builder mockClusterBuilder = mock(Cluster.Builder.class); when(mockClusterBuilder.addContactPoints(Matchers.<String[]>anyVararg())) .thenReturn(mockClusterBuilder); CassandraCqlClusterFactoryBean bean = new CassandraCqlClusterFactoryBean() { @Override Cluster.Builder newClusterBuilder() { return mockClusterBuilder; } }; bean.setBeanName("ABC"); bean.setClusterName("XYZ"); bean.afterPropertiesSet(); verify(mockClusterBuilder, times(1)).withClusterName(eq("XYZ")); }