Search in sources :

Example 1 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class MessageMetricsStatisticsByMetadataTest method testGetMessageStatistics.

@Override
public void testGetMessageStatistics() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    String payload = "SomePayload";
    MessageMetricsInterceptorByMetadata interceptor = createInterceptor();
    interceptor.setUniqueId(getName());
    Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName workflowObj = createWorkflowObjectName(adapterName);
        ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
        MessageMetricsStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj, MessageMetricsStatisticsMBean.class);
        MessageProcessor workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        workflow.processAsync(createMessageForInjection(payload));
        assertEquals(1, stats.getStatistics().size());
        assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
        MessageStatistic interceptorStat = (MessageStatistic) interceptor.getStats().get(0);
        MessageStatistic mbeanStat = stats.getStatistics().get(0);
        // They're not objectively equals (not clones), and no equals method.
        assertNotSame(interceptorStat, mbeanStat);
        assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
        assertEquals(interceptorStat.getTotalMessageCount(), mbeanStat.getTotalMessageCount());
        assertEquals(interceptorStat.getTotalMessageErrorCount(), mbeanStat.getTotalMessageErrorCount());
        assertEquals(interceptorStat.getTotalMessageSize(), mbeanStat.getTotalMessageSize());
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName)

Example 2 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class MessageMetricsStatisticsTest method testGetMessageStatistics.

@Test
public void testGetMessageStatistics() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    String payload = "SomePayload";
    MessageMetricsInterceptor interceptor = (MessageMetricsInterceptor) createInterceptor();
    interceptor.setUniqueId(getName());
    Adapter adapter = createSingleChannelAdapter(adapterName, interceptor);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName workflowObj = createWorkflowObjectName(adapterName);
        ObjectName metricsObj = createMetricsObjectName(adapterName, getName());
        MessageMetricsStatisticsMBean stats = JMX.newMBeanProxy(mBeanServer, metricsObj, MessageMetricsStatisticsMBean.class);
        MessageProcessor workflow = JMX.newMBeanProxy(mBeanServer, workflowObj, MessageProcessor.class);
        workflow.processAsync(createMessageForInjection(payload));
        assertEquals(1, stats.getStatistics().size());
        assertEquals(interceptor.getStats().size(), stats.getStatistics().size());
        MessageStatistic interceptorStat = (MessageStatistic) interceptor.getStats().get(0);
        MessageStatistic mbeanStat = stats.getStatistics().get(0);
        // They're not objectively equals (not clones), and no equals method.
        assertNotSame(interceptorStat, mbeanStat);
        assertEquals(interceptorStat.getEndMillis(), mbeanStat.getEndMillis());
        assertEquals(interceptorStat.getTotalMessageCount(), mbeanStat.getTotalMessageCount());
        assertEquals(interceptorStat.getTotalMessageErrorCount(), mbeanStat.getTotalMessageErrorCount());
        assertEquals(interceptorStat.getTotalMessageSize(), mbeanStat.getTotalMessageSize());
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) MessageProcessor(com.adaptris.interlok.management.MessageProcessor) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 3 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class MessageMetricsStatisticsTest method testNoCachesExists.

