Search in sources :

Example 6 with EventListener

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

the class TestHttpEventListener method testNoServerCertificateShouldNotSendRequest.

@Test
public void testNoServerCertificateShouldNotSendRequest() throws Exception {
    server.enqueue(new MockResponse().setResponseCode(200));
    EventListener eventListener = factory.create(Map.of("http-event-listener.connect-ingest-uri", new URL("https", server.getHostName(), server.getPort(), "/").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);
    assertNull(recordedRequest, "Handshake should have failed");
}
Also used : RecordedRequest(okhttp3.mockwebserver.RecordedRequest) MockResponse(okhttp3.mockwebserver.MockResponse) EventListener(io.trino.spi.eventlistener.EventListener) URL(java.net.URL) Test(org.testng.annotations.Test)

Example 7 with EventListener

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

the class TestHttpEventListener method testServerDelayDoesNotBlock.

@Test
public void testServerDelayDoesNotBlock() throws Exception {
    EventListener eventListener = factory.create(Map.of("http-event-listener.connect-ingest-uri", server.url("/").toString(), "http-event-listener.log-completed", "true"));
    server.enqueue(new MockResponse().setResponseCode(200).setHeadersDelay(5, TimeUnit.SECONDS));
    long startTime = System.nanoTime();
    eventListener.queryCompleted(queryCompleteEvent);
    long endTime = System.nanoTime();
    assertTrue(Duration.of(endTime - startTime, ChronoUnit.NANOS).compareTo(Duration.of(1, ChronoUnit.SECONDS)) < 0, "Server delay is blocking main thread");
    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 8 with EventListener

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

the class TestHttpEventListener method testAllLoggingDisabledShouldTimeout.

/**
 * Listener created without exceptions but not requests sent
 */
@Test
public void testAllLoggingDisabledShouldTimeout() throws Exception {
    server.enqueue(new MockResponse().setResponseCode(200));
    EventListener eventListener = factory.create(Map.of("http-event-listener.connect-ingest-uri", server.url("/").toString()));
    eventListener.queryCreated(null);
    eventListener.queryCompleted(null);
    eventListener.splitCompleted(null);
    assertNull(server.takeRequest(5, TimeUnit.SECONDS));
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) EventListener(io.trino.spi.eventlistener.EventListener) Test(org.testng.annotations.Test)

Example 9 with EventListener

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

the class TestAccessControlManager method testRegisterSingleEventListener.

@Test
public void testRegisterSingleEventListener() throws IOException {
    EventListener expectedListener = new EventListener() {
    };
    String systemAccessControlName = "event-listening-sac";
    TestingEventListenerManager eventListenerManager = emptyEventListenerManager();
    AccessControlManager accessControlManager = createAccessControlManager(eventListenerManager, ImmutableList.of("access-control.name=" + systemAccessControlName));
    accessControlManager.addSystemAccessControlFactory(eventListeningSystemAccessControlFactory(systemAccessControlName, expectedListener));
    accessControlManager.loadSystemAccessControl();
    assertThat(eventListenerManager.getConfiguredEventListeners()).contains(expectedListener);
}
Also used : TestingEventListenerManager(io.trino.testing.TestingEventListenerManager) EventListener(io.trino.spi.eventlistener.EventListener) Test(org.testng.annotations.Test)

Example 10 with EventListener

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

the class TestHttpEventListener method testHttpHeadersShouldBePresent.

@Test
public void testHttpHeadersShouldBePresent() 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-http-headers", "Authorization: Trust Me!, Cache-Control: no-cache"));
    server.enqueue(new MockResponse().setResponseCode(200));
    eventListener.queryCompleted(queryCompleteEvent);
    checkRequest(server.takeRequest(5, TimeUnit.SECONDS), Map.of("Authorization", "Trust Me!", "Cache-Control", "no-cache"), queryCompleteEventJson);
}
Also used : MockResponse(okhttp3.mockwebserver.MockResponse) EventListener(io.trino.spi.eventlistener.EventListener) Test(org.testng.annotations.Test)

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