use of io.stargate.it.driver.TestKeyspace in project stargate by stargate.
the class AuthApiServerMetricsTest method queryMetrics.
@Test
public void queryMetrics(@TestKeyspace CqlIdentifier keyspace) {
StargateBlockingStub stub = stubWithCallCredentials();
Response response = stub.executeQuery(cqlQuery("INSERT INTO test (k, v) VALUES ('a', 1)", queryParameters(keyspace)));
assertThat(response).isNotNull();
response = stub.executeQuery(cqlQuery("SELECT * FROM test", queryParameters(keyspace)));
assertThat(response.hasResultSet()).isTrue();
await().atMost(Duration.ofSeconds(5)).untilAsserted(() -> {
String result = RestUtils.get("", String.format("%s:8084/metrics", host), HttpStatus.SC_OK);
List<String> lines = Arrays.stream(result.split(System.getProperty("line.separator"))).filter(line -> line.startsWith("grpc_server")).collect(Collectors.toList());
assertThat(lines).anySatisfy(metric -> assertThat(metric).contains("grpc_server_processing_duration_seconds_count").contains("method=\"ExecuteQuery\"").contains("methodType=\"UNARY\"").contains("service=\"stargate.Stargate\"").contains("statusCode=\"OK\"")).anySatisfy(metric -> assertThat(metric).contains("grpc_server_processing_duration_seconds_sum").contains("method=\"ExecuteQuery\"").contains("methodType=\"UNARY\"").contains("service=\"stargate.Stargate\"").contains("statusCode=\"OK\"")).anySatisfy(metric -> assertThat(metric).contains("grpc_server_processing_duration_seconds_max").contains("method=\"ExecuteQuery\"").contains("methodType=\"UNARY\"").contains("service=\"stargate.Stargate\"").contains("statusCode=\"OK\""));
String responsesTotal = "grpc_server_responses_sent_messages_total{method=\"ExecuteQuery\",methodType=\"UNARY\",service=\"stargate.Stargate\",}";
String requestsTotal = "grpc_server_requests_received_messages_total{method=\"ExecuteQuery\",methodType=\"UNARY\",service=\"stargate.Stargate\",}";
assertThat(getGrpcMetric(result, responsesTotal)).hasValueSatisfying(v -> assertThat(v).isGreaterThan(0d));
assertThat(getGrpcMetric(result, requestsTotal)).hasValueSatisfying(v -> assertThat(v).isGreaterThan(0d));
});
}
use of io.stargate.it.driver.TestKeyspace in project stargate by stargate.
the class TableDdlTest method alterTableDrop.
@Test
public void alterTableDrop(CqlSession session, @TestKeyspace CqlIdentifier keyspaceId) {
String tableName = "tbl_altertabledrop_" + System.currentTimeMillis();
CLIENT.executeDdlQuery(String.format("mutation {\n" + " createTable(\n" + " keyspaceName: \"%s\"\n" + " tableName: \"%s\"\n" + " partitionKeys: [ {name: \"id\", type: { basic: UUID} } ]\n" + " values: [ {name: \"name\", type: { basic: TEXT} } ]\n" + " )\n" + "}", keyspaceId.asInternal(), tableName));
Map<String, Object> response = CLIENT.executeDdlQuery(String.format("mutation {\n" + " alterTableDrop(\n" + " keyspaceName: \"%s\"\n" + " tableName: \"%s\"\n" + " toDrop: [ \"name\" ]\n" + " )\n" + "}", keyspaceId.asInternal(), tableName));
assertThat(JsonPath.<Boolean>read(response, "$.alterTableDrop")).isTrue();
TableMetadata table = session.refreshSchema().getKeyspace(keyspaceId).flatMap(ks -> ks.getTable(tableName)).orElseThrow(AssertionError::new);
assertThat(table.getColumn("name")).isEmpty();
session.execute(String.format("DROP TABLE %s", tableName));
}
use of io.stargate.it.driver.TestKeyspace in project stargate by stargate.
the class TableDdlTest method createTableWithClusteringKey.
@Test
@DisplayName("Should create table with clustering keys")
public void createTableWithClusteringKey(CqlSession session, @TestKeyspace CqlIdentifier keyspaceId) {
String tableName = "tbl_createtable_with_ck_" + System.currentTimeMillis();
Map<String, Object> response = CLIENT.executeDdlQuery(String.format("mutation {\n" + " createTable(\n" + " keyspaceName: \"%s\"\n" + " tableName: \"%s\"\n" + " partitionKeys: [ {name: \"pk1\", type: { basic: INT} } ]\n" + " clusteringKeys: [\n" + " {name: \"ck1\", type: { basic: TIMEUUID} },\n" + " {name: \"ck2\", type: { basic: BIGINT}, order: \"DESC\" }\n" + " ]\n" + " values: [ {name: \"value1\", type: { basic: TEXT} } ]\n" + " )\n" + "}", keyspaceId.asInternal(), tableName));
assertThat(JsonPath.<Boolean>read(response, "$.createTable")).isTrue();
TableMetadata table = session.refreshSchema().getKeyspace(keyspaceId).flatMap(ks -> ks.getTable(tableName)).orElseThrow(AssertionError::new);
assertThat(table.getPartitionKey()).extracting(ColumnMetadata::getName).containsExactly(CqlIdentifier.fromInternal("pk1"));
assertThat(table.getClusteringColumns().keySet()).extracting(ColumnMetadata::getName).containsExactly(CqlIdentifier.fromInternal("ck1"), CqlIdentifier.fromInternal("ck2"));
assertThat(table.getClusteringColumns().values()).containsExactly(ClusteringOrder.ASC, ClusteringOrder.DESC);
session.execute(String.format("DROP TABLE %s", tableName));
}
use of io.stargate.it.driver.TestKeyspace in project stargate by stargate.
the class TableDdlTest method createTable.
@Test
public void createTable(CqlSession session, @TestKeyspace CqlIdentifier keyspaceId) {
String tableName = "tbl_createtable_" + System.currentTimeMillis();
Map<String, Object> response = CLIENT.executeDdlQuery(String.format("mutation {\n" + " createTable(\n" + " keyspaceName: \"%s\"\n" + " tableName: \"%s\"\n" + " partitionKeys: [ {name: \"id\", type: { basic: UUID} } ]\n" + " values: [\n" + " {name: \"lastname\", type: { basic: TEXT} },\n" + " {name: \"firstname\", type: { basic: TEXT} }\n" + " ]\n" + " )\n" + "}", keyspaceId.asInternal(), tableName));
assertThat(JsonPath.<Boolean>read(response, "$.createTable")).isTrue();
TableMetadata table = session.refreshSchema().getKeyspace(keyspaceId).flatMap(ks -> ks.getTable(tableName)).orElseThrow(AssertionError::new);
assertThat(table.getPartitionKey()).extracting(ColumnMetadata::getName).containsExactly(CqlIdentifier.fromInternal("id"));
assertThat(table.getColumn("id")).map(ColumnMetadata::getType).contains(DataTypes.UUID);
assertThat(table.getColumn("lastname")).map(ColumnMetadata::getType).contains(DataTypes.TEXT);
assertThat(table.getColumn("firstname")).map(ColumnMetadata::getType).contains(DataTypes.TEXT);
session.execute(String.format("DROP TABLE %s", tableName));
}
use of io.stargate.it.driver.TestKeyspace in project stargate by stargate.
the class TableDdlTest method alterTableAdd.
@Test
public void alterTableAdd(CqlSession session, @TestKeyspace CqlIdentifier keyspaceId) {
String tableName = "tbl_altertableadd_" + System.currentTimeMillis();
CLIENT.executeDdlQuery(String.format("mutation {\n" + " createTable(\n" + " keyspaceName: \"%s\"\n" + " tableName: \"%s\"\n" + " partitionKeys: [ {name: \"id\", type: { basic: UUID} } ]\n" + " )\n" + "}", keyspaceId.asInternal(), tableName));
Map<String, Object> response = CLIENT.executeDdlQuery(String.format("mutation {\n" + " alterTableAdd(\n" + " keyspaceName: \"%s\"\n" + " tableName: \"%s\"\n" + " toAdd: [ {name: \"name\", type: { basic: TEXT} } ]\n" + " )\n" + "}", keyspaceId.asInternal(), tableName));
assertThat(JsonPath.<Boolean>read(response, "$.alterTableAdd")).isTrue();
TableMetadata table = session.refreshSchema().getKeyspace(keyspaceId).flatMap(ks -> ks.getTable(tableName)).orElseThrow(AssertionError::new);
assertThat(table.getColumn("name")).hasValueSatisfying(c -> assertThat(c.getType()).isEqualTo(DataTypes.TEXT));
session.execute(String.format("DROP TABLE %s", tableName));
}
Aggregations