Search in sources :

Example 1 with Void

use of com.datastax.oss.protocol.internal.response.result.Void 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();
}
Also used : Frame(com.datastax.oss.protocol.internal.Frame) Query(com.datastax.oss.protocol.internal.request.Query) Void(com.datastax.oss.protocol.internal.response.result.Void) Test(org.junit.Test)

Example 2 with Void

use of com.datastax.oss.protocol.internal.response.result.Void in project java-driver by datastax.

the class DriverChannelTest method should_wait_for_coalesced_writes_when_closing_forcefully.

/**
 * Ensures that the potential delay introduced by the write coalescer does not mess with the
 * forceful shutdown sequence: any write submitted before {@link DriverChannel#forceClose()}
 * should get the "Channel was force-closed" error, whether it had been flushed or not.
 */
@Test
public void should_wait_for_coalesced_writes_when_closing_forcefully() {
    // 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.forceClose();
    // Then
    // not closed yet because there is still a pending write
    assertThat(closeFuture).isNotDone();
    assertNoOutboundFrame();
    // When
    // the coalescer finally runs
    writeCoalescer.triggerFlush();
    // and the pending write goes through
    Frame requestFrame = readOutboundFrame();
    assertThat(requestFrame).isNotNull();
    // Then
    assertThat(closeFuture).isSuccess();
    assertThat(responseCallback.getFailure()).isInstanceOf(ClosedConnectionException.class).hasMessageContaining("Channel was force-closed");
}
Also used : Frame(com.datastax.oss.protocol.internal.Frame) Query(com.datastax.oss.protocol.internal.request.Query) ClosedConnectionException(com.datastax.oss.driver.api.core.connection.ClosedConnectionException) Void(com.datastax.oss.protocol.internal.response.result.Void) Test(org.junit.Test)

Example 3 with Void

use of com.datastax.oss.protocol.internal.response.result.Void in project java-driver by datastax.

the class ChannelFactoryAvailableIdsTest method should_report_available_ids.

@Test
public void should_report_available_ids() {
    // Given
    ChannelFactory factory = newChannelFactory();
    // When
    CompletionStage<DriverChannel> channelFuture = factory.connect(SERVER_ADDRESS, DriverChannelOptions.builder().build(), NoopNodeMetricUpdater.INSTANCE);
    completeSimpleChannelInit();
    // Then
    assertThatStage(channelFuture).isSuccess(channel -> {
        assertThat(channel.getAvailableIds()).isEqualTo(128);
        // Write a request, should decrease the count
        assertThat(channel.preAcquireId()).isTrue();
        Future<java.lang.Void> writeFuture = channel.write(new Query("test"), false, Frame.NO_PAYLOAD, responseCallback);
        assertThat(writeFuture).isSuccess(v -> {
            assertThat(channel.getAvailableIds()).isEqualTo(127);
            // Complete the request, should increase again
            writeInboundFrame(readOutboundFrame(), Void.INSTANCE);
            verify(responseCallback, timeout(500)).onResponse(any(Frame.class));
            assertThat(channel.getAvailableIds()).isEqualTo(128);
        });
    });
}
Also used : Frame(com.datastax.oss.protocol.internal.Frame) Query(com.datastax.oss.protocol.internal.request.Query) Void(com.datastax.oss.protocol.internal.response.result.Void) Test(org.junit.Test)

Aggregations

Frame (com.datastax.oss.protocol.internal.Frame)3 Query (com.datastax.oss.protocol.internal.request.Query)3 Void (com.datastax.oss.protocol.internal.response.result.Void)3 Test (org.junit.Test)3 ClosedConnectionException (com.datastax.oss.driver.api.core.connection.ClosedConnectionException)1