Search in sources :

Example 1 with PreparedStatementExecution

use of org.scassandra.http.client.PreparedStatementExecution in project java-driver by datastax.

the class ConsistencyTest method should_use_query_option_serial_cl.

/**
 * Exhaustively tests all serial consistency levels when they are set via QueryOptions.
 *
 * @test_category consistency
 */
@Test(groups = "short", dataProvider = "serialConsistencyLevels", dataProviderClass = DataProviders.class)
public void should_use_query_option_serial_cl(ConsistencyLevel cl) throws Throwable {
    // Build a cluster with a CL level set in the query options.
    Cluster cluster = builder().withQueryOptions(new QueryOptions().setSerialConsistencyLevel(cl)).build();
    try {
        Session session = cluster.connect();
        // Construct unique query, with no CL defined.
        String queryString = "serial_query_cl";
        Query clQuery = executeSimple(session, queryString, null, cl);
        checkSerialCLMatch(cl, clQuery.getSerialConsistency());
        // Check prepared statement CL
        String prepareString = "preapred_statement_serial_cl";
        PreparedStatementExecution pse = executePrepared(session, prepareString, null, null);
        checkSerialCLMatch(cl, pse.getSerialConsistency());
        // Check batch statement CL
        String batchStateString = "batch_statement_serial_cl";
        BatchExecution batch = executeBatch(session, batchStateString, null, null);
        checkSerialCLMatch(cl, batch.getSerialConsistency());
    } finally {
        cluster.close();
    }
}
Also used : Query(org.scassandra.http.client.Query) BatchExecution(org.scassandra.http.client.BatchExecution) PreparedStatementExecution(org.scassandra.http.client.PreparedStatementExecution) Test(org.testng.annotations.Test)

Example 2 with PreparedStatementExecution

use of org.scassandra.http.client.PreparedStatementExecution in project java-driver by datastax.

the class ConsistencyTest method should_use_global_default_cl_when_none_specified.

/**
 * When no consistency level is defined the default of LOCAL_ONE should be used.
 *
 * @test_category consistency
 */
