Search in sources :

Example 1 with DriverChannelOptions

use of com.datastax.oss.driver.internal.core.channel.DriverChannelOptions in project java-driver by datastax.

the class ControlConnectionEventsTest method should_process_topology_change_events.

@Test
public void should_process_topology_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;
    TopologyChangeEvent event = new TopologyChangeEvent(ProtocolConstants.TopologyChangeType.NEW_NODE, ADDRESS1);
    // When
    callback.onEvent(event);
    // Then
    verify(eventBus).fire(TopologyEvent.suggestAdded(ADDRESS1));
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) DriverChannelOptions(com.datastax.oss.driver.internal.core.channel.DriverChannelOptions) TopologyChangeEvent(com.datastax.oss.protocol.internal.response.event.TopologyChangeEvent) EventCallback(com.datastax.oss.driver.internal.core.channel.EventCallback) Test(org.junit.Test)

Example 2 with DriverChannelOptions

use of com.datastax.oss.driver.internal.core.channel.DriverChannelOptions in project java-driver by datastax.

the class ControlConnectionEventsTest method should_register_for_all_events_if_topology_requested.

@Test
public void should_register_for_all_events_if_topology_requested() {
    // Given
    DriverChannel channel1 = newMockDriverChannel(1);
    ArgumentCaptor<DriverChannelOptions> optionsCaptor = ArgumentCaptor.forClass(DriverChannelOptions.class);
    when(channelFactory.connect(eq(node1), optionsCaptor.capture())).thenReturn(CompletableFuture.completedFuture(channel1));
    // When
    controlConnection.init(true, false, false);
    // Then
    await().untilAsserted(() -> {
        DriverChannelOptions channelOptions = optionsCaptor.getValue();
        assertThat(channelOptions.eventTypes).containsExactly(ProtocolConstants.EventType.SCHEMA_CHANGE, ProtocolConstants.EventType.STATUS_CHANGE, ProtocolConstants.EventType.TOPOLOGY_CHANGE);
        assertThat(channelOptions.eventCallback).isEqualTo(controlConnection);
    });
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) DriverChannelOptions(com.datastax.oss.driver.internal.core.channel.DriverChannelOptions) Test(org.junit.Test)

Example 3 with DriverChannelOptions

use of com.datastax.oss.driver.internal.core.channel.DriverChannelOptions in project java-driver by datastax.

the class ControlConnectionEventsTest method should_register_for_schema_events_only_if_topology_not_requested.

@Test
public void should_register_for_schema_events_only_if_topology_not_requested() {
    // Given
    DriverChannel channel1 = newMockDriverChannel(1);
    ArgumentCaptor<DriverChannelOptions> optionsCaptor = ArgumentCaptor.forClass(DriverChannelOptions.class);
    when(channelFactory.connect(eq(node1), optionsCaptor.capture())).thenReturn(CompletableFuture.completedFuture(channel1));
    // When
    controlConnection.init(false, false, false);
    // Then
    await().untilAsserted(() -> {
        DriverChannelOptions channelOptions = optionsCaptor.getValue();
        assertThat(channelOptions.eventTypes).containsExactly(ProtocolConstants.EventType.SCHEMA_CHANGE);
        assertThat(channelOptions.eventCallback).isEqualTo(controlConnection);
    });
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) DriverChannelOptions(com.datastax.oss.driver.internal.core.channel.DriverChannelOptions) Test(org.junit.Test)

Example 4 with DriverChannelOptions

use of com.datastax.oss.driver.internal.core.channel.DriverChannelOptions in project java-driver by datastax.

the class ControlConnectionEventsTest method should_process_schema_change_events.

@Test
public void should_process_schema_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(false, false, false);
    await().until(() -> optionsCaptor.getValue() != null);
    EventCallback callback = optionsCaptor.getValue().eventCallback;
    SchemaChangeEvent event = new SchemaChangeEvent(ProtocolConstants.SchemaChangeType.CREATED, ProtocolConstants.SchemaChangeTarget.FUNCTION, "ks", "fn", ImmutableList.of("text", "text"));
    // When
    callback.onEvent(event);
    // Then
    verify(metadataManager).refreshSchema("ks", false, false);
}
Also used : DriverChannel(com.datastax.oss.driver.internal.core.channel.DriverChannel) DriverChannelOptions(com.datastax.oss.driver.internal.core.channel.DriverChannelOptions) EventCallback(com.datastax.oss.driver.internal.core.channel.EventCallback) SchemaChangeEvent(com.datastax.oss.protocol.internal.response.event.SchemaChangeEvent) Test(org.junit.Test)

Example 5 with DriverChannelOptions

use of com.datastax.oss.driver.internal.core.channel.DriverChannelOptions 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)

Aggregations

DriverChannel (com.datastax.oss.driver.internal.core.channel.DriverChannel)5 DriverChannelOptions (com.datastax.oss.driver.internal.core.channel.DriverChannelOptions)5 Test (org.junit.Test)5 EventCallback (com.datastax.oss.driver.internal.core.channel.EventCallback)3 SchemaChangeEvent (com.datastax.oss.protocol.internal.response.event.SchemaChangeEvent)1 StatusChangeEvent (com.datastax.oss.protocol.internal.response.event.StatusChangeEvent)1 TopologyChangeEvent (com.datastax.oss.protocol.internal.response.event.TopologyChangeEvent)1