Search in sources :

Example 1 with ISimpleMXBean

use of org.apache.camel.component.jmx.beans.ISimpleMXBean in project camel by apache.

the class JMXMonitorTypeCounterTest method counter.

@Test
public void counter() throws Exception {
    ISimpleMXBean simpleBean = getSimpleMXBean();
    // we should get an event after the monitor number reaches 3
    simpleBean.setMonitorNumber(1);
    // this should trigger a notification
    simpleBean.setMonitorNumber(3);
    // we should get 1 change from the counter bean
    getMockFixture().waitForMessages();
    getMockFixture().assertMessageReceived(new File("src/test/resources/monitor-consumer/monitorNotification.xml"));
    // the offset value was two, so another change won't trigger an event. 
    // it'll take 2 more changes to trigger the event
    getMockFixture().getMockEndpoint().setExpectedMessageCount(1);
    simpleBean.setMonitorNumber(4);
    simpleBean.setMonitorNumber(5);
    getMockFixture().waitForMessages();
    getMockFixture().assertMessageReceived(new File("src/test/resources/monitor-consumer/monitorNotification-2.xml"));
}
Also used : File(java.io.File) ISimpleMXBean(org.apache.camel.component.jmx.beans.ISimpleMXBean) Test(org.junit.Test)

Example 2 with ISimpleMXBean

use of org.apache.camel.component.jmx.beans.ISimpleMXBean in project camel by apache.

the class JMXMonitorTypeGaugeTest method gauge.

@Test
public void gauge() throws Exception {
    ISimpleMXBean simpleBean = getSimpleMXBean();
    // we should get an event after the number exceeds 100 or drops below 50
    simpleBean.setMonitorNumber(75);
    simpleBean.setMonitorNumber(110);
    getMockFixture().waitForMessages();
    getMockFixture().assertMessageReceived(new File("src/test/resources/monitor-consumer/gaugeNotification-high.xml"));
    getMockFixture().getMockEndpoint().setExpectedMessageCount(1);
    simpleBean.setMonitorNumber(90);
    Thread.sleep(600);
    simpleBean.setMonitorNumber(60);
    Thread.sleep(600);
    simpleBean.setMonitorNumber(40);
    getMockFixture().waitForMessages();
    getMockFixture().assertMessageReceived(new File("src/test/resources/monitor-consumer/gaugeNotification-low.xml"));
}
Also used : File(java.io.File) ISimpleMXBean(org.apache.camel.component.jmx.beans.ISimpleMXBean) Test(org.junit.Test)

Example 3 with ISimpleMXBean

use of org.apache.camel.component.jmx.beans.ISimpleMXBean in project camel by apache.

the class JMXNotificationFilterTest method testNotificationFilter.

@Test
public void testNotificationFilter() throws Exception {
    ISimpleMXBean bean = getSimpleMXBean();
    assertEquals("no notifications should have been filtered at this point", 0, mRejected.size());
    // we should only get 5 messages, which is 1/2 the number of times we touched the object.
    // The 1/2 is due to the behavior of the test NotificationFilter implemented below 
    getMockFixture().getMockEndpoint().setExpectedMessageCount(5);
    for (int i = 0; i < 10; i++) {
        bean.touch();
    }
    getMockFixture().waitForMessages();
    assertEquals("5 notifications should have been filtered", 5, mRejected.size());
    // assert that all of the rejected ones are odd and accepted ones even
    for (Notification rejected : mRejected) {
        assertEquals(1, rejected.getSequenceNumber() % 2);
    }
    for (Exchange received : getMockFixture().getMockEndpoint().getReceivedExchanges()) {
        Notification n = (Notification) received.getIn().getBody();
        assertEquals(0, n.getSequenceNumber() % 2);
    }
}
Also used : Exchange(org.apache.camel.Exchange) Notification(javax.management.Notification) ISimpleMXBean(org.apache.camel.component.jmx.beans.ISimpleMXBean) Test(org.junit.Test)

Example 4 with ISimpleMXBean

use of org.apache.camel.component.jmx.beans.ISimpleMXBean in project camel by apache.

the class JMXObjectPropertiesTest method testObjectProperties.

@Test
public void testObjectProperties() throws Exception {
    ISimpleMXBean bean = getSimpleMXBean();
    bean.touch();
    getMockFixture().waitForMessages();
}
Also used : ISimpleMXBean(org.apache.camel.component.jmx.beans.ISimpleMXBean) Test(org.junit.Test)

Example 5 with ISimpleMXBean

use of org.apache.camel.component.jmx.beans.ISimpleMXBean in project camel by apache.

the class JMXHandbackTest method test.

@Test
public void test() throws Exception {
    ISimpleMXBean simpleBean = getSimpleMXBean();
    simpleBean.userData("myUserData");
    getMockFixture().waitForMessages();
    Message m = getMockFixture().getMessage(0);
    URI uri = (URI) m.getHeader("jmx.handback");
    assertSame(hb, uri);
}
Also used : Message(org.apache.camel.Message) URI(java.net.URI) ISimpleMXBean(org.apache.camel.component.jmx.beans.ISimpleMXBean) Test(org.junit.Test)

Aggregations

ISimpleMXBean (org.apache.camel.component.jmx.beans.ISimpleMXBean)8 Test (org.junit.Test)8 File (java.io.File)5 URI (java.net.URI)1 Notification (javax.management.Notification)1 Exchange (org.apache.camel.Exchange)1 Message (org.apache.camel.Message)1