Search in sources :

Example 1 with NotificationSystem

use of com.github.ambry.notification.NotificationSystem in project ambry by linkedin.

the class VcrServerTest method setup.

@BeforeClass
public static void setup() throws Exception {
    mockClusterAgentsFactory = new MockClusterAgentsFactory(false, true, 1, 1, 2);
    mockClusterMap = mockClusterAgentsFactory.getClusterMap();
    notificationSystem = mock(NotificationSystem.class);
}
Also used : MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) NotificationSystem(com.github.ambry.notification.NotificationSystem) BeforeClass(org.junit.BeforeClass)

Example 2 with NotificationSystem

use of com.github.ambry.notification.NotificationSystem in project ambry by linkedin.

the class RestServerTest method badArgumentsTest.

// serverCreationWithBadInputTest() helpers
/**
 * Tests {@link RestServer} instantiation attempts with bad input.
 * @throws Exception
 * @throws IOException
 */
private void badArgumentsTest() throws Exception {
    // dud properties. server should pick up defaults
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = new VerifiableProperties(properties);
    ClusterMap clusterMap = new MockClusterMap();
    NotificationSystem notificationSystem = new LoggingNotificationSystem();
    try {
        // no props.
        new RestServer(null, clusterMap, notificationSystem, SSL_FACTORY);
        fail("Properties missing, yet no exception was thrown");
    } catch (IllegalArgumentException e) {
    // nothing to do. expected.
    }
    try {
        // no ClusterMap.
        new RestServer(verifiableProperties, null, notificationSystem, SSL_FACTORY);
        fail("ClusterMap missing, yet no exception was thrown");
    } catch (IllegalArgumentException e) {
    // nothing to do. expected.
    }
    try {
        // no NotificationSystem.
        new RestServer(verifiableProperties, clusterMap, null, SSL_FACTORY);
        fail("NotificationSystem missing, yet no exception was thrown");
    } catch (IllegalArgumentException e) {
    // nothing to do. expected.
    }
}
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)

Example 3 with NotificationSystem

use of com.github.ambry.notification.NotificationSystem in project ambry by linkedin.

the class RestServerTest method startShutdownTestWithBadComponent.

/**
 * Tests for correct exceptions thrown on {@link RestServer#start()}/{@link RestServer#shutdown()} with bad
 * components.
 * @throws Exception
 */
@Test
public void startShutdownTestWithBadComponent() throws Exception {
    Properties properties = new Properties();
    properties.setProperty("rest.server.nio.server.factory", MockNioServerFactory.class.getCanonicalName());
    // makes MockNioServer throw exceptions.
    properties.setProperty(MockNioServerFactory.IS_FAULTY_KEY, "true");
    VerifiableProperties verifiableProperties = getVProps(properties);
    ClusterMap clusterMap = new MockClusterMap();
    NotificationSystem notificationSystem = new LoggingNotificationSystem();
    RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY);
    try {
        server.start();
        fail("start() should not be successful. MockNioServer::start() would have thrown InstantiationException");
    } catch (InstantiationException e) {
    // nothing to do. expected.
    } finally {
        try {
            server.shutdown();
            fail("RestServer shutdown should have failed.");
        } catch (RuntimeException e) {
        // nothing to do. expected.
        }
    }
}
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 4 with NotificationSystem

use of com.github.ambry.notification.NotificationSystem in project ambry by linkedin.

the class VcrServerTest method testVCRServerWithReporterFactory.

/**
 * Bring up the VCR server and then shut it down with {@link StaticVcrClusterParticipant} and a custom {@link JmxReporter}
 * factory.
 * @throws Exception
 */
@Test
public void testVCRServerWithReporterFactory() throws Exception {
    VerifiableProperties verifiableProperties = getStaticClusterVcrProps();
    ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
    Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
    VcrServer vcrServer = new VcrServer(verifiableProperties, mockClusterAgentsFactory, notificationSystem, reporterFactory);
    vcrServer.startup();
    // check that the custom ObjectNameFactory specified in reporterFactory was used.
    verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
    vcrServer.shutdown();
}
Also used : DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) AfterClass(org.junit.AfterClass) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) SSLFactory(com.github.ambry.commons.SSLFactory) BeforeClass(org.junit.BeforeClass) VerifiableProperties(com.github.ambry.config.VerifiableProperties) TestSSLUtils(com.github.ambry.commons.TestSSLUtils) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) IOException(java.io.IOException) Test(org.junit.Test) Function(java.util.function.Function) File(java.io.File) CloudConfig(com.github.ambry.config.CloudConfig) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Mockito(org.mockito.Mockito) TestUtils(com.github.ambry.utils.TestUtils) HelixControllerManager(com.github.ambry.utils.HelixControllerManager) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) Assert(org.junit.Assert) Collections(java.util.Collections) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) NotificationSystem(com.github.ambry.notification.NotificationSystem) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Test(org.junit.Test)

Example 5 with NotificationSystem

use of com.github.ambry.notification.NotificationSystem 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)

Aggregations

NotificationSystem (com.github.ambry.notification.NotificationSystem)8 VerifiableProperties (com.github.ambry.config.VerifiableProperties)7 Properties (java.util.Properties)7 MockClusterMap (com.github.ambry.clustermap.MockClusterMap)6 ClusterMap (com.github.ambry.clustermap.ClusterMap)5 LoggingNotificationSystem (com.github.ambry.commons.LoggingNotificationSystem)5 Test (org.junit.Test)5 MetricRegistry (com.codahale.metrics.MetricRegistry)2 DefaultObjectNameFactory (com.codahale.metrics.jmx.DefaultObjectNameFactory)2 JmxReporter (com.codahale.metrics.jmx.JmxReporter)2 ObjectNameFactory (com.codahale.metrics.jmx.ObjectNameFactory)2 MockClusterAgentsFactory (com.github.ambry.clustermap.MockClusterAgentsFactory)2 SSLFactory (com.github.ambry.commons.SSLFactory)2 IOException (java.io.IOException)2 Collections (java.util.Collections)2 Function (java.util.function.Function)2 Assert (org.junit.Assert)2 BeforeClass (org.junit.BeforeClass)2 Mockito (org.mockito.Mockito)2 CloudDestinationFactory (com.github.ambry.cloud.CloudDestinationFactory)1