Search in sources :

Example 1 with StatementWrapper

use of com.datastax.driver.core.StatementWrapper in project pinpoint by naver.

the class CassandraDatastaxITBase method testBatchStatement_and_StatementWrapper.

@Test
public void testBatchStatement_and_StatementWrapper() throws Exception {
    final String testId1 = "998";
    final String testValue1 = "testValue998";
    final String testId2 = "999";
    final String testValue2 = "testValue999";
    PluginTestVerifier verifier = PluginTestVerifierHolder.getInstance();
    try (Session session = openSession(cluster)) {
        // ===============================================
        // Insert Data 2 x (PreparedStatement, BoundStatement)
        PreparedStatement preparedStatement = session.prepare(CQL_INSERT);
        BoundStatement boundStatement1 = new BoundStatement(preparedStatement);
        boundStatement1.bind(testId1, testValue1);
        BoundStatement boundStatement2 = new BoundStatement(preparedStatement);
        boundStatement2.bind(testId2, testValue2);
        BatchStatement batchStatement = new BatchStatement();
        batchStatement.add(boundStatement1);
        batchStatement.add(boundStatement2);
        session.execute(batchStatement);
        verifier.printCache();
        // Cluster#connect(String)
        Class<?> clusterClass = Class.forName("com.datastax.driver.core.Cluster");
        Method connect = clusterClass.getDeclaredMethod("connect", String.class);
        verifier.verifyTrace(event(CASSANDRA, connect, null, CASSANDRA_ADDRESS, TEST_KEYSPACE));
        // SessionManager#prepare(String) OR AbstractSession#prepare(String)
        Class<?> sessionClass;
        try {
            sessionClass = Class.forName("com.datastax.driver.core.AbstractSession");
        } catch (ClassNotFoundException e) {
            sessionClass = Class.forName("com.datastax.driver.core.SessionManager");
        }
        Method prepare = sessionClass.getDeclaredMethod("prepare", String.class);
        verifier.verifyTrace(event(CASSANDRA, prepare, null, CASSANDRA_ADDRESS, TEST_KEYSPACE, sql(CQL_INSERT, null)));
        // SessionManager#execute(Statement) OR AbstractSession#execute(Statement)
        Method execute = sessionClass.getDeclaredMethod("execute", Statement.class);
        verifier.verifyTrace(event(CASSANDRA_EXECUTE_QUERY, execute, null, CASSANDRA_ADDRESS, TEST_KEYSPACE));
        // ====================
        final String cqlDelete = String.format("DELETE FROM %s.%s WHERE %s IN (? , ?)", TEST_KEYSPACE, TEST_TABLE, TEST_COL_ID);
        PreparedStatement deletePreparedStatement = session.prepare(cqlDelete);
        BoundStatement deleteBoundStatement = new BoundStatement(deletePreparedStatement);
        deleteBoundStatement.bind(testId1, testId2);
        Statement wrappedDeleteStatement = new StatementWrapper(deleteBoundStatement) {
        };
        session.execute(wrappedDeleteStatement);
        verifier.printCache();
        // SessionManager#prepare(String) OR AbstractSession#prepare(String)
        verifier.verifyTrace(event(CASSANDRA, prepare, null, CASSANDRA_ADDRESS, TEST_KEYSPACE, sql(cqlDelete, null)));
        // SessionManager#execute(String, Object[]) OR AbstractSession#execute(String, Object[])
        verifier.verifyTrace(event(CASSANDRA_EXECUTE_QUERY, execute, null, CASSANDRA_ADDRESS, TEST_KEYSPACE, sql(cqlDelete, null)));
    }
}
Also used : StatementWrapper(com.datastax.driver.core.StatementWrapper) PreparedStatement(com.datastax.driver.core.PreparedStatement) BoundStatement(com.datastax.driver.core.BoundStatement) Statement(com.datastax.driver.core.Statement) BatchStatement(com.datastax.driver.core.BatchStatement) BatchStatement(com.datastax.driver.core.BatchStatement) PreparedStatement(com.datastax.driver.core.PreparedStatement) Method(java.lang.reflect.Method) PluginTestVerifier(com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier) BoundStatement(com.datastax.driver.core.BoundStatement) Session(com.datastax.driver.core.Session) Test(org.junit.Test)

Aggregations

BatchStatement (com.datastax.driver.core.BatchStatement)1 BoundStatement (com.datastax.driver.core.BoundStatement)1 PreparedStatement (com.datastax.driver.core.PreparedStatement)1 Session (com.datastax.driver.core.Session)1 Statement (com.datastax.driver.core.Statement)1 StatementWrapper (com.datastax.driver.core.StatementWrapper)1 PluginTestVerifier (com.navercorp.pinpoint.bootstrap.plugin.test.PluginTestVerifier)1 Method (java.lang.reflect.Method)1 Test (org.junit.Test)1