Search in sources :

Example 16 with Ready

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

the class ProtocolInitHandlerTest method should_add_heartbeat_handler_to_pipeline_on_success.

@Test
public void should_add_heartbeat_handler_to_pipeline_on_success() {
    ProtocolInitHandler protocolInitHandler = new ProtocolInitHandler(internalDriverContext, DefaultProtocolVersion.V4, null, END_POINT, DriverChannelOptions.DEFAULT, heartbeatHandler, false);
    channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, protocolInitHandler);
    ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
    // heartbeat should initially not be in pipeline
    assertThat(channel.pipeline().get(ChannelFactory.HEARTBEAT_HANDLER_NAME)).isNull();
    // It should send a STARTUP message
    Frame requestFrame = readOutboundFrame();
    assertThat(requestFrame.message).isInstanceOf(Startup.class);
    assertThat(connectFuture).isNotDone();
    // Simulate a READY response
    writeInboundFrame(buildInboundFrame(requestFrame, new Ready()));
    // Simulate the cluster name check
    requestFrame = readOutboundFrame();
    assertThat(requestFrame.message).isInstanceOf(Query.class);
    writeInboundFrame(requestFrame, TestResponses.clusterNameResponse("someClusterName"));
    // Init should complete
    assertThat(connectFuture).isSuccess();
    // should have added heartbeat handler to pipeline.
    assertThat(channel.pipeline().get(ChannelFactory.HEARTBEAT_HANDLER_NAME)).isEqualTo(heartbeatHandler);
    // should have removed itself from pipeline.
    assertThat(channel.pipeline().last()).isNotEqualTo(protocolInitHandler);
}
Also used : ChannelFuture(io.netty.channel.ChannelFuture) Ready(com.datastax.oss.protocol.internal.response.Ready) Frame(com.datastax.oss.protocol.internal.Frame) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Aggregations

Ready (com.datastax.oss.protocol.internal.response.Ready)16 Test (org.junit.Test)15 Frame (com.datastax.oss.protocol.internal.Frame)12 ChannelFuture (io.netty.channel.ChannelFuture)10 InetSocketAddress (java.net.InetSocketAddress)10 Query (com.datastax.oss.protocol.internal.request.Query)4 Register (com.datastax.oss.protocol.internal.request.Register)2 Error (com.datastax.oss.protocol.internal.response.Error)2 SetKeyspace (com.datastax.oss.protocol.internal.response.result.SetKeyspace)2 AuthProvider (com.datastax.oss.driver.api.core.auth.AuthProvider)1 ImmutableList (com.datastax.oss.driver.shaded.guava.common.collect.ImmutableList)1 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)1 List (java.util.List)1