Search in sources :

Example 11 with EventListener

use of io.trino.spi.eventlistener.EventListener in project trino by trinodb.

the class TestHttpEventListener method testServerShouldRetry.

@Test(dataProvider = "retryStatusCodes")
public void testServerShouldRetry(int responseCode) throws Exception {
    EventListener eventListener = factory.create(Map.of("http-event-listener.connect-ingest-uri", server.url("/").toString(), "http-event-listener.log-completed", "true", "http-event-listener.connect-retry-count", "1"));
    server.enqueue(new MockResponse().setResponseCode(responseCode));
    server.enqueue(new MockResponse().setResponseCode(200));
    eventListener.queryCompleted(queryCompleteEvent);
    assertNotNull(server.takeRequest(5, TimeUnit.SECONDS));
    checkRequest(server.takeRequest(5, TimeUnit.SECONDS), queryCompleteEventJson);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) EventListener(io.trino.spi.eventlistener.EventListener) Test(org.testng.annotations.Test)

Example 12 with EventListener

use of io.trino.spi.eventlistener.EventListener in project trino by trinodb.

the class TestHttpEventListener method testHttpsEnabledShouldUseTLSv13.

@Test
public void testHttpsEnabledShouldUseTLSv13() throws Exception {
    setupServerTLSCertificate();
    server.enqueue(new MockResponse().setResponseCode(200));
    EventListener eventListener = factory.create(Map.of("http-event-listener.connect-ingest-uri", server.url("/").toString(), "http-event-listener.log-completed", "true", "http-event-listener.http-client.key-store-path", "src/test/resources/trino-httpquery-test.p12", "http-event-listener.http-client.key-store-password", "testing-ssl"));
    eventListener.queryCompleted(queryCompleteEvent);
    RecordedRequest recordedRequest = server.takeRequest(5, TimeUnit.SECONDS);
    assertNotNull(recordedRequest, "Handshake probably failed");
    assertEquals(recordedRequest.getTlsVersion().javaName(), "TLSv1.3");
    checkRequest(recordedRequest, queryCompleteEventJson);
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) EventListener(io.trino.spi.eventlistener.EventListener) Test(org.testng.annotations.Test)

Example 13 with EventListener

use of io.trino.spi.eventlistener.EventListener in project trino by trinodb.

the class TestHttpEventListener method testAllLoggingEnabledShouldSendCorrectEvent.

@Test
public void testAllLoggingEnabledShouldSendCorrectEvent() throws Exception {
    EventListener eventListener = factory.create(Map.of("http-event-listener.connect-ingest-uri", server.url("/").toString(), "http-event-listener.log-completed", "true", "http-event-listener.log-created", "true", "http-event-listener.log-split", "true"));
    server.enqueue(new MockResponse().setResponseCode(200));
    server.enqueue(new MockResponse().setResponseCode(200));
    server.enqueue(new MockResponse().setResponseCode(200));
    eventListener.queryCreated(queryCreatedEvent);
    checkRequest(server.takeRequest(5, TimeUnit.SECONDS), queryCreatedEventJson);
    eventListener.queryCompleted(queryCompleteEvent);
    checkRequest(server.takeRequest(5, TimeUnit.SECONDS), queryCompleteEventJson);
    eventListener.splitCompleted(splitCompleteEvent);
    checkRequest(server.takeRequest(5, TimeUnit.SECONDS), splitCompleteEventJson);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) EventListener(io.trino.spi.eventlistener.EventListener) Test(org.testng.annotations.Test)

Example 14 with EventListener

use of io.trino.spi.eventlistener.EventListener in project trino by trinodb.

the class TestHttpEventListener method testDifferentCertificatesShouldNotSendRequest.

@Test
public void testDifferentCertificatesShouldNotSendRequest() throws Exception {
    setupServerTLSCertificate();
    server.enqueue(new MockResponse().setResponseCode(200));
    EventListener eventListener = factory.create(Map.of("http-event-listener.connect-ingest-uri", server.url("/").toString(), "http-event-listener.log-completed", "true", "http-event-listener.http-client.key-store-path", "src/test/resources/trino-httpquery-test2.p12", "http-event-listener.http-client.key-store-password", "testing-ssl"));
    eventListener.queryCompleted(queryCompleteEvent);
    RecordedRequest recordedRequest = server.takeRequest(5, TimeUnit.SECONDS);
    assertNull(recordedRequest, "Handshake should have failed");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) EventListener(io.trino.spi.eventlistener.EventListener) Test(org.testng.annotations.Test)

Example 15 with EventListener

use of io.trino.spi.eventlistener.EventListener in project trino by trinodb.

the class EventListenerManager method createEventListener.

private EventListener createEventListener(File configFile) {
    log.info("-- Loading event listener %s --", configFile);
    configFile = configFile.getAbsoluteFile();
    Map<String, String> properties = loadEventListenerProperties(configFile);
    String name = properties.remove(EVENT_LISTENER_NAME_PROPERTY);
    checkArgument(!isNullOrEmpty(name), "EventListener plugin configuration for %s does not contain %s", configFile, EVENT_LISTENER_NAME_PROPERTY);
    EventListenerFactory factory = eventListenerFactories.get(name);
    checkArgument(factory != null, "Event listener factory '%s' is not registered. Available factories: %s", name, eventListenerFactories.keySet());
    EventListener eventListener;
    try (ThreadContextClassLoader ignored = new ThreadContextClassLoader(factory.getClass().getClassLoader())) {
        eventListener = factory.create(properties);
    }
    log.info("-- Loaded event listener %s --", configFile);
    return eventListener;
}
Also used : EventListenerFactory(io.trino.spi.eventlistener.EventListenerFactory) EventListener(io.trino.spi.eventlistener.EventListener) ThreadContextClassLoader(io.trino.spi.classloader.ThreadContextClassLoader)

Aggregations

EventListener (io.trino.spi.eventlistener.EventListener)15 Test (org.testng.annotations.Test)12 MockResponse (okhttp3.mockwebserver.MockResponse)10 ThreadContextClassLoader (io.trino.spi.classloader.ThreadContextClassLoader)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)2 Binder (com.google.inject.Binder)2 Injector (com.google.inject.Injector)2 Key (com.google.inject.Key)2 Module (com.google.inject.Module)2 Scopes (com.google.inject.Scopes)2 TypeLiteral (com.google.inject.TypeLiteral)2 Multibinder.newSetBinder (com.google.inject.multibindings.Multibinder.newSetBinder)2 Bootstrap (io.airlift.bootstrap.Bootstrap)2 LifeCycleManager (io.airlift.bootstrap.LifeCycleManager)2 EventModule (io.airlift.event.client.EventModule)2 JsonModule (io.airlift.json.JsonModule)2 CatalogNameModule (io.trino.plugin.base.CatalogNameModule)2 ClassLoaderSafeConnectorPageSinkProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSinkProvider)2 ClassLoaderSafeConnectorPageSourceProvider (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorPageSourceProvider)2 ClassLoaderSafeConnectorSplitManager (io.trino.plugin.base.classloader.ClassLoaderSafeConnectorSplitManager)2