Search in sources :

Example 6 with Prepare

use of com.datastax.oss.protocol.internal.request.Prepare in project java-driver by datastax.

the class ReprepareOnUpTest method should_not_reprepare_already_known_statements.

@Test
public void should_not_reprepare_already_known_statements() {
    MockReprepareOnUp reprepareOnUp = new MockReprepareOnUp("test", pool, ImmediateEventExecutor.INSTANCE, getMockPayloads('a', 'b', 'c', 'd', 'e', 'f'), context, whenPrepared);
    reprepareOnUp.start();
    MockAdminQuery adminQuery = reprepareOnUp.queries.poll();
    assertThat(adminQuery).isNotNull();
    assertThat(adminQuery.request).isInstanceOf(Query.class);
    assertThat(((Query) adminQuery.request).query).isEqualTo("SELECT prepared_id FROM system.prepared_statements");
    // server knows d, e and f already:
    adminQuery.resultFuture.complete(new AdminResult(preparedIdRows('d', 'e', 'f'), null, DefaultProtocolVersion.DEFAULT));
    for (char c = 'a'; c <= 'c'; c++) {
        adminQuery = reprepareOnUp.queries.poll();
        assertThat(adminQuery).isNotNull();
        assertThat(adminQuery.request).isInstanceOf(Prepare.class);
        assertThat(((Prepare) adminQuery.request).cqlQuery).isEqualTo("mock query " + c);
        adminQuery.resultFuture.complete(null);
    }
    assertThatStage(done).isSuccess(v -> assertThat(reprepareOnUp.queries).isEmpty());
}
Also used : Query(com.datastax.oss.protocol.internal.request.Query) Prepare(com.datastax.oss.protocol.internal.request.Prepare) AdminResult(com.datastax.oss.driver.internal.core.adminrequest.AdminResult) Test(org.junit.Test)

Aggregations

Prepare (com.datastax.oss.protocol.internal.request.Prepare)6 AdminResult (com.datastax.oss.driver.internal.core.adminrequest.AdminResult)4 Query (com.datastax.oss.protocol.internal.request.Query)4 Test (org.junit.Test)4 CqlIdentifier (com.datastax.oss.driver.api.core.CqlIdentifier)1 NodeUnavailableException (com.datastax.oss.driver.api.core.NodeUnavailableException)1 ProtocolVersion (com.datastax.oss.driver.api.core.ProtocolVersion)1 ProtocolVersionRegistry (com.datastax.oss.driver.internal.core.ProtocolVersionRegistry)1 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)1 NonNull (edu.umd.cs.findbugs.annotations.NonNull)1