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();
}
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)));
}
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;
}
Aggregations