Search in sources :

Example 1 with TestKeyspace

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));
    });
}
Also used : Response(io.stargate.proto.QueryOuterClass.Response) CqlSessionSpec(io.stargate.it.driver.CqlSessionSpec) Arrays(java.util.Arrays) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) HttpStatus(org.apache.http.HttpStatus) RestUtils(io.stargate.it.http.RestUtils) MetricsTestsHelper.getMetricValueOptional(io.stargate.it.MetricsTestsHelper.getMetricValueOptional) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) Query(io.stargate.proto.QueryOuterClass.Query) BeforeAll(org.junit.jupiter.api.BeforeAll) Duration(java.time.Duration) Awaitility.await(org.awaitility.Awaitility.await) StargateBlockingStub(io.stargate.proto.StargateGrpc.StargateBlockingStub) Response(io.stargate.proto.QueryOuterClass.Response) Batch(io.stargate.proto.QueryOuterClass.Batch) TestKeyspace(io.stargate.it.driver.TestKeyspace) Collectors(java.util.stream.Collectors) StatusRuntimeException(io.grpc.StatusRuntimeException) Values(io.stargate.grpc.Values) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) CqlSessionExtension(io.stargate.it.driver.CqlSessionExtension) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) StargateBlockingStub(io.stargate.proto.StargateGrpc.StargateBlockingStub) Test(org.junit.jupiter.api.Test)

Example 2 with TestKeyspace

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));
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) JsonPath(com.jayway.jsonpath.JsonPath) TestKeyspace(io.stargate.it.driver.TestKeyspace) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) RestUtils(io.stargate.it.http.RestUtils) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) List(java.util.List) CqlSessionExtension(io.stargate.it.driver.CqlSessionExtension) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest)

Example 3 with TestKeyspace

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));
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) JsonPath(com.jayway.jsonpath.JsonPath) TestKeyspace(io.stargate.it.driver.TestKeyspace) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) RestUtils(io.stargate.it.http.RestUtils) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) List(java.util.List) CqlSessionExtension(io.stargate.it.driver.CqlSessionExtension) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with TestKeyspace

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));
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) JsonPath(com.jayway.jsonpath.JsonPath) TestKeyspace(io.stargate.it.driver.TestKeyspace) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) RestUtils(io.stargate.it.http.RestUtils) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) List(java.util.List) CqlSessionExtension(io.stargate.it.driver.CqlSessionExtension) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest)

Example 5 with TestKeyspace

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));
}
Also used : TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) TableMetadata(com.datastax.oss.driver.api.core.metadata.schema.TableMetadata) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ClusteringOrder(com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) JsonPath(com.jayway.jsonpath.JsonPath) TestKeyspace(io.stargate.it.driver.TestKeyspace) ColumnMetadata(com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata) RestUtils(io.stargate.it.http.RestUtils) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) DataTypes(com.datastax.oss.driver.api.core.type.DataTypes) List(java.util.List) CqlSessionExtension(io.stargate.it.driver.CqlSessionExtension) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) CqlSession(com.datastax.oss.driver.api.core.CqlSession) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest)

Aggregations

CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)7 CqlSession (com.datastax.oss.driver.api.core.CqlSession)7 CqlSessionExtension (io.stargate.it.driver.CqlSessionExtension)7 TestKeyspace (io.stargate.it.driver.TestKeyspace)7 RestUtils (io.stargate.it.http.RestUtils)7 StargateConnectionInfo (io.stargate.it.storage.StargateConnectionInfo)7 BeforeAll (org.junit.jupiter.api.BeforeAll)7 Test (org.junit.jupiter.api.Test)7 ExtendWith (org.junit.jupiter.api.extension.ExtendWith)7 List (java.util.List)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 JsonPath (com.jayway.jsonpath.JsonPath)5 DisplayName (org.junit.jupiter.api.DisplayName)5 ClusteringOrder (com.datastax.oss.driver.api.core.metadata.schema.ClusteringOrder)4 ColumnMetadata (com.datastax.oss.driver.api.core.metadata.schema.ColumnMetadata)4 TableMetadata (com.datastax.oss.driver.api.core.metadata.schema.TableMetadata)4 DataTypes (com.datastax.oss.driver.api.core.type.DataTypes)4 BaseIntegrationTest (io.stargate.it.BaseIntegrationTest)4 Map (java.util.Map)4 Arrays (java.util.Arrays)3