use of com.datastax.oss.protocol.internal.request.Prepare in project java-driver by datastax.
the class CqlPrepareHandler method sendRequest.
private void sendRequest(PrepareRequest request, Node node, int retryCount) {
if (result.isDone()) {
return;
}
DriverChannel channel = null;
if (node == null || (channel = session.getChannel(node, logPrefix)) == null) {
while (!result.isDone() && (node = queryPlan.poll()) != null) {
channel = session.getChannel(node, logPrefix);
if (channel != null) {
break;
} else {
recordError(node, new NodeUnavailableException(node));
}
}
}
if (channel == null) {
setFinalError(AllNodesFailedException.fromErrors(this.errors));
} else {
InitialPrepareCallback initialPrepareCallback = new InitialPrepareCallback(request, node, channel, retryCount);
Prepare message = toPrepareMessage(request);
channel.write(message, false, request.getCustomPayload(), initialPrepareCallback).addListener(initialPrepareCallback);
}
}
use of com.datastax.oss.protocol.internal.request.Prepare in project java-driver by datastax.
the class ReprepareOnUpTest method should_reprepare_all_if_system_table_empty.
@Test
public void should_reprepare_all_if_system_table_empty() {
MockReprepareOnUp reprepareOnUp = new MockReprepareOnUp("test", pool, ImmediateEventExecutor.INSTANCE, getMockPayloads('a', 'b', 'c', 'd', 'e', 'f'), context, whenPrepared);
reprepareOnUp.start();
MockAdminQuery adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Query.class);
assertThat(((Query) adminQuery.request).query).isEqualTo("SELECT prepared_id FROM system.prepared_statements");
// server knows no ids:
adminQuery.resultFuture.complete(new AdminResult(preparedIdRows(), null, DefaultProtocolVersion.DEFAULT));
for (char c = 'a'; c <= 'f'; c++) {
adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Prepare.class);
assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
adminQuery.resultFuture.complete(null);
}
assertThatStage(done).isSuccess(v -> assertThat(reprepareOnUp.queries).isEmpty());
}
use of com.datastax.oss.protocol.internal.request.Prepare in project java-driver by datastax.
the class ReprepareOnUpTest method should_limit_number_of_statements_reprepared_in_parallel.
@Test
public void should_limit_number_of_statements_reprepared_in_parallel() {
when(defaultProfile.getInt(DefaultDriverOption.REPREPARE_MAX_PARALLELISM)).thenReturn(3);
MockReprepareOnUp reprepareOnUp = new MockReprepareOnUp("test", pool, ImmediateEventExecutor.INSTANCE, getMockPayloads('a', 'b', 'c', 'd', 'e', 'f'), context, whenPrepared);
reprepareOnUp.start();
MockAdminQuery adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Query.class);
assertThat(((Query) adminQuery.request).query).isEqualTo("SELECT prepared_id FROM system.prepared_statements");
// server knows no ids => will reprepare all 6:
adminQuery.resultFuture.complete(new AdminResult(preparedIdRows(), null, DefaultProtocolVersion.DEFAULT));
// 3 statements have enqueued, we've not completed the queries yet so no more should be sent:
assertThat(reprepareOnUp.queries.size()).isEqualTo(3);
// As we complete each statement, another one should enqueue:
for (char c = 'a'; c <= 'c'; c++) {
adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Prepare.class);
assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
adminQuery.resultFuture.complete(null);
assertThat(reprepareOnUp.queries.size()).isEqualTo(3);
}
// Complete the last 3:
for (char c = 'd'; c <= 'f'; c++) {
adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Prepare.class);
assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
adminQuery.resultFuture.complete(null);
}
assertThatStage(done).isSuccess(v -> assertThat(reprepareOnUp.queries).isEmpty());
}
use of com.datastax.oss.protocol.internal.request.Prepare in project java-driver by datastax.
the class CqlPrepareHandler method toPrepareMessage.
@NonNull
private Prepare toPrepareMessage(PrepareRequest request) {
ProtocolVersion protocolVersion = context.getProtocolVersion();
ProtocolVersionRegistry registry = context.getProtocolVersionRegistry();
CqlIdentifier keyspace = request.getKeyspace();
if (keyspace != null && !registry.supports(protocolVersion, DefaultProtocolFeature.PER_REQUEST_KEYSPACE)) {
throw new IllegalArgumentException("Can't use per-request keyspace with protocol " + protocolVersion);
}
return new Prepare(request.getQuery(), (keyspace == null) ? null : keyspace.asInternal());
}
use of com.datastax.oss.protocol.internal.request.Prepare in project java-driver by datastax.
the class ReprepareOnUpTest method should_limit_number_of_statements_to_reprepare.
@Test
public void should_limit_number_of_statements_to_reprepare() {
when(defaultProfile.getInt(DefaultDriverOption.REPREPARE_MAX_STATEMENTS)).thenReturn(3);
MockReprepareOnUp reprepareOnUp = new MockReprepareOnUp("test", pool, ImmediateEventExecutor.INSTANCE, getMockPayloads('a', 'b', 'c', 'd', 'e', 'f'), context, whenPrepared);
reprepareOnUp.start();
MockAdminQuery adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Query.class);
assertThat(((Query) adminQuery.request).query).isEqualTo("SELECT prepared_id FROM system.prepared_statements");
// server knows no ids:
adminQuery.resultFuture.complete(new AdminResult(preparedIdRows(), null, DefaultProtocolVersion.DEFAULT));
for (char c = 'a'; c <= 'c'; c++) {
adminQuery = reprepareOnUp.queries.poll();
assertThat(adminQuery).isNotNull();
assertThat(adminQuery.request).isInstanceOf(Prepare.class);
assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
adminQuery.resultFuture.complete(null);
}
assertThatStage(done).isSuccess(v -> assertThat(reprepareOnUp.queries).isEmpty());
}
Aggregations