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