Search in sources :

Example 1 with SchemaChangeEvent

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

the class ControlConnection method processSchemaChange.

private void processSchemaChange(Event event) {
    SchemaChangeEvent sce = (SchemaChangeEvent) event;
    context.getMetadataManager().refreshSchema(sce.keyspace, false, false).whenComplete((metadata, error) -> {
        if (error != null) {
            Loggers.warnWithException(LOG, "[{}] Unexpected error while refreshing schema for a SCHEMA_CHANGE event, " + "keeping previous version", logPrefix, error);
        }
    });
}
Also used : SchemaChangeEvent(com.datastax.oss.protocol.internal.response.event.SchemaChangeEvent)

Example 2 with SchemaChangeEvent

use of com.datastax.oss.protocol.internal.response.event.SchemaChangeEvent 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)

Aggregations

SchemaChangeEvent (com.datastax.oss.protocol.internal.response.event.SchemaChangeEvent)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 Test (org.junit.Test)1