use of com.datastax.oss.protocol.internal.response.Ready in project java-driver by datastax.
the class ProtocolInitHandlerTest method should_check_cluster_name_if_provided.
@Test
public void should_check_cluster_name_if_provided() {
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, new ProtocolInitHandler(internalDriverContext, DefaultProtocolVersion.V4, "expectedClusterName", END_POINT, DriverChannelOptions.DEFAULT, heartbeatHandler, false));
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
Frame requestFrame = readOutboundFrame();
writeInboundFrame(requestFrame, new Ready());
requestFrame = readOutboundFrame();
assertThat(requestFrame.message).isInstanceOf(Query.class);
Query query = (Query) requestFrame.message;
assertThat(query.query).isEqualTo("SELECT cluster_name FROM system.local");
assertThat(connectFuture).isNotDone();
writeInboundFrame(requestFrame, TestResponses.clusterNameResponse("expectedClusterName"));
assertThat(connectFuture).isSuccess();
}
use of com.datastax.oss.protocol.internal.response.Ready in project java-driver by datastax.
the class ProtocolInitHandlerTest method should_fail_to_initialize_if_cluster_name_does_not_match.
@Test
public void should_fail_to_initialize_if_cluster_name_does_not_match() throws Throwable {
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, new ProtocolInitHandler(internalDriverContext, DefaultProtocolVersion.V4, "expectedClusterName", END_POINT, DriverChannelOptions.DEFAULT, heartbeatHandler, false));
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
writeInboundFrame(readOutboundFrame(), new Ready());
writeInboundFrame(readOutboundFrame(), TestResponses.clusterNameResponse("differentClusterName"));
assertThat(connectFuture).isFailed(e -> assertThat(e).isInstanceOf(ClusterNameMismatchException.class).hasMessageContaining(String.format("Node %s reports cluster name 'differentClusterName' that doesn't match our cluster name 'expectedClusterName'.", END_POINT)));
}
use of com.datastax.oss.protocol.internal.response.Ready in project java-driver by datastax.
the class ProtocolInitHandlerTest method should_initialize.
@Test
public void should_initialize() {
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, new ProtocolInitHandler(internalDriverContext, DefaultProtocolVersion.V4, null, END_POINT, DriverChannelOptions.DEFAULT, heartbeatHandler, false));
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
// 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();
}
use of com.datastax.oss.protocol.internal.response.Ready in project java-driver by datastax.
the class ProtocolInitHandlerTest method should_invoke_auth_provider_when_server_does_not_send_challenge.
@Test
public void should_invoke_auth_provider_when_server_does_not_send_challenge() {
channel.pipeline().addLast(ChannelFactory.INIT_HANDLER_NAME, new ProtocolInitHandler(internalDriverContext, DefaultProtocolVersion.V4, null, END_POINT, DriverChannelOptions.DEFAULT, heartbeatHandler, false));
AuthProvider authProvider = mock(AuthProvider.class);
when(internalDriverContext.getAuthProvider()).thenReturn(Optional.of(authProvider));
ChannelFuture connectFuture = channel.connect(new InetSocketAddress("localhost", 9042));
Frame requestFrame = readOutboundFrame();
assertThat(requestFrame.message).isInstanceOf(Startup.class);
// Simulate a READY response, the provider should be notified
writeInboundFrame(buildInboundFrame(requestFrame, new Ready()));
verify(authProvider).onMissingChallenge(END_POINT);
// Since our mock does nothing, init should proceed normally
requestFrame = readOutboundFrame();
assertThat(requestFrame.message).isInstanceOf(Query.class);
writeInboundFrame(requestFrame, TestResponses.clusterNameResponse("someClusterName"));
assertThat(connectFuture).isSuccess();
}
use of com.datastax.oss.protocol.internal.response.Ready 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();
}
Aggregations