Tabnine Logo
Host
Code IndexAdd Tabnine to your IDE (free)

How to use
Host
in
com.datastax.driver.core

Best Java code snippets using com.datastax.driver.core.Host (Showing top 20 results out of 540)

Refine searchRefine arrow

  • Cluster
  • Cluster.Builder
  • Metadata
  • Assertions
  • Test
origin: Netflix/conductor

  @Override
  public Cluster get() {
    String host = configuration.getHostAddress();
    int port = configuration.getPort();

    LOGGER.info("Connecting to cassandra cluster with host:{}, port:{}", host, port);

    Cluster cluster = Cluster.builder()
        .addContactPoint(host)
        .withPort(port)
        .build();

    Metadata metadata = cluster.getMetadata();
    LOGGER.info("Connected to cluster: {}", metadata.getClusterName());
    metadata.getAllHosts().forEach(h -> {
      LOGGER.info("Datacenter:{}, host:{}, rack: {}", h.getDatacenter(), h.getAddress(), h.getRack());
    });
    return cluster;
  }
}
origin: com.datastax.cassandra/cassandra-driver-core

boolean supports(ProtocolVersion version) {
 return getCassandraVersion() == null
   || version.minCassandraVersion().compareTo(getCassandraVersion().nextStable()) <= 0;
}
origin: com.datastax.cassandra/cassandra-driver-core

 @Override
 public void onFailure(Throwable t) {
  if (t instanceof BusyPoolException) {
   logError(host.getSocketAddress(), t);
  } else {
   logger.error("Unexpected error while querying " + host.getAddress(), t);
   logError(host.getSocketAddress(), t);
  }
  findNextHostAndQuery();
 }
});
origin: apache/storm

/**
 * {@inheritDoc}
 */
