Search in sources :

Example 1 with StargateConnectionInfo

use of io.stargate.it.storage.StargateConnectionInfo in project stargate by stargate.

the class SystemTablesTest method addAndRemovePeers.

@Test
@DisplayName("Should add/remove Stargate addresses from system.peers")
public void addAndRemovePeers(CqlSession session, StargateEnvironmentInfo environmentInfo) throws Exception {
    Node localNode = session.getMetadata().getNodes().values().iterator().next();
    StargateConnectionInfo newNode = environmentInfo.addNode();
    await().atMost(Duration.ofMinutes(5)).pollInterval(Duration.ofSeconds(1)).until(() -> session.getMetadata().getNodes().size() > 2);
    InetAddress newNodeAddress = InetAddress.getByName(newNode.seedAddress());
    Row newNodeRow = queryPeer(session, localNode, newNodeAddress);
    assertThat(newNodeRow).isNotNull();
    assertThat(newNodeRow.getInetAddress("peer")).isEqualTo(newNodeAddress);
    environmentInfo.removeNode(newNode);
    await().atMost(Duration.ofMinutes(5)).pollInterval(Duration.ofSeconds(1)).until(() -> session.getMetadata().getNodes().size() < 3);
    Row removedNodeRow = queryPeer(session, localNode, newNodeAddress);
    assertThat(removedNodeRow).isNull();
}
Also used : StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) Node(com.datastax.oss.driver.api.core.metadata.Node) Row(com.datastax.oss.driver.api.core.cql.Row) InetAddress(java.net.InetAddress) Test(org.junit.jupiter.api.Test) BaseIntegrationTest(io.stargate.it.BaseIntegrationTest) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with StargateConnectionInfo

use of io.stargate.it.storage.StargateConnectionInfo in project stargate by stargate.

the class UdtTest method setup.

@BeforeAll
public static void setup(StargateConnectionInfo cluster, @TestKeyspace CqlIdentifier keyspaceId, CqlSession session) {
    CLIENT = new GraphqlFirstClient(cluster.seedAddress(), RestUtils.getAuthToken(cluster.seedAddress()));
    KEYSPACE = keyspaceId.asInternal();
    CLIENT.deploySchema(KEYSPACE, "type Key @cql_entity(target: UDT) @cql_input {\n" + "  k: Int\n" + "}\n" + "type Value @cql_entity(target: UDT) @cql_input {\n" + "  v: Int\n" + "}\n" + "type Foo @cql_input {\n" + // UDT as partition key
    "  k: Key! @cql_column(partitionKey: true, typeHint: \"frozen<\\\"Key\\\">\")\n" + // UDT as a regular column with index => must be frozen
    "  v: Value @cql_column(typeHint: \"frozen<\\\"Value\\\">\") @cql_index\n" + // List of UDT (the element is implicitly frozen) with index on elements
    "  vs1: [Value] @cql_index\n" + // List of UDT with FULL index => the list must be frozen
    "  vs2: [Value]  @cql_column(typeHint: \"frozen<list<\\\"Value\\\">>\")\n" + "                @cql_index(target: FULL)\n" + "}\n" + "type Query {\n" + "  foo(k: KeyInput!): Foo\n" + "  foosByV(v: ValueInput): [Foo]\n" + "  foosByVs1(\n" + "    v: ValueInput @cql_where(field: \"vs1\" predicate: CONTAINS)\n" + "  ): [Foo]\n" + "  foosByVs2(\n" + "    vs2: [ValueInput]\n" + "  ): [Foo]\n" + "}\n");
    Optional<KeyspaceMetadata> keyspace = session.refreshSchema().getKeyspace(keyspaceId);
    UserDefinedType keyType = keyspace.flatMap(ks -> ks.getUserDefinedType(CqlIdentifier.fromInternal("Key"))).orElseThrow(AssertionError::new);
    UserDefinedType valueType = keyspace.flatMap(ks -> ks.getUserDefinedType(CqlIdentifier.fromInternal("Value"))).orElseThrow(AssertionError::new);
    // Just insert one row. We just want to check that the queries run and things get serialized and
    // deserialized correctly, we're not testing the backend.
    session.execute("INSERT INTO \"Foo\"(k, v, vs1, vs2) VALUES(?, ?, ?, ?)", keyType.newValue(1), valueType.newValue(2), Arrays.asList(valueType.newValue(3)), Arrays.asList(valueType.newValue(4)));
}
Also used : Arrays(java.util.Arrays) CqlIdentifier(com.datastax.oss.driver.api.core.CqlIdentifier) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) JsonPath(com.jayway.jsonpath.JsonPath) TestKeyspace(io.stargate.it.driver.TestKeyspace) RestUtils(io.stargate.it.http.RestUtils) DisplayName(org.junit.jupiter.api.DisplayName) Test(org.junit.jupiter.api.Test) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) 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) Optional(java.util.Optional) AssertionsForClassTypes.assertThat(org.assertj.core.api.AssertionsForClassTypes.assertThat) UserDefinedType(com.datastax.oss.driver.api.core.type.UserDefinedType) KeyspaceMetadata(com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata) BeforeAll(org.junit.jupiter.api.BeforeAll)

Example 3 with StargateConnectionInfo

use of io.stargate.it.storage.StargateConnectionInfo in project stargate by stargate.

the class DefaultContactPointResolver method resolve.

@Override
public List<InetSocketAddress> resolve(ExtensionContext context) {
    StargateEnvironmentInfo stargate = (StargateEnvironmentInfo) context.getStore(ExtensionContext.Namespace.GLOBAL).get(StargateExtension.STORE_KEY);
    if (stargate == null) {
        throw new IllegalStateException(String.format("%s can only be used in conjunction with %s (make sure it is declared last)", CqlSessionExtension.class.getSimpleName(), StargateExtension.class.getSimpleName()));
    }
    List<InetSocketAddress> contactPoints = new ArrayList<>();
    for (StargateConnectionInfo node : stargate.nodes()) {
        contactPoints.add(new InetSocketAddress(node.seedAddress(), node.cqlPort()));
    }
    return contactPoints;
}
Also used : StargateEnvironmentInfo(io.stargate.it.storage.StargateEnvironmentInfo) StargateConnectionInfo(io.stargate.it.storage.StargateConnectionInfo) InetSocketAddress(java.net.InetSocketAddress) ArrayList(java.util.ArrayList)

Aggregations

StargateConnectionInfo (io.stargate.it.storage.StargateConnectionInfo)3 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 CqlSession (com.datastax.oss.driver.api.core.CqlSession)1 Row (com.datastax.oss.driver.api.core.cql.Row)1 Node (com.datastax.oss.driver.api.core.metadata.Node)1 KeyspaceMetadata (com.datastax.oss.driver.api.core.metadata.schema.KeyspaceMetadata)1 UserDefinedType (com.datastax.oss.driver.api.core.type.UserDefinedType)1 JsonPath (com.jayway.jsonpath.JsonPath)1 BaseIntegrationTest (io.stargate.it.BaseIntegrationTest)1 CqlSessionExtension (io.stargate.it.driver.CqlSessionExtension)1 TestKeyspace (io.stargate.it.driver.TestKeyspace)1 RestUtils (io.stargate.it.http.RestUtils)1 StargateEnvironmentInfo (io.stargate.it.storage.StargateEnvironmentInfo)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Optional (java.util.Optional)1