Search in sources :

Example 1 with StatusChangeEvent

use of com.datastax.oss.protocol.internal.response.event.StatusChangeEvent in project java-driver by datastax.

the class ControlConnectionEventsTest method should_process_status_change_events.

@Test
public void should_process_status_change_events() {
    // Given
    DriverChannel channel1 = newMockDriverChannel(1);
    ArgumentCaptor<DriverChannelOptions> optionsCaptor = ArgumentCaptor.forClass(DriverChannelOptions.class);
    when(channelFactory.connect(eq(node1), optionsCaptor.capture())).thenReturn(CompletableFuture.completedFuture(channel1));
    controlConnection.init(true, false, false);
    await().until(() -> optionsCaptor.getValue() != null);
    EventCallback callback = optionsCaptor.getValue().eventCallback;
    StatusChangeEvent event = new StatusChangeEvent(ProtocolConstants.StatusChangeType.UP, ADDRESS1);
    // When
    callback.onEvent(event);
    // Then
    verify(eventBus).fire(TopologyEvent.suggestUp(ADDRESS1));
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) DriverChannelOptions(com.datastax.oss.driver.internal.core.channel.DriverChannelOptions) StatusChangeEvent(com.datastax.oss.protocol.internal.response.event.StatusChangeEvent) EventCallback(com.datastax.oss.driver.internal.core.channel.EventCallback) Test(org.junit.Test)

Example 2 with StatusChangeEvent

use of com.datastax.oss.protocol.internal.response.event.StatusChangeEvent in project java-driver by datastax.

the class InFlightHandlerTest method should_notify_callback_of_events.

@Test
public void should_notify_callback_of_events() {
    // Given
    EventCallback eventCallback = mock(EventCallback.class);
    addToPipelineWithEventCallback(eventCallback);
    // When
    StatusChangeEvent event = new StatusChangeEvent(ProtocolConstants.StatusChangeType.UP, new InetSocketAddress("127.0.0.1", 9042));
    Frame eventFrame = Frame.forResponse(DefaultProtocolVersion.V3.getCode(), -1, null, Collections.emptyMap(), Collections.emptyList(), event);
    writeInboundFrame(eventFrame);
    // Then
    ArgumentCaptor<StatusChangeEvent> captor = ArgumentCaptor.forClass(StatusChangeEvent.class);
    verify(eventCallback).onEvent(captor.capture());
    assertThat(captor.getValue()).isSameAs(event);
}
Also used : Frame(com.datastax.oss.protocol.internal.Frame) StatusChangeEvent(com.datastax.oss.protocol.internal.response.event.StatusChangeEvent) InetSocketAddress(java.net.InetSocketAddress) Test(org.junit.Test)

Aggregations

StatusChangeEvent (com.datastax.oss.protocol.internal.response.event.StatusChangeEvent)2 Test (org.junit.Test)2 DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)1 DriverChannelOptions (com.datastax.oss.driver.internal.core.channel.DriverChannelOptions)1 EventCallback (com.datastax.oss.driver.internal.core.channel.EventCallback)1 Frame (com.datastax.oss.protocol.internal.Frame)1 InetSocketAddress (java.net.InetSocketAddress)1