@Override
public synchronized Session connect() throws NoHostAvailableException {
  if (isDisconnected()) {
    LOG.info("Connected to cluster: {}", cluster.getClusterName());
    for (Host host : getAllHosts())
      LOG.info("Datacenter: {}; Host: {}; Rack: {}", host.getDatacenter(), host.getAddress(), host.getRack());
    LOG.info("Connect to cluster using keyspace %s", keyspace);
    session = cluster.connect(keyspace);
  } else {
    LOG.warn("{} - Already connected to cluster: {}", getExecutorName(), cluster.getClusterName());
  }
  if (session.isClosed()) {
    LOG.warn("Session has been closed - create new one!");
    this.session = cluster.newSession();
  }
  return session;
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_throw_proper_unavailable_exception() {
 simulateError(1, unavailable);
 try {
  query();
  fail("expected an UnavailableException");
 } catch (UnavailableException e) {
  assertThat(e.getMessage())
    .isEqualTo(
      "Not enough replicas available for query at consistency LOCAL_ONE (1 required but only 0 alive)");
  assertThat(e.getConsistencyLevel()).isEqualTo(LOCAL_ONE);
  assertThat(e.getAliveReplicas()).isEqualTo(0);
  assertThat(e.getRequiredReplicas()).isEqualTo(1);
  assertThat(e.getAddress()).isEqualTo(host1.getSocketAddress());
  assertThat(e.getHost()).isEqualTo(host1.getAddress());
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

 @Test(groups = "short", dataProvider = "connectionErrors")
 public void should_rethrow_on_connection_error(CloseType closeType) {
  simulateError(1, Result.closed_connection, new ClosedConnectionConfig(closeType));
  try {
   query();
   Fail.fail("expected a TransportException");
  } catch (TransportException e) {
   assertThat(e.getMessage())
     .isEqualTo(String.format("[%s] Connection has been closed", host1.getSocketAddress()));
  }
  assertOnRequestErrorWasCalled(1, TransportException.class);
  assertThat(errors.getRetries().getCount()).isEqualTo(0);
  assertThat(errors.getConnectionErrors().getCount()).isEqualTo(1);
  assertThat(errors.getIgnoresOnConnectionError().getCount()).isEqualTo(0);
  assertThat(errors.getRetriesOnConnectionError().getCount()).isEqualTo(0);
  assertQueried(1, 1);
  assertQueried(2, 0);
  assertQueried(3, 0);
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "unit")
public void should_ignore_DCs_in_black_list() {
 when(host1.getDatacenter()).thenReturn("dc1");
 when(host2.getDatacenter()).thenReturn("dc2");
 when(host3.getDatacenter()).thenReturn(null);
 HostFilterPolicy policy =
   HostFilterPolicy.fromDCBlackList(wrappedPolicy, Lists.newArrayList("dc2"));
 assertThat(policy.distance(host1)).isSameAs(HostDistance.LOCAL);
 assertThat(policy.distance(host2)).isSameAs(HostDistance.IGNORED);
 assertThat(policy.distance(host3)).isSameAs(HostDistance.LOCAL);
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_rethrow_unavailable_in_no_host_available_exception() {
 LoadBalancingPolicy firstHostOnlyPolicy =
   new WhiteListPolicy(
     Policies.defaultLoadBalancingPolicy(),
     Collections.singletonList(host1.getSocketAddress()));
   Cluster.builder()
     .addContactPoints(scassandras.address(1).getAddress())
     .withPort(scassandras.getBinaryPort())
     .withRetryPolicy(retryPolicy)
     .withLoadBalancingPolicy(firstHostOnlyPolicy)
     .build();
  Session whiteListedSession = whiteListedCluster.connect();
   fail("expected an NoHostAvailableException");
  } catch (NoHostAvailableException e) {
   Throwable error = e.getErrors().get(host1.getSocketAddress());
   assertThat(error).isNotNull();
   assertThat(error).isInstanceOf(UnavailableException.class);
  Metrics.Errors whiteListErrors = whiteListedCluster.getMetrics().getErrorMetrics();
  assertThat(whiteListErrors.getRetriesOnUnavailable().getCount()).isEqualTo(1);
  assertQueried(1, 1);
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_init_cluster_and_session_if_needed() throws Exception {
 // For this test we need an uninitialized cluster, so we can't reuse the one provided by the
 // parent class. Rebuild a new one with the same (unique) host.
 Host host = cluster().getMetadata().allHosts().iterator().next();
 Cluster cluster2 =
   register(
     Cluster.builder()
       .addContactPointsWithPorts(Lists.newArrayList(host.getSocketAddress()))
       .build());
 try {
  Session session2 = cluster2.newSession();
  // Neither cluster2 nor session2 are initialized at this point
  assertThat(cluster2.manager.metadata).isNull();
  ResultSetFuture future = session2.executeAsync("select release_version from system.local");
  Row row = Uninterruptibles.getUninterruptibly(future).one();
  assertThat(row.getString(0)).isNotEmpty();
 } finally {
  cluster2.close();
 }
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_connect_with_credentials() {
 PlainTextAuthProvider authProvider = spy(new PlainTextAuthProvider("cassandra", "cassandra"));
 Cluster cluster =
   Cluster.builder()
     .addContactPoints(getContactPoints())
     .withPort(ccm().getBinaryPort())
     .withAuthProvider(authProvider)
     .build();
 cluster.connect();
 verify(authProvider, atLeastOnce())
   .newAuthenticator(
     findHost(cluster, 1).getSocketAddress(),
     "org.apache.cassandra.auth.PasswordAuthenticator");
 assertThat(cluster.getMetrics().getErrorMetrics().getAuthenticationErrors().getCount())
   .isEqualTo(0);
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
@CCMConfig(createCcm = false)
public void should_randomize_contact_points_when_determining_control_connection() {
  for (int i = 0; i < iterations; i++) {
   Cluster cluster =
     Cluster.builder()
       .addContactPoints(contactPoints)
       .withPort(scassandras.getBinaryPort())
       .withNettyOptions(nonQuietClusterCloseOptions)
       .build();
    cluster.init();
    occurrencesByHost.add(cluster.manager.controlConnection.connectedHost().getAddress());
   } finally {
    cluster.close();
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_log_ignored_request_error() throws InterruptedException {
 simulateError(1, server_error);
 retryDecision = ignore();
 query();
 String line = appender.waitAndGet(5000);
 assertThat(line.trim())
   .isEqualTo(
     expectedMessage(
       IGNORING_REQUEST_ERROR,
       defaultCL,
       0,
       new ServerError(host1.getSocketAddress(), "Server Error").toString()));
}
origin: com.datastax.cassandra/cassandra-driver-core

public HostAssert isUp() {
 assertThat(actual.isUp()).isTrue();
 return this;
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_use_local_dc_from_contact_points_when_not_explicitly_specified() {
 Cluster cluster =
   builder()
     .addContactPoints(sCluster.address(1, 1).getAddress())
     .withPort(sCluster.getBinaryPort())
     .withLoadBalancingPolicy(policy)
     .build();
  cluster.init();
  assertThat(initHostsCaptor.getValue()).containsExactly(host1);
  assertThat(policy.localDc).isEqualTo(host1.getDatacenter());
  cluster.close();
  sCluster.stop();
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short", dataProviderClass = DataProviders.class, dataProvider = "bool")
@CCMConfig(createCcm = false)
public void should_use_port_from_peers_v2_table(boolean sharedIP) {
   Cluster.builder()
     .addContactPointsWithPorts(sCluster.address(1))
     .withNettyOptions(nonQuietClusterCloseOptions);
  builder.withPort(sCluster.getBinaryPort());
  cluster.connect();
  assertThat(cluster.getMetadata().getAllHosts()).hasSize(5);
    assertThat(host).hasNoListenSocketAddress();
   uniqueAddresses.add(host.getAddress());
   uniqueSocketAddresses.add(host.getSocketAddress());
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
@CCMConfig(createCcm = false)
public void should_fetch_whole_peers_table_if_broadcast_address_changed()
  cluster.init();
  Host host2 = cluster.getMetadata().getHost(node2RpcAddress);
  assertThat(host2).isNotNull();
  InetSocketAddress node2OldBroadcastAddress = host2.getBroadcastSocketAddress();
  InetSocketAddress node2NewBroadcastAddress =
    new InetSocketAddress(InetAddress.getByName("1.2.3.4"), scassandras.getBinaryPort());
  assertThat(host2.getSocketAddress().getAddress())
    .isEqualTo(node2OldBroadcastAddress.getAddress());
      .put(
        "peer", node2NewBroadcastAddress.getAddress()) // new broadcast address for host 2
      .put("rpc_address", host2.getAddress()) // rpc_broadcast_address remains unchanged
      .put("host_id", UUID.randomUUID())
      .put("data_center", datacenter(1))
  host2 = cluster.getMetadata().getHost(node2RpcAddress);
  assertThat(host2.getBroadcastSocketAddress().getAddress())
    .isEqualTo(node2NewBroadcastAddress.getAddress());
  assertThat(host2.getSocketAddress()).isEqualTo(node2RpcAddress);
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
public void should_parse_table_options() {
 VersionNumber version = TestUtils.findHost(cluster(), 1).getCassandraVersion();
 TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("with_options");
  assertThat(table.getOptions().getBloomFilterFalsePositiveChance()).isEqualTo(0.01);
  assertThat(table.getOptions().getComment()).isEqualTo("My awesome table");
  assertThat(table.getOptions().getCaching()).contains(entry("keys", "ALL"));
  assertThat(table.getOptions().getCaching()).contains(entry("rows_per_partition", "10"));
  assertThat(table.getOptions().getCompaction())
    .contains(entry("class", "org.apache.cassandra.db.compaction.LeveledCompactionStrategy"));
  assertThat(table.getOptions().getCompaction()).contains(entry("sstable_size_in_mb", "15"));
  assertThat(table.getOptions().getCompression())
origin: com.datastax.cassandra/cassandra-driver-core

public HostAssert isInDatacenter(String datacenter) {
 assertThat(actual.getDatacenter()).isEqualTo(datacenter);
 return this;
}
origin: com.datastax.cassandra/cassandra-driver-core

public ClusterAssert usesControlHost(int node) {
 String expectedAddress = TestUtils.ipOfNode(node);
 Host controlHost = actual.manager.controlConnection.connectedHost();
 assertThat(controlHost.getAddress().getHostAddress()).isEqualTo(expectedAddress);
 return this;
}
origin: com.datastax.cassandra/cassandra-driver-core

@Test(groups = "short")
@CCMConfig(numberOfNodes = 2, clusterProvider = "updatablePolicy")
public void refreshTest() throws Throwable {
 // Ugly
 Host[] hosts = new Host[2];
 for (Host h : cluster().getMetadata().getAllHosts()) {
  if (h.getAddress().equals(ccm().addressOfNode(1).getAddress())) hosts[0] = h;
  else hosts[1] = h;
 }
 assertTrue(
   session().getState().getConnectedHosts().contains(hosts[0]),
   "Connected hosts: " + session().getState().getConnectedHosts());
 assertTrue(
   !session().getState().getConnectedHosts().contains(hosts[1]),
   "Connected hosts: " + session().getState().getConnectedHosts());
 policy.changeTheHost(hosts[1]);
 assertTrue(
   !session().getState().getConnectedHosts().contains(hosts[0]),
   "Connected hosts: " + session().getState().getConnectedHosts());
 assertTrue(
   session().getState().getConnectedHosts().contains(hosts[1]),
   "Connected hosts: " + session().getState().getConnectedHosts());
}
com.datastax.driver.coreHost

Javadoc

A Cassandra node.

This class keeps the information the driver maintain on a given Cassandra node.

Most used methods

  • getAddress
    Returns the address that the driver will use to connect to the node. This is a shortcut for getSocke
  • getDatacenter
    Returns the name of the datacenter this host is part of. The returned datacenter name is the one as
  • getRack
    Returns the name of the rack this host is part of. The returned rack name is the one as known by Cas
  • getCassandraVersion
    The Cassandra version the host is running. It is also possible for this information to be unavailabl
  • isUp
    Returns whether the host is considered up by the driver. Please note that this is only the view of t
  • getSocketAddress
    Returns the address and port that the driver will use to connect to the node. This is the node's br
  • toString
  • equals
  • <init>
  • getBroadcastAddress
    Returns the node broadcast address (that is, the IP by which it should be contacted by other peers i
  • setDown
  • setLocationInfo
  • setDown,
  • setLocationInfo,
  • setUp,
  • wasJustAdded,
  • setDseGraphEnabled,
  • setDseVersion,
  • setDseWorkload,
  • setTokens,
  • setVersion,
  • getBroadcastSocketAddress

Popular in Java

  • Making http requests using okhttp
  • setContentView (Activity)
  • setRequestProperty (URLConnection)
  • notifyDataSetChanged (ArrayAdapter)
  • Proxy (java.net)
    This class represents proxy server settings. A created instance of Proxy stores a type and an addres
  • DecimalFormat (java.text)
    A concrete subclass of NumberFormat that formats decimal numbers. It has a variety of features desig
  • HashSet (java.util)
    HashSet is an implementation of a Set. All optional operations (adding and removing) are supported.
  • StringTokenizer (java.util)
    Breaks a string into tokens; new code should probably use String#split.> // Legacy code: StringTo
  • TimerTask (java.util)
    The TimerTask class represents a task to run at a specified time. The task may be run once or repeat
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now