Search in sources :

Example 16 with LoggingNotificationSystem

use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.

the class NonBlockingRouterTest method testNonBlockingRouterFactory.

/**
 * Test the {@link NonBlockingRouterFactory}
 */
@Test
public void testNonBlockingRouterFactory() throws Exception {
    Properties props = getNonBlockingRouterProperties("NotInClusterMap");
    VerifiableProperties verifiableProperties = new VerifiableProperties((props));
    try {
        router = (NonBlockingRouter) new NonBlockingRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null).getRouter();
        Assert.fail("NonBlockingRouterFactory instantiation should have failed because the router datacenter is not in " + "the cluster map");
    } catch (IllegalStateException e) {
    }
    props = getNonBlockingRouterProperties("DC1");
    verifiableProperties = new VerifiableProperties((props));
    router = (NonBlockingRouter) new NonBlockingRouterFactory(verifiableProperties, mockClusterMap, new LoggingNotificationSystem(), null).getRouter();
    assertExpectedThreadCounts(2, 1);
    router.close();
    assertExpectedThreadCounts(0, 0);
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) Test(org.junit.Test)

Example 17 with LoggingNotificationSystem

use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.

the class NonBlockingRouterTest method testRequestResponseHandlerThreadExitFlow.

/**
 * Test RequestResponseHandler thread exit flow. If the RequestResponseHandlerThread exits on its own (due to a
 * Throwable), then the router gets closed immediately along with the completion of all the operations.
 */
@Test
public void testRequestResponseHandlerThreadExitFlow() throws Exception {
    Properties props = getNonBlockingRouterProperties("DC1");
    VerifiableProperties verifiableProperties = new VerifiableProperties((props));
    MockClusterMap mockClusterMap = new MockClusterMap();
    MockTime mockTime = new MockTime();
    router = new NonBlockingRouter(new RouterConfig(verifiableProperties), new NonBlockingRouterMetrics(mockClusterMap), new MockNetworkClientFactory(verifiableProperties, mockSelectorState, MAX_PORTS_PLAIN_TEXT, MAX_PORTS_SSL, CHECKOUT_TIMEOUT_MS, new MockServerLayout(mockClusterMap), mockTime), new LoggingNotificationSystem(), mockClusterMap, kms, cryptoService, cryptoJobHandler, mockTime);
    assertExpectedThreadCounts(2, 1);
    setOperationParams();
    mockSelectorState.set(MockSelectorState.ThrowExceptionOnAllPoll);
    Future future = router.putBlob(putBlobProperties, putUserMetadata, putChannel);
    try {
        while (!future.isDone()) {
            mockTime.sleep(1000);
            Thread.yield();
        }
        future.get();
        Assert.fail("The operation should have failed");
    } catch (ExecutionException e) {
        Assert.assertEquals(RouterErrorCode.OperationTimedOut, ((RouterException) e.getCause()).getErrorCode());
    }
    setOperationParams();
    mockSelectorState.set(MockSelectorState.ThrowThrowableOnSend);
    future = router.putBlob(putBlobProperties, putUserMetadata, putChannel);
    Thread requestResponseHandlerThreadRegular = TestUtils.getThreadByThisName("RequestResponseHandlerThread-0");
    Thread requestResponseHandlerThreadBackground = TestUtils.getThreadByThisName("RequestResponseHandlerThread-backgroundDeleter");
    if (requestResponseHandlerThreadRegular != null) {
        requestResponseHandlerThreadRegular.join(NonBlockingRouter.SHUTDOWN_WAIT_MS);
    }
    if (requestResponseHandlerThreadBackground != null) {
        requestResponseHandlerThreadBackground.join(NonBlockingRouter.SHUTDOWN_WAIT_MS);
    }
    try {
        future.get();
        Assert.fail("The operation should have failed");
    } catch (ExecutionException e) {
        Assert.assertEquals(RouterErrorCode.RouterClosed, ((RouterException) e.getCause()).getErrorCode());
    }
    assertClosed();
    // Ensure that both operations failed and with the right exceptions.
    Assert.assertEquals("No ChunkFiller Thread should be running after the router is closed", 0, TestUtils.numThreadsByThisName("ChunkFillerThread"));
    Assert.assertEquals("No RequestResponseHandler should be running after the router is closed", 0, TestUtils.numThreadsByThisName("RequestResponseHandlerThread"));
    Assert.assertEquals("All operations should have completed", 0, router.getOperationsCount());
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) BlobProperties(com.github.ambry.messageformat.BlobProperties) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) RouterConfig(com.github.ambry.config.RouterConfig) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) Future(java.util.concurrent.Future) ExecutionException(java.util.concurrent.ExecutionException) MockTime(com.github.ambry.utils.MockTime) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 18 with LoggingNotificationSystem

