use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class BoundStatementSimulacronIT method should_use_consistencies_from_simple_statement.
@Test
public void should_use_consistencies_from_simple_statement() {
try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
PreparedStatement prepared = session.prepare(st);
SIMULACRON_RULE.cluster().clearLogs();
// since query is unprimed, we use a text value for bind parameter as this is
// what simulacron expects for unprimed statements.
session.execute(prepared.bind("0"));
List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
assertThat(logs).hasSize(1);
QueryLog log = logs.get(0);
Message message = log.getFrame().message;
assertThat(message).isInstanceOf(Execute.class);
Execute execute = (Execute) message;
assertThat(execute.options.consistency).isEqualTo(DefaultConsistencyLevel.TWO.getProtocolCode());
assertThat(execute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.LOCAL_SERIAL.getProtocolCode());
}
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class BoundStatementSimulacronIT method should_use_consistencies.
@Test
public void should_use_consistencies() {
try (CqlSession session = SessionUtils.newSession(SIMULACRON_RULE)) {
// set consistencies on simple statement, but they will be unused since
// overridden by bound statement.
SimpleStatement st = SimpleStatement.builder("SELECT * FROM test where k = ?").setConsistencyLevel(DefaultConsistencyLevel.TWO).setSerialConsistencyLevel(DefaultConsistencyLevel.LOCAL_SERIAL).build();
PreparedStatement prepared = session.prepare(st);
SIMULACRON_RULE.cluster().clearLogs();
// since query is unprimed, we use a text value for bind parameter as this is
// what simulacron expects for unprimed statements.
session.execute(prepared.boundStatementBuilder("0").setConsistencyLevel(DefaultConsistencyLevel.THREE).setSerialConsistencyLevel(DefaultConsistencyLevel.SERIAL).build());
List<QueryLog> logs = SIMULACRON_RULE.cluster().getLogs().getQueryLogs();
assertThat(logs).hasSize(1);
QueryLog log = logs.get(0);
Message message = log.getFrame().message;
assertThat(message).isInstanceOf(Execute.class);
Execute execute = (Execute) message;
assertThat(execute.options.consistency).isEqualTo(DefaultConsistencyLevel.THREE.getProtocolCode());
assertThat(execute.options.serialConsistency).isEqualTo(DefaultConsistencyLevel.SERIAL.getProtocolCode());
}
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class CqlRequestHandler method sendRequest.
/**
* Sends the request to the next available node.
*
* @param statement The statement to execute.
* @param retriedNode if not null, it will be attempted first before the rest of the query plan.
* @param queryPlan the list of nodes to try (shared with all other executions)
* @param currentExecutionIndex 0 for the initial execution, 1 for the first speculative one, etc.
* @param retryCount the number of times that the retry policy was invoked for this execution
* already (note that some internal retries don't go through the policy, and therefore don't
* increment this counter)
* @param scheduleNextExecution whether to schedule the next speculative execution
*/
private void sendRequest(Statement<?> statement, Node retriedNode, Queue<Node> queryPlan, int currentExecutionIndex, int retryCount, boolean scheduleNextExecution) {
if (result.isDone()) {
return;
}
Node node = retriedNode;
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) {
// We've reached the end of the query plan without finding any node to write to
if (!result.isDone() && activeExecutionsCount.decrementAndGet() == 0) {
// We're the last execution so fail the result
setFinalError(statement, AllNodesFailedException.fromErrors(this.errors), null, -1);
}
} else {
NodeResponseCallback nodeResponseCallback = new NodeResponseCallback(statement, node, queryPlan, channel, currentExecutionIndex, retryCount, scheduleNextExecution, logPrefix);
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(statement, context);
Message message = Conversions.toMessage(statement, executionProfile, context);
channel.write(message, statement.isTracing(), statement.getCustomPayload(), nodeResponseCallback).addListener(nodeResponseCallback);
}
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class AdminRequestHandler method onResponse.
@Override
public void onResponse(Frame responseFrame) {
if (timeoutFuture != null) {
timeoutFuture.cancel(true);
}
Message message = responseFrame.message;
LOG.debug("[{}] Got response {}", logPrefix, responseFrame.message);
if (!expectedResponseType.isInstance(message)) {
// Note that this also covers error responses, no need to get too fancy here
setFinalError(new UnexpectedResponseException(debugString, message));
} else if (expectedResponseType == Rows.class) {
Rows rows = (Rows) message;
ByteBuffer pagingState = rows.getMetadata().pagingState;
AdminRequestHandler nextHandler = (pagingState == null) ? null : this.copy(pagingState);
// The public factory methods guarantee that expectedResponseType and ResultT always match:
@SuppressWarnings("unchecked") ResultT result = (ResultT) new AdminResult(rows, nextHandler, channel.protocolVersion());
setFinalResult(result);
} else if (expectedResponseType == Prepared.class) {
Prepared prepared = (Prepared) message;
@SuppressWarnings("unchecked") ResultT result = (ResultT) ByteBuffer.wrap(prepared.preparedQueryId);
setFinalResult(result);
} else if (expectedResponseType == com.datastax.oss.protocol.internal.response.result.Void.class) {
setFinalResult(null);
} else {
setFinalError(new AssertionError("Unhandled response type" + expectedResponseType));
}
}
use of com.datastax.oss.protocol.internal.Message in project java-driver by datastax.
the class GraphRequestHandlerTest method should_create_query_message_from_batch_statement.
@Test
@UseDataProvider(location = DseTestDataProviders.class, value = "supportedGraphProtocols")
public void should_create_query_message_from_batch_statement(GraphProtocol graphProtocol) throws IOException {
// initialization
GraphRequestHandlerTestHarness harness = GraphRequestHandlerTestHarness.builder().build();
@SuppressWarnings("rawtypes") List<GraphTraversal> traversalsTest = ImmutableList.of(// GraphDataTypesTest
DseGraph.g.addV("person").property("p1", 2.3f).property("p2", LocalDateTime.now(ZoneOffset.UTC)), DseGraph.g.addV("software").property("p3", new BigInteger("123456789123456789123456789123456789")).property("p4", ImmutableList.of(Point.fromCoordinates(30.4, 25.63746284))));
GraphStatement<?> graphStatement = BatchGraphStatement.builder().addTraversals(traversalsTest).build();
GraphBinaryModule module = createGraphBinaryModule(harness.getContext());
// when
DriverExecutionProfile executionProfile = Conversions.resolveExecutionProfile(graphStatement, harness.getContext());
Message m = GraphConversions.createMessageFromGraphStatement(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
Map<String, ByteBuffer> createdCustomPayload = GraphConversions.createCustomPayload(graphStatement, graphProtocol, executionProfile, harness.getContext(), module);
// checks
assertThat(m).isInstanceOf(RawBytesQuery.class);
testQueryRequestAndPayloadContents(((RawBytesQuery) m), createdCustomPayload, GraphConversions.bytecodeToSerialize(graphStatement), graphProtocol, module);
}
Aggregations