@Test
public void testNoCachesExists() throws Exception {
    String adapterName = this.getClass().getSimpleName() + "." + getName();
    Adapter adapter = createAdapter(adapterName);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    try {
        start(adapter);
        register(mBeans);
        ObjectName adapterObj = createAdapterObjectName(adapterName);
        ObjectName metricsObj = createMetricsObjectName(adapterName);
        MessageMetricsStatisticsMBean metrics = JMX.newMBeanProxy(mBeanServer, metricsObj, MessageMetricsStatisticsMBean.class);
        assertEquals(0, metrics.getNumberOfTimeSlices());
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) Adapter(com.adaptris.core.Adapter) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 4 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class MessageNotificationCase method register.

protected void register(Collection<BaseComponentMBean> mBeans) throws Exception {
    for (BaseComponentMBean bean : mBeans) {
        ObjectName name = bean.createObjectName();
        registeredObjects.add(name);
        mBeanServer.registerMBean(bean, name);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) ObjectName(javax.management.ObjectName)

Example 5 with BaseComponentMBean

use of com.adaptris.core.runtime.BaseComponentMBean in project interlok by adaptris.

the class SlowMessageNotificationTest method testNotification_SentAsPartOfCleanup.

@Test
public void testNotification_SentAsPartOfCleanup() throws Exception {
    SlowMessageNotification notif = new SlowMessageNotification(getName(), new TimeInterval(100L, TimeUnit.MILLISECONDS), new TimeInterval(200L, TimeUnit.MILLISECONDS));
    StandardWorkflow workflow = createWorkflow(getName() + "_Workflow", notif);
    workflow.getServiceCollection().add(new WaitService(new TimeInterval(500L, TimeUnit.MILLISECONDS)));
    Adapter adapter = createAdapter(getName(), workflow);
    List<BaseComponentMBean> mBeans = createJmxManagers(adapter);
    BaseComponentMBean notifier = getFirstImpl(mBeans, InterceptorNotificationMBean.class);
    assertNotNull(notifier);
    ObjectName notifObjName = notifier.createObjectName();
    SimpleNotificationListener listener = new SimpleNotificationListener();
    try {
        start(adapter);
        register(mBeans);
        mBeanServer.addNotificationListener(notifObjName, listener, null, null);
        AdaptrisMessage msg = AdaptrisMessageFactory.getDefaultInstance().newMessage();
        workflow.onAdaptrisMessage(msg);
        listener.waitForMessages(1);
        assertEquals(1, listener.getNotifications().size());
        Notification notification = listener.getNotifications().get(0);
        Properties userData = (Properties) notification.getUserData();
        assertEquals(msg.getUniqueId(), userData.getProperty(SlowMessageNotification.KEY_MESSAGE_ID));
        assertEquals("-1", userData.getProperty(SlowMessageNotification.KEY_MESSAGE_DURATION));
        assertEquals("-1", userData.getProperty(SlowMessageNotification.KEY_MESSAGE_END));
        assertEquals("false", userData.getProperty(SlowMessageNotification.KEY_MESSAGE_SUCCESS));
    } finally {
        stop(adapter);
    }
}
Also used : BaseComponentMBean(com.adaptris.core.runtime.BaseComponentMBean) WaitService(com.adaptris.core.services.WaitService) StandardWorkflow(com.adaptris.core.StandardWorkflow) TimeInterval(com.adaptris.util.TimeInterval) AdaptrisMessage(com.adaptris.core.AdaptrisMessage) SimpleNotificationListener(com.adaptris.core.runtime.SimpleNotificationListener) Adapter(com.adaptris.core.Adapter) Properties(java.util.Properties) Notification(javax.management.Notification) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Aggregations

BaseComponentMBean (com.adaptris.core.runtime.BaseComponentMBean)29 ObjectName (javax.management.ObjectName)26 Adapter (com.adaptris.core.Adapter)25 Test (org.junit.Test)24 AdaptrisMessage (com.adaptris.core.AdaptrisMessage)16 StandardWorkflow (com.adaptris.core.StandardWorkflow)16 SimpleNotificationListener (com.adaptris.core.runtime.SimpleNotificationListener)16 Notification (javax.management.Notification)10 TimeInterval (com.adaptris.util.TimeInterval)9 Properties (java.util.Properties)6 WorkflowManagerMBean (com.adaptris.core.runtime.WorkflowManagerMBean)5 SerializableAdaptrisMessage (com.adaptris.core.SerializableAdaptrisMessage)3 AdapterManager (com.adaptris.core.runtime.AdapterManager)3 AlwaysFailService (com.adaptris.core.services.AlwaysFailService)3 WaitService (com.adaptris.core.services.WaitService)3 MessageProcessor (com.adaptris.interlok.management.MessageProcessor)2 ArrayList (java.util.ArrayList)2 ChildRuntimeInfoComponent (com.adaptris.core.runtime.ChildRuntimeInfoComponent)1