Search in sources :

Example 1 with SetKeyspace

use of com.datastax.oss.protocol.internal.response.result.SetKeyspace in project java-driver by datastax.

the class ProtocolInitHandlerTest method should_initialize_with_keyspace.

@Test
public void should_initialize_with_keyspace() {
    DriverChannelOptions options = DriverChannelOptions.builder().withKeyspace(CqlIdentifier.fromCql("ks")).build();
    channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, new ProtocolInitHandler(internalDriverContext, DefaultProtocolVersion.V4, null, END_POINT, options, heartbeatHandler, false));
    ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
    writeInboundFrame(readOutboundFrame(), new Ready());
    writeInboundFrame(readOutboundFrame(), TestResponses.clusterNameResponse("someClusterName"));
    Frame requestFrame = readOutboundFrame();
    assertThat(requestFrame.message).isInstanceOf(Query.class);
    assertThat(((Query) requestFrame.message).query).isEqualTo("USE \"ks\"");
    writeInboundFrame(requestFrame, new SetKeyspace("ks"));
    assertThat(connectFuture).isSuccess();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Ready(com.datastax.oss.protocol.internal.response.Ready) Frame(com.datastax.oss.protocol.internal.Frame) Query(com.datastax.oss.protocol.internal.request.Query) InetSocketAddress(java.net.InetSocketAddress) SetKeyspace(com.datastax.oss.protocol.internal.response.result.SetKeyspace) Test(org.junit.Test)

Example 2 with SetKeyspace

use of com.datastax.oss.protocol.internal.response.result.SetKeyspace in project java-driver by datastax.

the class CqlRequestHandlerTest method should_switch_keyspace_on_session_after_successful_use_statement.

@Test
public void should_switch_keyspace_on_session_after_successful_use_statement() {
    try (RequestHandlerTestHarness harness = RequestHandlerTestHarness.builder().withResponse(node1, defaultFrameOf(new SetKeyspace("newKeyspace"))).build()) {
        CompletionStage<AsyncResultSet> resultSetFuture = new CqlRequestHandler(UNDEFINED_IDEMPOTENCE_STATEMENT, harness.getSession(), harness.getContext(), "test").handle();
        assertThatStage(resultSetFuture).isSuccess(resultSet -> verify(harness.getSession()).setKeyspace(CqlIdentifier.fromInternal("newKeyspace")));
    }
}
Also used : AsyncResultSet(com.datastax.oss.driver.api.core.cql.AsyncResultSet) SetKeyspace(com.datastax.oss.protocol.internal.response.result.SetKeyspace) Test(org.junit.Test)

Example 3 with SetKeyspace

use of com.datastax.oss.protocol.internal.response.result.SetKeyspace in project java-driver by datastax.

the class InFlightHandlerTest method should_set_keyspace.

@Test
public void should_set_keyspace() {
    // Given
    addToPipeline();
    ChannelPromise setKeyspacePromise = channel.newPromise();
    DriverChannel.SetKeyspaceEvent setKeyspaceEvent = new DriverChannel.SetKeyspaceEvent(CqlIdentifier.fromCql("ks"), setKeyspacePromise);
    // When
    channel.pipeline().fireUserEventTriggered(setKeyspaceEvent);
    Frame requestFrame = readOutboundFrame();
    // Then
    assertThat(requestFrame.message).isInstanceOf(Query.class);
    writeInboundFrame(requestFrame, new SetKeyspace("ks"));
    assertThat(setKeyspacePromise).isSuccess();
}
Also used : Frame(com.datastax.oss.protocol.internal.Frame) ChannelPromise(io.netty.channel.ChannelPromise) SetKeyspace(com.datastax.oss.protocol.internal.response.result.SetKeyspace) Test(org.junit.Test)

Example 4 with SetKeyspace

use of com.datastax.oss.protocol.internal.response.result.SetKeyspace in project java-driver by datastax.

the class ProtocolInitHandlerTest method should_initialize_with_keyspace_and_events.

@Test
public void should_initialize_with_keyspace_and_events() {
    List<String> eventTypes = ImmutableList.of("foo", "bar");
    EventCallback eventCallback = mock(EventCallback.class);
    DriverChannelOptions driverChannelOptions = DriverChannelOptions.builder().withKeyspace(CqlIdentifier.fromCql("ks")).withEvents(eventTypes, eventCallback).build();
    channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, new ProtocolInitHandler(internalDriverContext, DefaultProtocolVersion.V4, null, END_POINT, driverChannelOptions, heartbeatHandler, false));
    ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
    writeInboundFrame(readOutboundFrame(), new Ready());
    writeInboundFrame(readOutboundFrame(), TestResponses.clusterNameResponse("someClusterName"));
    Frame requestFrame = readOutboundFrame();
    assertThat(requestFrame.message).isInstanceOf(Query.class);
    assertThat(((Query) requestFrame.message).query).isEqualTo("USE \"ks\"");
    writeInboundFrame(requestFrame, new SetKeyspace("ks"));
    requestFrame = readOutboundFrame();
    assertThat(requestFrame.message).isInstanceOf(Register.class);
    assertThat(((Register) requestFrame.message).eventTypes).containsExactly("foo", "bar");
    writeInboundFrame(requestFrame, new Ready());
    assertThat(connectFuture).isSuccess();
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Ready(com.datastax.oss.protocol.internal.response.Ready) Frame(com.datastax.oss.protocol.internal.Frame) Query(com.datastax.oss.protocol.internal.request.Query) Register(com.datastax.oss.protocol.internal.request.Register) InetSocketAddress(java.net.InetSocketAddress) SetKeyspace(com.datastax.oss.protocol.internal.response.result.SetKeyspace) Test(org.junit.Test)

Aggregations

SetKeyspace (com.datastax.oss.protocol.internal.response.result.SetKeyspace)4 Test (org.junit.Test)4 Frame (com.datastax.oss.protocol.internal.Frame)3 Query (com.datastax.oss.protocol.internal.request.Query)2 Ready (com.datastax.oss.protocol.internal.response.Ready)2 ChannelFuture (io.netty.channel.ChannelFuture)2 InetSocketAddress (java.net.InetSocketAddress)2 AsyncResultSet (com.datastax.oss.driver.api.core.cql.AsyncResultSet)1 Register (com.datastax.oss.protocol.internal.request.Register)1 ChannelPromise (io.netty.channel.ChannelPromise)1