use of com.datastax.driver.core.Host in project javaee7-samples by javaee-samples.
the class PersonSessionBean method initDB.
@PostConstruct
private void initDB() {
cluster = Cluster.builder().addContactPoint("localhost").build();
Metadata metadata = cluster.getMetadata();
System.out.printf("Connected to cluster: %s\n", metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
System.out.printf("Datacenter: %s; Host: %s; Rack: %s\n", host.getDatacenter(), host.getAddress(), host.getRack());
}
session = cluster.connect();
session.execute("CREATE KEYSPACE IF NOT EXISTS test WITH replication " + "= {'class':'SimpleStrategy', 'replication_factor':1};");
session.execute("CREATE TABLE IF NOT EXISTS test.person (" + "name text PRIMARY KEY," + "age int" + ");");
selectAllPersons = session.prepare("SELECT * FROM test.person");
insertPerson = session.prepare("INSERT INTO test.person (name, age) VALUES (?, ?);");
}
use of com.datastax.driver.core.Host in project zipkin by openzipkin.
the class SessionFactoryTest method loadBalancing_defaultsToRoundRobin.
@Test
public void loadBalancing_defaultsToRoundRobin() {
RoundRobinPolicy policy = toRoundRobinPolicy(Cassandra3Storage.builder().build());
Host foo = mock(Host.class);
when(foo.getDatacenter()).thenReturn("foo");
Host bar = mock(Host.class);
when(bar.getDatacenter()).thenReturn("bar");
policy.init(mock(Cluster.class), asList(foo, bar));
assertThat(policy.distance(foo)).isEqualTo(HostDistance.LOCAL);
assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL);
}
use of com.datastax.driver.core.Host in project GNS by MobilityFirst.
the class CassandraRecords method connect.
private void connect(String node) {
cluster = Cluster.builder().addContactPoint(node).build();
Metadata metadata = cluster.getMetadata();
DatabaseConfig.getLogger().log(Level.INFO, "Connected to cluster: {0}", metadata.getClusterName());
for (Host host : metadata.getAllHosts()) {
DatabaseConfig.getLogger().log(Level.INFO, "Datacenter: {0} Host: {1} Rack: {2}", new Object[] { host.getDatacenter(), host.getAddress(), host.getRack() });
}
session = cluster.connect();
}
use of com.datastax.driver.core.Host in project zipkin by openzipkin.
the class SessionFactoryTest method loadBalancing_defaultsToRoundRobin.
@Test
public void loadBalancing_defaultsToRoundRobin() {
RoundRobinPolicy policy = toRoundRobinPolicy(CassandraStorage.builder().build());
Host foo = mock(Host.class);
when(foo.getDatacenter()).thenReturn("foo");
Host bar = mock(Host.class);
when(bar.getDatacenter()).thenReturn("bar");
policy.init(mock(Cluster.class), asList(foo, bar));
assertThat(policy.distance(foo)).isEqualTo(HostDistance.LOCAL);
assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL);
}
use of com.datastax.driver.core.Host in project zipkin by openzipkin.
the class SessionFactoryTest method loadBalancing_settingLocalDcIgnoresOtherDatacenters.
@Test
public void loadBalancing_settingLocalDcIgnoresOtherDatacenters() {
DCAwareRoundRobinPolicy policy = toDCAwareRoundRobinPolicy(CassandraStorage.builder().localDc("bar").build());
Host foo = mock(Host.class);
when(foo.getDatacenter()).thenReturn("foo");
Host bar = mock(Host.class);
when(bar.getDatacenter()).thenReturn("bar");
policy.init(mock(Cluster.class), asList(foo, bar));
assertThat(policy.distance(foo)).isEqualTo(HostDistance.IGNORED);
assertThat(policy.distance(bar)).isEqualTo(HostDistance.LOCAL);
}
Aggregations