use of com.datastax.oss.protocol.internal.Frame 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.Frame 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.Frame in project java-driver by datastax.
the class DriverChannelTest method should_wait_for_coalesced_writes_when_closing_gracefully.
/**
* Ensures that the potential delay introduced by the write coalescer does not mess with the
* graceful shutdown sequence: any write submitted before {@link DriverChannel#close()} is
* guaranteed to complete.
*/
@Test
public void should_wait_for_coalesced_writes_when_closing_gracefully() {
// Given
MockResponseCallback responseCallback = new MockResponseCallback();
driverChannel.write(new Query("test"), false, Frame.NO_PAYLOAD, responseCallback);
// nothing written yet because the coalescer hasn't flushed
assertNoOutboundFrame();
// When
Future<java.lang.Void> closeFuture = driverChannel.close();
// Then
// not closed yet because there is still a pending write
assertThat(closeFuture).isNotDone();
assertNoOutboundFrame();
// When
// the coalescer finally runs
writeCoalescer.triggerFlush();
// Then
// the pending write goes through
Frame requestFrame = readOutboundFrame();
assertThat(requestFrame).isNotNull();
// not closed yet because there is now a pending response
assertThat(closeFuture).isNotDone();
// When
// the pending response arrives
writeInboundFrame(requestFrame, Void.INSTANCE);
assertThat(responseCallback.getLastResponse().message).isEqualTo(Void.INSTANCE);
// Then
assertThat(closeFuture).isSuccess();
}
use of com.datastax.oss.protocol.internal.Frame in project java-driver by datastax.
the class InFlightHandlerTest method should_notify_callback_of_response.
@Test
public void should_notify_callback_of_response() {
// Given
addToPipeline();
when(streamIds.acquire()).thenReturn(42);
MockResponseCallback responseCallback = new MockResponseCallback();
channel.writeAndFlush(new DriverChannel.RequestMessage(QUERY, false, Frame.NO_PAYLOAD, responseCallback));
Frame requestFrame = readOutboundFrame();
// When
Frame responseFrame = buildInboundFrame(requestFrame, Void.INSTANCE);
writeInboundFrame(responseFrame);
// Then
assertThat(responseCallback.getLastResponse()).isSameAs(responseFrame);
verify(streamIds).release(42);
}
use of com.datastax.oss.protocol.internal.Frame in project java-driver by datastax.
the class InFlightHandlerTest method should_assign_streamid_and_send_frame.
@Test
public void should_assign_streamid_and_send_frame() {
// Given
addToPipeline();
when(streamIds.acquire()).thenReturn(42);
MockResponseCallback responseCallback = new MockResponseCallback();
// When
ChannelFuture writeFuture = channel.writeAndFlush(new DriverChannel.RequestMessage(QUERY, false, Frame.NO_PAYLOAD, responseCallback));
// Then
assertThat(writeFuture).isSuccess();
verify(streamIds).acquire();
Frame frame = readOutboundFrame();
assertThat(frame.streamId).isEqualTo(42);
assertThat(frame.message).isEqualTo(QUERY);
}
Aggregations