use of com.datastax.oss.protocol.internal.request.Register in project java-driver by datastax.
the class ProtocolInitHandlerTest method should_initialize_with_events.
@Test
public void should_initialize_with_events() {
List<String> eventTypes = ImmutableList.of("foo", "bar");
EventCallback eventCallback = mock(EventCallback.class);
DriverChannelOptions driverChannelOptions = DriverChannelOptions.builder().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(Register.class);
assertThat(((Register) requestFrame.message).eventTypes).containsExactly("foo", "bar");
writeInboundFrame(requestFrame, new Ready());
assertThat(connectFuture).isSuccess();
}
use of com.datastax.oss.protocol.internal.request.Register 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