Search in sources :

Example 1 with QueryMessage

use of org.apache.cassandra.transport.messages.QueryMessage in project cassandra by apache.

the class ClientWarningsTest method testLargeBatchWithProtoV4.

@Test
public void testLargeBatchWithProtoV4() throws Exception {
    createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)");
    try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) {
        client.connect(false);
        QueryMessage query = new QueryMessage(createBatchStatement2(DatabaseDescriptor.getBatchSizeWarnThreshold() / 2 + 1), QueryOptions.DEFAULT);
        Message.Response resp = client.execute(query);
        assertEquals(1, resp.getWarnings().size());
        query = new QueryMessage(createBatchStatement(DatabaseDescriptor.getBatchSizeWarnThreshold()), QueryOptions.DEFAULT);
        resp = client.execute(query);
        assertNull(resp.getWarnings());
    }
}
Also used : QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) Message(org.apache.cassandra.transport.Message) SimpleClient(org.apache.cassandra.transport.SimpleClient) Test(org.junit.Test)

Example 2 with QueryMessage

use of org.apache.cassandra.transport.messages.QueryMessage in project cassandra by apache.

the class ClientWarningsTest method testLargeBatchWithProtoV2.

@Test
public void testLargeBatchWithProtoV2() throws Exception {
    createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)");
    try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V3)) {
        client.connect(false);
        QueryMessage query = new QueryMessage(createBatchStatement(DatabaseDescriptor.getBatchSizeWarnThreshold()), QueryOptions.DEFAULT);
        Message.Response resp = client.execute(query);
        assertNull(resp.getWarnings());
    }
}
Also used : QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) Message(org.apache.cassandra.transport.Message) SimpleClient(org.apache.cassandra.transport.SimpleClient) Test(org.junit.Test)

Example 3 with QueryMessage

use of org.apache.cassandra.transport.messages.QueryMessage in project cassandra by apache.

the class MessagePayloadTest method testMessagePayload.

@Test
public void testMessagePayload() 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);
        try {
            client.connect(false);
            Map<String, ByteBuffer> reqMap;
            Map<String, ByteBuffer> respMap;
            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 = respMap = Collections.singletonMap("bar", bytes(42));
            queryMessage.setCustomPayload(reqMap);
            Message.Response queryResponse = client.execute(queryMessage);
            payloadEquals(reqMap, requestPayload);
            payloadEquals(respMap, queryResponse.getCustomPayload());
            reqMap = Collections.singletonMap("foo", bytes(43));
            responsePayload = respMap = Collections.singletonMap("bar", bytes(43));
            prepareMessage.setCustomPayload(reqMap);
            ResultMessage.Prepared prepareResponse = (ResultMessage.Prepared) client.execute(prepareMessage);
            payloadEquals(reqMap, requestPayload);
            payloadEquals(respMap, prepareResponse.getCustomPayload());
            ExecuteMessage executeMessage = new ExecuteMessage(prepareResponse.statementId, QueryOptions.DEFAULT);
            reqMap = Collections.singletonMap("foo", bytes(44));
            responsePayload = respMap = Collections.singletonMap("bar", bytes(44));
            executeMessage.setCustomPayload(reqMap);
            Message.Response executeResponse = client.execute(executeMessage);
            payloadEquals(reqMap, requestPayload);
            payloadEquals(respMap, executeResponse.getCustomPayload());
            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 = respMap = Collections.singletonMap("bar", bytes(45));
            batchMessage.setCustomPayload(reqMap);
            Message.Response batchResponse = client.execute(batchMessage);
            payloadEquals(reqMap, requestPayload);
            payloadEquals(respMap, batchResponse.getCustomPayload());
        } finally {
            client.close();
        }
    } finally {
        cqlQueryHandlerField.set(null, queryHandler);
    }
}
Also used : QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) QueryHandler(org.apache.cassandra.cql3.QueryHandler) BatchMessage(org.apache.cassandra.transport.messages.BatchMessage) PrepareMessage(org.apache.cassandra.transport.messages.PrepareMessage) ExecuteMessage(org.apache.cassandra.transport.messages.ExecuteMessage) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) ResultMessage(org.apache.cassandra.transport.messages.ResultMessage) ByteBuffer(java.nio.ByteBuffer) PrepareMessage(org.apache.cassandra.transport.messages.PrepareMessage) ExecuteMessage(org.apache.cassandra.transport.messages.ExecuteMessage) BatchMessage(org.apache.cassandra.transport.messages.BatchMessage) Test(org.junit.Test)

