本文整理了Java中com.datastax.driver.core.Metadata
类的一些代码示例,展示了Metadata
类的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Metadata
类的具体详情如下:
包路径:com.datastax.driver.core.Metadata
类名称:Metadata
[英]Keeps metadata on the connected cluster, including known nodes and schema definitions.
[中]在连接的集群上保留元数据,包括已知节点和架构定义。
代码示例来源:origin: prestodb/presto
private void checkSizeEstimatesTableExist()
{
KeyspaceMetadata keyspaceMetadata = executeWithSession(session -> session.getCluster().getMetadata().getKeyspace(SYSTEM));
checkState(keyspaceMetadata != null, "system keyspace metadata must not be null");
TableMetadata table = keyspaceMetadata.getTable(SIZE_ESTIMATES);
if (table == null) {
throw new PrestoException(NOT_SUPPORTED, "Cassandra versions prior to 2.1.5 are not supported");
}
}
代码示例来源: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
/**
* Quotes a column name to make it case sensitive.
*
* @param columnName the column name to quote.
* @return the quoted column name.
* @see Metadata#quote(String)
*/
public static String quote(String columnName) {
return Metadata.quote(columnName);
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void remainingDeleteTests() throws Exception {
Statement query;
TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable(TABLE_TEXT);
assertNotNull(table);
String expected = String.format("DELETE k FROM %s.test_text;", keyspace);
query = delete("k").from(table);
assertEquals(query.toString(), expected);
try {
session().execute(query);
fail();
} catch (SyntaxError e) {
// Missing WHERE clause
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@SuppressWarnings("RedundantCast")
@Test(groups = "short", dataProvider = "existingKeyspaceName")
@CassandraVersion("2.1.0")
public void should_notify_of_udt_drop(String keyspace) {
session1.execute(String.format("CREATE TYPE %s.type1(i int)", keyspace));
session1.execute(String.format("DROP TYPE %s.type1", keyspace));
for (SchemaChangeListener listener : listeners) {
ArgumentCaptor<UserType> removed = ArgumentCaptor.forClass(UserType.class);
verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onUserTypeRemoved(removed.capture());
assertThat((DataType) removed.getValue()).isUserType(handleId(keyspace), "type1");
}
for (Metadata m : metadatas())
assertThat((DataType) m.getKeyspace(keyspace).getUserType("type1")).isNull();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
@CassandraVersion(value = "3.6", description = "Non-frozen UDTs were introduced in C* 3.6")
public void should_indicate_user_type_is_not_frozen() {
session().execute("CREATE TABLE not_frozen_table(k int primary key, v type_for_frozen_test)");
KeyspaceMetadata keyspaceMetadata = cluster().getMetadata().getKeyspace(this.keyspace);
assertThat(keyspaceMetadata.getUserType("type_for_frozen_test")).isNotFrozen();
DataType userType = keyspaceMetadata.getTable("not_frozen_table").getColumn("v").getType();
assertThat(userType).isNotFrozen();
assertThat(userType.toString()).isEqualTo(keyspace + ".type_for_frozen_test");
ResultSet rs = session().execute("SELECT v FROM not_frozen_table WHERE k = 1");
assertThat(rs.getColumnDefinitions().getType(0)).isNotFrozen();
PreparedStatement pst = session().prepare("SELECT v FROM not_frozen_table WHERE k = ?");
assertThat(pst.getVariables().getType(0)).isNotFrozen();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Ensures that if cluster does not have the system.peers_v2 table that cluster initialization
* still succeeds.
*
* @jira_ticket JAVA-1388
* @since 3.6.0
*/
@Test(groups = "short")
@CCMConfig(createCcm = false)
public void should_connect_when_peers_v2_table_not_present() {
ScassandraCluster sCluster =
ScassandraCluster.builder().withNodes(5).withPeersV2(false).build();
Cluster cluster =
Cluster.builder()
.addContactPointsWithPorts(sCluster.address(1))
.withNettyOptions(nonQuietClusterCloseOptions)
.withPort(sCluster.getBinaryPort())
.build();
try {
sCluster.init();
cluster.connect();
assertThat(cluster.getMetadata().getAllHosts()).hasSize(5);
} finally {
cluster.close();
sCluster.stop();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short", dataProvider = "existingKeyspaceName")
@CassandraVersion("2.2.0")
public void should_notify_of_function_drop(String keyspace) {
session1.execute(
String.format(
"CREATE FUNCTION %s.\"ID\"(i int) RETURNS NULL ON NULL INPUT RETURNS int LANGUAGE java AS 'return i;'",
keyspace));
session1.execute(String.format("DROP FUNCTION %s.\"ID\"", keyspace));
for (SchemaChangeListener listener : listeners) {
ArgumentCaptor<FunctionMetadata> removed = ArgumentCaptor.forClass(FunctionMetadata.class);
verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onFunctionRemoved(removed.capture());
assertThat(removed.getValue()).isInKeyspace(handleId(keyspace)).hasSignature("\"ID\"(int)");
}
for (Metadata m : metadatas())
assertThat(m.getKeyspace(keyspace).getFunction("\"ID\"", DataType.cint())).isNull();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short", dataProvider = "shuffleProvider")
public void should_order_replicas_based_on_configuration(
TokenAwarePolicy.ReplicaOrdering ordering) {
Cluster.builder()
.addContactPoints(sCluster.address(1).getAddress())
.withPort(sCluster.getBinaryPort())
Lists.newArrayList(cluster.getMetadata().getReplicas("keyspace", routingKey));
assertThat(replicas)
.containsExactly(
assertThat(queryPlan).containsOnlyElementsOf(cluster.getMetadata().getAllHosts());
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* Validates that columns using the duration type are properly represented in {@link
* TableMetadata}.
*
* @jira_ticket JAVA-1347
* @test_category metadata
*/
@Test(groups = "short")
public void should_parse_column_metadata() {
// column metadata
TableMetadata table = cluster().getMetadata().getKeyspace(keyspace).getTable("test_duration");
assertThat(table.getColumn("c1")).hasType(DataType.duration());
assertThat(table.asCQLQuery()).contains("c1 duration");
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_expose_token_ranges() throws Exception {
Metadata metadata = cluster().getMetadata();
metadata.getReplicas(
ks1,
TypeCodec.cint()
.serialize(
testKey,
cluster().getConfiguration().getProtocolOptions().getProtocolVersion()));
assertThat(replicas).hasSize(1);
Host replica = replicas.iterator().next();
session().prepare("SELECT i FROM foo WHERE token(i) > ? and token(i) <= ?");
for (TokenRange range : metadata.getTokenRanges()) {
List<Row> rows = rangeQuery(rangeStmt, range);
for (Row row : rows) {
foundRange = range;
assertThat(metadata.getReplicas(ks1, range)).contains(replica);
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_parse_table_with_case_sensitive_column_names_and_reserved_keywords()
throws Exception {
String c1 = Metadata.quote("quotes go \"\" here \"\" ");
String c2 = Metadata.quote("\\x00\\x25");
String c3 = Metadata.quote("columnfamily");
String c4 = Metadata.quote("select");
String c5 = Metadata.quote("who''s there'? ");
String c6 = Metadata.quote("faux )");
String c7 = Metadata.quote("COMPACT STORAGE");
TableMetadata table1 = cluster().getMetadata().getKeyspace(keyspace).getTable("\"MyTable1\"");
TableMetadata table2 = cluster().getMetadata().getKeyspace(keyspace).getTable("\"MyTable2\"");
.hasColumn(c6)
.hasColumn(c7);
assertThat(table1.asCQLQuery()).startsWith(cql1);
assertThat(table2)
.hasColumn(c1)
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void should_parse_user_defined_type_when_definition_in_old_user_types() {
Metadata metadata = cluster().getMetadata();
KeyspaceMetadata keyspaceMetadata = metadata.getKeyspace(this.keyspace);
assertThat(parse("\"A\"", cluster(), keyspace, null, keyspaceMetadata.userTypes, false, false))
.isUserType(keyspace, "A");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short")
public void testCaseSensitiveKeyspace() throws Throwable {
String ksName = "\"MyKeyspace2\"";
session().execute(String.format(CREATE_KEYSPACE_SIMPLE_FORMAT, ksName, 1));
assertExists(ksName, "MyKeyspace2");
assertExists(Metadata.quote("MyKeyspace2"), "MyKeyspace2");
assertNotExists("mykeyspace2");
assertNotExists("MyKeyspace2");
assertNotExists("MYKEYSPACE2");
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short", dataProvider = "existingKeyspaceName")
public void should_notify_of_table_creation(String keyspace) throws InterruptedException {
execute(CREATE_TABLE, keyspace);
for (SchemaChangeListener listener : listeners) {
ArgumentCaptor<TableMetadata> added = ArgumentCaptor.forClass(TableMetadata.class);
verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableAdded(added.capture());
assertThat(added.getValue()).isInKeyspace(handleId(keyspace)).hasName("table1");
}
for (Metadata m : metadatas())
assertThat(m.getKeyspace(keyspace).getTable("table1")).isNotNull();
}
代码示例来源: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());
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/** JAVA-684: Empty TokenRange returned in a one token cluster */
@Test(groups = "short")
public void should_return_single_non_empty_range_when_cluster_has_one_single_token() {
cluster().manager.controlConnection.refreshNodeListAndTokenMap();
Metadata metadata = cluster().getMetadata();
Set<TokenRange> tokenRanges = metadata.getTokenRanges();
assertThat(tokenRanges).hasSize(1);
TokenRange tokenRange = tokenRanges.iterator().next();
assertThat(tokenRange)
.startsWith(Token.M3PToken.FACTORY.minToken())
.endsWith(Token.M3PToken.FACTORY.minToken())
.isNotEmpty()
.isNotWrappedAround();
Set<Host> hostsForRange = metadata.getReplicas(keyspace, tokenRange);
Host host1 = TestUtils.findHost(cluster(), 1);
assertThat(hostsForRange).containsOnly(host1);
ByteBuffer randomPartitionKey = Bytes.fromHexString("0xCAFEBABE");
Set<Host> hostsForKey = metadata.getReplicas(keyspace, randomPartitionKey);
assertThat(hostsForKey).containsOnly(host1);
Set<TokenRange> rangesForHost = metadata.getTokenRanges(keyspace, host1);
assertThat(rangesForHost).containsOnly(tokenRange);
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short", dataProvider = "newKeyspaceName")
public void should_notify_of_keyspace_drop(String keyspace) throws InterruptedException {
execute(CREATE_KEYSPACE, keyspace);
for (SchemaChangeListener listener : listeners) {
ArgumentCaptor<KeyspaceMetadata> added = ArgumentCaptor.forClass(KeyspaceMetadata.class);
verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceAdded(added.capture());
assertThat(added.getValue()).hasName(handleId(keyspace));
}
for (Metadata m : metadatas())
assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isNotEmpty();
execute(CREATE_TABLE, keyspace); // to test table drop notifications
execute(DROP_KEYSPACE, keyspace);
for (SchemaChangeListener listener : listeners) {
ArgumentCaptor<TableMetadata> table = ArgumentCaptor.forClass(TableMetadata.class);
verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onTableRemoved(table.capture());
assertThat(table.getValue()).hasName("table1").isInKeyspace(handleId(keyspace));
ArgumentCaptor<KeyspaceMetadata> ks = ArgumentCaptor.forClass(KeyspaceMetadata.class);
verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceRemoved(ks.capture());
assertThat(ks.getValue()).hasName(handleId(keyspace));
}
for (Metadata m : metadatas()) {
assertThat(m.getKeyspace(keyspace)).isNull();
assertThat(m.getReplicas(keyspace, Bytes.fromHexString("0xCAFEBABE"))).isEmpty();
}
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
@Test(groups = "short", dataProvider = "newKeyspaceName")
public void should_notify_of_keyspace_creation(String keyspace) throws InterruptedException {
execute(CREATE_KEYSPACE, keyspace);
for (SchemaChangeListener listener : listeners) {
ArgumentCaptor<KeyspaceMetadata> added = ArgumentCaptor.forClass(KeyspaceMetadata.class);
verify(listener, timeout(NOTIF_TIMEOUT_MS).times(1)).onKeyspaceAdded(added.capture());
assertThat(added.getValue()).hasName(handleId(keyspace));
}
for (Metadata m : metadatas()) assertThat(m.getKeyspace(keyspace)).isNotNull();
}
代码示例来源:origin: com.datastax.cassandra/cassandra-driver-core
/**
* @test_category queries:builder
* @jira_ticket JAVA-1286
* @jira_ticket CASSANDRA-7423
*/
@Test(groups = "unit")
public void should_handle_retrieving_udt_fields() throws Exception {
assertThat(select().path("a", Metadata.quote("B")).raw("c.\"D\"").from("tbl").getQueryString())
.isEqualTo("SELECT a.\"B\",c.\"D\" FROM tbl;");
}
内容来源于网络,如有侵权,请联系作者删除!