use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.

the class RestServerTest method startShutdownTest.

/**
 * Tests {@link RestServer#start()} and {@link RestServer#shutdown()}.
 * @throws Exception
 */
@Test
public void startShutdownTest() throws Exception {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = getVProps(properties);
    ClusterMap clusterMap = new MockClusterMap();
    NotificationSystem notificationSystem = new LoggingNotificationSystem();
    RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY);
    server.start();
    server.shutdown();
    server.awaitShutdown();
}
Also used : ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) NotificationSystem(com.github.ambry.notification.NotificationSystem) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 19 with LoggingNotificationSystem

use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.

the class RestServerTest method shutdownWithoutStartTest.

/**
 * Tests for {@link RestServer#shutdown()} when {@link RestServer#start()} had not been called previously. This test
 * is for cases where {@link RestServer#start()} has failed and {@link RestServer#shutdown()} needs to be run.
 * @throws Exception
 */
@Test
public void shutdownWithoutStartTest() throws Exception {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = getVProps(properties);
    ClusterMap clusterMap = new MockClusterMap();
    NotificationSystem notificationSystem = new LoggingNotificationSystem();
    RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY);
    server.shutdown();
    server.awaitShutdown();
}
Also used : ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) NotificationSystem(com.github.ambry.notification.NotificationSystem) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 20 with LoggingNotificationSystem

use of com.github.ambry.commons.LoggingNotificationSystem in project ambry by linkedin.

the class RestServerTest method doBadFactoryClassTest.

/**
 * Tests for bad factory class name for {@code configKey} in {@link RestServer}.
 * @param configKey the property whose value is the bad factory class
 * @throws Exception
 */
private void doBadFactoryClassTest(String configKey) throws Exception {
    Properties properties = new Properties();
    setMandatoryValues(properties);
    // Non existent class.
    properties.setProperty(configKey, "non.existent.factory");
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    try {
        new RestServer(verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), SSL_FACTORY);
        fail("Properties file contained non existent " + configKey + ", yet no exception was thrown");
    } catch (ClassNotFoundException e) {
    // nothing to do. expected.
    }
    // invalid factory class.
    properties.setProperty(configKey, RestServerTest.class.getCanonicalName());
    verifiableProperties = new VerifiableProperties(properties);
    try {
        new RestServer(verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), SSL_FACTORY);
        fail("Properties file contained invalid " + configKey + " class, yet no exception was thrown");
    } catch (NullPointerException e) {
    // nothing to do. expected.
    }
    // faulty factory class
    properties.setProperty(configKey, FaultyFactory.class.getCanonicalName());
    verifiableProperties = new VerifiableProperties(properties);
    try {
        RestServer restServer = new RestServer(verifiableProperties, new MockClusterMap(), new LoggingNotificationSystem(), SSL_FACTORY);
        restServer.start();
        fail("Properties file contained faulty " + configKey + " class, yet no exception was thrown");
    } catch (InstantiationException e) {
    // nothing to do. expected.
    }
}
Also used : VerifiableProperties(com.github.ambry.config.VerifiableProperties) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) MockClusterMap(com.github.ambry.clustermap.MockClusterMap)

Aggregations

LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)22 VerifiableProperties (com.github.ambry.config.VerifiableProperties)19 Properties (java.util.Properties)14 Test (org.junit.Test)14 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)13 RouterConfig (com.github.ambry.config.RouterConfig)11 BlobProperties (com.github.ambry.messageformat.BlobProperties)11 MockTime (com.github.ambry.utils.MockTime)7 ArrayList (java.util.ArrayList)6 ClusterMap (com.github.ambry.clustermap.ClusterMap)5 NotificationSystem (com.github.ambry.notification.NotificationSystem)4 IOException (java.io.IOException)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 ByteBufferReadableStreamChannel (com.github.ambry.commons.ByteBufferReadableStreamChannel)3 ResponseHandler (com.github.ambry.commons.ResponseHandler)3 ServerErrorCode (com.github.ambry.commons.ServerErrorCode)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 BlobId (com.github.ambry.commons.BlobId)2 SSLFactory (com.github.ambry.commons.SSLFactory)2 KMSConfig (com.github.ambry.config.KMSConfig)2