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);
}
Aggregations