Example 4 with QueryMessage

use of org.apache.cassandra.transport.messages.QueryMessage in project cassandra by apache.

the class ClientWarningsTest method testTombstoneWarning.

@Test
public void testTombstoneWarning() throws Exception {
    final int iterations = 10000;
    createTable("CREATE TABLE %s (pk int, ck int, v int, PRIMARY KEY (pk, ck))");
    try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) {
        client.connect(false);
        for (int i = 0; i < iterations; i++) {
            QueryMessage query = new QueryMessage(String.format("INSERT INTO %s.%s (pk, ck, v) VALUES (1, %s, 1)", KEYSPACE, currentTable(), i), QueryOptions.DEFAULT);
            client.execute(query);
        }
        ColumnFamilyStore store = Keyspace.open(KEYSPACE).getColumnFamilyStore(currentTable());
        store.forceBlockingFlush();
        for (int i = 0; i < iterations; i++) {
            QueryMessage query = new QueryMessage(String.format("DELETE v FROM %s.%s WHERE pk = 1 AND ck = %s", KEYSPACE, currentTable(), i), QueryOptions.DEFAULT);
            client.execute(query);
        }
        store.forceBlockingFlush();
        {
            QueryMessage query = new QueryMessage(String.format("SELECT * FROM %s.%s WHERE pk = 1", KEYSPACE, currentTable()), QueryOptions.DEFAULT);
            Message.Response resp = client.execute(query);
            assertEquals(1, resp.getWarnings().size());
        }
    }
}
Also used : QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) SimpleClient(org.apache.cassandra.transport.SimpleClient) Test(org.junit.Test)

Example 5 with QueryMessage

use of org.apache.cassandra.transport.messages.QueryMessage in project cassandra by apache.

the class ClientWarningsTest method testUnloggedBatchWithProtoV4.

@Test
public void testUnloggedBatchWithProtoV4() throws Exception {
    createTable("CREATE TABLE %s (pk int PRIMARY KEY, v text)");
    try (SimpleClient client = new SimpleClient(nativeAddr.getHostAddress(), nativePort, ProtocolVersion.V4)) {
        client.connect(false);
        QueryMessage query = new QueryMessage(createBatchStatement2(1), QueryOptions.DEFAULT);
        Message.Response resp = client.execute(query);
        assertNull(resp.getWarnings());
        query = new QueryMessage(createBatchStatement2(DatabaseDescriptor.getBatchSizeWarnThreshold()), QueryOptions.DEFAULT);
        resp = client.execute(query);
        assertEquals(1, resp.getWarnings().size());
    }
}
Also used : QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) QueryMessage(org.apache.cassandra.transport.messages.QueryMessage) Message(org.apache.cassandra.transport.Message) SimpleClient(org.apache.cassandra.transport.SimpleClient) Test(org.junit.Test)

Aggregations

QueryMessage (org.apache.cassandra.transport.messages.QueryMessage)6 Test (org.junit.Test)6 SimpleClient (org.apache.cassandra.transport.SimpleClient)4 Message (org.apache.cassandra.transport.Message)3 ByteBuffer (java.nio.ByteBuffer)2 QueryHandler (org.apache.cassandra.cql3.QueryHandler)2 BatchMessage (org.apache.cassandra.transport.messages.BatchMessage)2 ExecuteMessage (org.apache.cassandra.transport.messages.ExecuteMessage)2 PrepareMessage (org.apache.cassandra.transport.messages.PrepareMessage)2 ResultMessage (org.apache.cassandra.transport.messages.ResultMessage)2 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1