Search in sources :

Example 1 with DefaultObjectNameFactory

use of com.codahale.metrics.jmx.DefaultObjectNameFactory 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 2 with DefaultObjectNameFactory

use of com.codahale.metrics.jmx.DefaultObjectNameFactory in project ambry by linkedin.

the class RestServerTest method startShutdownTestWithReporterFactory.

/**
 * Tests {@link RestServer#start()} and {@link RestServer#shutdown()} with a custom {@link JmxReporter} factory.
 * @throws Exception
 */
@Test
public void startShutdownTestWithReporterFactory() throws Exception {
    Properties properties = new Properties();
    VerifiableProperties verifiableProperties = getVProps(properties);
    ClusterMap clusterMap = new MockClusterMap();
    NotificationSystem notificationSystem = new LoggingNotificationSystem();
    ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
    Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
    RestServer server = new RestServer(verifiableProperties, clusterMap, notificationSystem, SSL_FACTORY, Collections.emptyList(), reporterFactory);
    server.start();
    // check that the custom ObjectNameFactory specified in reporterFactory was used.
    verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
    server.shutdown();
    server.awaitShutdown();
}
Also used : DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) SSLFactory(com.github.ambry.commons.SSLFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) ClusterMap(com.github.ambry.clustermap.ClusterMap) IOException(java.io.IOException) Test(org.junit.Test) Function(java.util.function.Function) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Mockito(org.mockito.Mockito) InMemoryRouterFactory(com.github.ambry.router.InMemoryRouterFactory) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) Assert(org.junit.Assert) Collections(java.util.Collections) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) NotificationSystem(com.github.ambry.notification.NotificationSystem) ClusterMap(com.github.ambry.clustermap.ClusterMap) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) NotificationSystem(com.github.ambry.notification.NotificationSystem) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) JmxReporter(com.codahale.metrics.jmx.JmxReporter) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) MockClusterMap(com.github.ambry.clustermap.MockClusterMap) Test(org.junit.Test)

Example 3 with DefaultObjectNameFactory

use of com.codahale.metrics.jmx.DefaultObjectNameFactory in project ambry by linkedin.

the class AmbryServerTest method testAmbryServerWithReporterFactory.

/**
 * Test starting and shutting down the server with a custom {@link JmxReporter} factory.
 * @throws Exception
 */
@Test
public void testAmbryServerWithReporterFactory() throws Exception {
    ClusterAgentsFactory clusterAgentsFactory = new MockClusterAgentsFactory(false, false, 1, 1, 1);
    ObjectNameFactory spyObjectNameFactory = spy(new DefaultObjectNameFactory());
    Function<MetricRegistry, JmxReporter> reporterFactory = reporter -> JmxReporter.forRegistry(reporter).createsObjectNamesWith(spyObjectNameFactory).build();
    DataNodeId dataNodeId = clusterAgentsFactory.getClusterMap().getDataNodeIds().get(0);
    Properties props = new Properties();
    props.setProperty("host.name", dataNodeId.getHostname());
    props.setProperty("port", Integer.toString(dataNodeId.getPort()));
    props.setProperty("clustermap.cluster.name", "test");
    props.setProperty("clustermap.datacenter.name", "DC1");
    props.setProperty("clustermap.host.name", dataNodeId.getHostname());
    AmbryServer ambryServer = new AmbryServer(new VerifiableProperties(props), clusterAgentsFactory, null, new LoggingNotificationSystem(), SystemTime.getInstance(), reporterFactory);
    ambryServer.startup();
    verify(spyObjectNameFactory, atLeastOnce()).createName(anyString(), anyString(), anyString());
    ambryServer.shutdown();
}
Also used : DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) ClusterAgentsFactory(com.github.ambry.clustermap.ClusterAgentsFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DataNodeId(com.github.ambry.clustermap.DataNodeId) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) Test(org.junit.Test) Function(java.util.function.Function) JmxReporter(com.codahale.metrics.jmx.JmxReporter) Mockito(org.mockito.Mockito) SystemTime(com.github.ambry.utils.SystemTime) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) ObjectNameFactory(com.codahale.metrics.jmx.ObjectNameFactory) MetricRegistry(com.codahale.metrics.MetricRegistry) Properties(java.util.Properties) VerifiableProperties(com.github.ambry.config.VerifiableProperties) DefaultObjectNameFactory(com.codahale.metrics.jmx.DefaultObjectNameFactory) JmxReporter(com.codahale.metrics.jmx.JmxReporter) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) LoggingNotificationSystem(com.github.ambry.commons.LoggingNotificationSystem) ClusterAgentsFactory(com.github.ambry.clustermap.ClusterAgentsFactory) MockClusterAgentsFactory(com.github.ambry.clustermap.MockClusterAgentsFactory) DataNodeId(com.github.ambry.clustermap.DataNodeId) Test(org.junit.Test)

Aggregations

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