use of org.apache.cassandra.transport.messages.QueryMessage in project cassandra by apache.
the class MessagePayloadTest method testMessagePayloadVersion3.
@Test
public void testMessagePayloadVersion3() throws Throwable {
QueryHandler queryHandler = (QueryHandler) cqlQueryHandlerField.get(null);
cqlQueryHandlerField.set(null, new TestQueryHandler());
try {
requireNetwork();
Assert.assertSame(TestQueryHandler.class, ClientState.getCQLQueryHandler().getClass());
SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V3);
try {
client.connect(false);
Map<String, ByteBuffer> reqMap;
QueryMessage queryMessage = new QueryMessage("CREATE TABLE " + KEYSPACE + ".atable (pk int PRIMARY KEY, v text)", QueryOptions.DEFAULT);
PrepareMessage prepareMessage = new PrepareMessage("SELECT * FROM " + KEYSPACE + ".atable");
reqMap = Collections.singletonMap("foo", bytes(42));
responsePayload = Collections.singletonMap("bar", bytes(42));
queryMessage.setCustomPayload(reqMap);
try {
client.execute(queryMessage);
Assert.fail();
} catch (RuntimeException e) {
Assert.assertTrue(e.getCause() instanceof ProtocolException);
}
queryMessage.setCustomPayload(null);
client.execute(queryMessage);
reqMap = Collections.singletonMap("foo", bytes(43));
responsePayload = Collections.singletonMap("bar", bytes(43));
prepareMessage.setCustomPayload(reqMap);
try {
client.execute(prepareMessage);
Assert.fail();
} catch (RuntimeException e) {
Assert.assertTrue(e.getCause() instanceof ProtocolException);
}
prepareMessage.setCustomPayload(null);
ResultMessage.Prepared prepareResponse = (ResultMessage.Prepared) client.execute(prepareMessage);
ExecuteMessage executeMessage = new ExecuteMessage(prepareResponse.statementId, QueryOptions.DEFAULT);
reqMap = Collections.singletonMap("foo", bytes(44));
responsePayload = Collections.singletonMap("bar", bytes(44));
executeMessage.setCustomPayload(reqMap);
try {
client.execute(executeMessage);
Assert.fail();
} catch (RuntimeException e) {
Assert.assertTrue(e.getCause() instanceof ProtocolException);
}
BatchMessage batchMessage = new BatchMessage(BatchStatement.Type.UNLOGGED, Collections.<Object>singletonList("INSERT INTO " + KEYSPACE + ".atable (pk,v) VALUES (1, 'foo')"), Collections.singletonList(Collections.<ByteBuffer>emptyList()), QueryOptions.DEFAULT);
reqMap = Collections.singletonMap("foo", bytes(45));
responsePayload = Collections.singletonMap("bar", bytes(45));
batchMessage.setCustomPayload(reqMap);
try {
client.execute(batchMessage);
Assert.fail();
} catch (RuntimeException e) {
Assert.assertTrue(e.getCause() instanceof ProtocolException);
}
} finally {
client.close();
}
} finally {
cqlQueryHandlerField.set(null, queryHandler);
}
}
Aggregations