@Test(groups = "short")
public void should_use_global_default_cl_when_none_specified() throws Throwable {
    // Build a cluster with no CL level set in the query options.
    Cluster cluster = builder().build();
    try {
        Session session = cluster.connect();
        // Construct unique simple statement query, with no CL defined.
        // Check to ensure
        String queryString = "default_cl";
        Query clQuery = executeSimple(session, queryString, null, null);
        assertTrue(clQuery.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
        // Check prepared statement default CL
        String prepareString = "prepared_default_cl";
        PreparedStatementExecution pse = executePrepared(session, prepareString, null, null);
        assertTrue(pse.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
        // Check batch statement default CL
        String batchStateString = "batch_default_cl";
        BatchExecution batch = executeBatch(session, batchStateString, null, null);
        assertTrue(batch.getConsistency().equals(ConsistencyLevel.LOCAL_ONE.toString()));
    } finally {
        cluster.close();
    }
}
Also used : Query(org.scassandra.http.client.Query) BatchExecution(org.scassandra.http.client.BatchExecution) PreparedStatementExecution(org.scassandra.http.client.PreparedStatementExecution) Test(org.testng.annotations.Test)

Example 3 with PreparedStatementExecution

use of org.scassandra.http.client.PreparedStatementExecution in project java-driver by datastax.

the class ConsistencyTest method should_use_statement_cl.

/**
 * Exhaustively tests all consistency levels when they are set at the statement level.
 *
 * @test_category consistency
 */
@Test(groups = "short", dataProvider = "consistencyLevels", dataProviderClass = DataProviders.class)
public void should_use_statement_cl(ConsistencyLevel cl) throws Throwable {
    // Build a cluster with no CL set in the query options.
    // Note: nonQuietClusterCloseOptions is used to speed up tests
    Cluster cluster = builder().build();
    try {
        Session session = cluster.connect();
        // Construct unique query statement with a CL defined.
        String queryString = "statement_cl";
        Query clQuery = executeSimple(session, queryString, cl, null);
        assertTrue(clQuery.getConsistency().equals(cl.toString()));
        // Check prepared statement CL
        String prepareString = "preapred_statement_cl";
        PreparedStatementExecution pse = executePrepared(session, prepareString, cl, null);
        assertTrue(pse.getConsistency().equals(cl.toString()));
        // Check batch statement CL
        String batchStateString = "batch_statement_cl";
        BatchExecution batch = executeBatch(session, batchStateString, cl, null);
        assertTrue(batch.getConsistency().equals(cl.toString()));
    } finally {
        cluster.close();
    }
}
Also used : Query(org.scassandra.http.client.Query) BatchExecution(org.scassandra.http.client.BatchExecution) PreparedStatementExecution(org.scassandra.http.client.PreparedStatementExecution) Test(org.testng.annotations.Test)

Example 4 with PreparedStatementExecution

use of org.scassandra.http.client.PreparedStatementExecution in project java-driver by datastax.

the class ConsistencyTest method executePrepared.

public PreparedStatementExecution executePrepared(Session session, String statement, ConsistencyLevel level, ConsistencyLevel serialLevel) {
    PreparedStatement ps = session.prepare(statement);
    BoundStatement bound = ps.bind();
    if (level != null) {
        bound.setConsistencyLevel(level);
    }
    if (serialLevel != null) {
        bound.setSerialConsistencyLevel(serialLevel);
    }
    session.execute(bound);
    List<PreparedStatementExecution> pses = sCluster.node(1).activityClient().retrievePreparedStatementExecutions();
    PreparedStatementExecution pse = pses.get(0);
    assertTrue(pse.getPreparedStatementText().equals(statement));
    return pse;
}
Also used : PreparedStatementExecution(org.scassandra.http.client.PreparedStatementExecution)

Example 5 with PreparedStatementExecution

use of org.scassandra.http.client.PreparedStatementExecution in project data-transfer-project by google.

the class CosmosStoreTest method verifyCreateAndFind.

@Test
@Ignore
public void verifyCreateAndFind() throws Exception {
    PrimingRequest.Then.ThenBuilder thenInsert = PrimingRequest.then();
    thenInsert.withVariableTypes(UUID, VARCHAR);
    PrimingRequest createRequest = PrimingRequest.preparedStatementBuilder().withQuery(JOB_INSERT).withThen(thenInsert).build();
    cassandra.primingClient().prime(createRequest);
    PortabilityJob primeJob = PortabilityJob.builder().build();
    java.util.UUID jobId = java.util.UUID.randomUUID();
    Map row = Collections.singletonMap("job_data", new ObjectMapper().writeValueAsString(primeJob));
    PrimingRequest.Then.ThenBuilder thenQuery = PrimingRequest.then();
    PrimingRequest findRequest = PrimingRequest.preparedStatementBuilder().withQuery(JOB_QUERY).withThen(thenQuery.withVariableTypes(UUID).withColumnTypes(ColumnMetadata.column("job_id", UUID)).withRows(row)).build();
    cassandra.primingClient().prime(findRequest);
    PrimingRequest.Then.ThenBuilder thenUpdate = PrimingRequest.then();
    thenUpdate.withVariableTypes(VARCHAR, UUID).withColumnTypes(ColumnMetadata.column("job_data", VARCHAR), ColumnMetadata.column("job_id", UUID));
    PrimingRequest updateRequest = PrimingRequest.preparedStatementBuilder().withQuery(JOB_UPDATE).withThen(thenUpdate).build();
    cassandra.primingClient().prime(updateRequest);
    PrimingRequest.Then.ThenBuilder thenRemove = PrimingRequest.then();
    thenRemove.withVariableTypes(UUID);
    PrimingRequest removeRequest = PrimingRequest.preparedStatementBuilder().withQuery(JOB_DELETE).withThen(thenRemove).build();
    cassandra.primingClient().prime(removeRequest);
    PortabilityJob createJob = PortabilityJob.builder().build();
    cosmosStore.createJob(jobId, createJob);
    PortabilityJob copy = cosmosStore.findJob(jobId).toBuilder().setState(PortabilityJob.State.COMPLETE).build();
    cosmosStore.updateJob(jobId, copy);
    cosmosStore.remove(jobId);
    PreparedStatementExecution expectedStatement = PreparedStatementExecution.builder().withPreparedStatementText(JOB_DELETE).withConsistency("LOCAL_ONE").build();
    Assert.assertThat(cassandra.activityClient().retrievePreparedStatementExecutions(), preparedStatementRecorded(expectedStatement));
}
Also used : PortabilityJob(org.dataportabilityproject.spi.cloud.types.PortabilityJob) Map(java.util.Map) PreparedStatementExecution(org.scassandra.http.client.PreparedStatementExecution) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrimingRequest(org.scassandra.http.client.PrimingRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

PreparedStatementExecution (org.scassandra.http.client.PreparedStatementExecution)8 BatchExecution (org.scassandra.http.client.BatchExecution)6 Query (org.scassandra.http.client.Query)6 Test (org.testng.annotations.Test)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 Map (java.util.Map)1 PortabilityJob (org.dataportabilityproject.spi.cloud.types.PortabilityJob)1 Ignore (org.junit.Ignore)1 Test (org.junit.Test)1 PrimingRequest (org.scassandra.http.client.PrimingRequest)1