Search in sources :

Example 86 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedSuspendedServiceTest method testConsumeSuspendAndResumeFile.

public void testConsumeSuspendAndResumeFile() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    MBeanServer mbeanServer = getMBeanServer();
    Set<ObjectName> set = mbeanServer.queryNames(new ObjectName("*:type=consumers,*"), null);
    assertEquals(1, set.size());
    ObjectName on = set.iterator().next();
    boolean registered = mbeanServer.isRegistered(on);
    assertEquals("Should be registered", true, registered);
    Boolean ss = (Boolean) mbeanServer.getAttribute(on, "SupportSuspension");
    assertEquals(true, ss.booleanValue());
    Boolean suspended = (Boolean) mbeanServer.getAttribute(on, "Suspended");
    assertEquals(false, suspended.booleanValue());
    MockEndpoint mock = getMockEndpoint("mock:result");
    mock.expectedMessageCount(1);
    template.sendBodyAndHeader("file://target/suspended", "Bye World", Exchange.FILE_NAME, "bye.txt");
    template.sendBodyAndHeader("file://target/suspended", "Hello World", Exchange.FILE_NAME, "hello.txt");
    assertMockEndpointsSatisfied();
    Thread.sleep(1000);
    // now its suspended by the policy
    suspended = (Boolean) mbeanServer.getAttribute(on, "Suspended");
    assertEquals(true, suspended.booleanValue());
    // the route is suspended by the policy so we should only receive one
    String[] files = new File("target/suspended/").list();
    assertNotNull(files);
    assertEquals("The file should exists", 1, files.length);
    // reset mock
    mock.reset();
    mock.expectedMessageCount(1);
    // now resume it
    mbeanServer.invoke(on, "resume", null, null);
    assertMockEndpointsSatisfied();
    suspended = (Boolean) mbeanServer.getAttribute(on, "Suspended");
    assertEquals(false, suspended.booleanValue());
    Thread.sleep(500);
    // and the file is now deleted
    files = new File("target/suspended/").list();
    assertNotNull(files);
    assertEquals("The file should exists", 0, files.length);
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) File(java.io.File) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 87 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedThrottlerTest method testThrottleAsyncExceptionVisableViaJmx.

public void testThrottleAsyncExceptionVisableViaJmx() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    if (isPlatform("windows")) {
        // windows needs more sleep to read updated jmx values so we skip as we dont want further delays in core tests
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler4\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route4\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    getMockEndpoint("mock:endAsyncException").expectedMessageCount(10);
    NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCountAsyncException").whenReceived(5).create();
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCountAsyncException", "Message " + i);
    }
    assertTrue(notifier.matches(2, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
    // give a sec for exception handling to finish..
    Thread.sleep(500);
    // since all exchanges ended w/ exception, they are not completed
    Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(0, completed.longValue());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 88 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedThrottlerTest method testRejectedExecutionCallerRuns.

public void testRejectedExecutionCallerRuns() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler2\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    MockEndpoint mock = getMockEndpoint("mock:endAsyncRejectCallerRuns");
    // only one message (the first one) should get through because the rest should get delayed
    mock.expectedMessageCount(10);
    MockEndpoint exceptionMock = getMockEndpoint("mock:rejectedExceptionEndpoint");
    exceptionMock.expectedMessageCount(0);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCountRejectExecutionCallerRuns", "Message " + i);
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 89 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedThrottlerTest method testThrottleVisableViaJmx.

public void testThrottleVisableViaJmx() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    if (isPlatform("windows")) {
        // windows needs more sleep to read updated jmx values so we skip as we dont want further delays in core tests
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler2\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    getMockEndpoint("mock:end").expectedMessageCount(10);
    NotifyBuilder notifier = new NotifyBuilder(context).from("seda:throttleCount").whenReceived(5).create();
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCount", "Message " + i);
    }
    assertTrue(notifier.matches(2, TimeUnit.SECONDS));
    assertMockEndpointsSatisfied();
    Long completed = (Long) mbeanServer.getAttribute(routeName, "ExchangesCompleted");
    assertEquals(10, completed.longValue());
}
Also used : NotifyBuilder(org.apache.camel.builder.NotifyBuilder) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Example 90 with ObjectName

use of javax.management.ObjectName in project camel by apache.

the class ManagedThrottlerTest method testRejectedExecution.

public void testRejectedExecution() throws Exception {
    // JMX tests dont work well on AIX CI servers (hangs them)
    if (isPlatform("aix")) {
        return;
    }
    // get the stats for the route
    MBeanServer mbeanServer = getMBeanServer();
    // get the object name for the delayer
    ObjectName throttlerName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=processors,name=\"mythrottler2\"");
    // use route to get the total time
    ObjectName routeName = ObjectName.getInstance("org.apache.camel:context=camel-1,type=routes,name=\"route2\"");
    // reset the counters
    mbeanServer.invoke(routeName, "reset", null, null);
    MockEndpoint mock = getMockEndpoint("mock:endAsyncReject");
    // only one message (the first one) should get through because the rest should get delayed
    mock.expectedMessageCount(1);
    MockEndpoint exceptionMock = getMockEndpoint("mock:rejectedExceptionEndpoint1");
    exceptionMock.expectedMessageCount(9);
    for (int i = 0; i < 10; i++) {
        template.sendBody("seda:throttleCountRejectExecution", "Message " + i);
    }
    assertMockEndpointsSatisfied();
}
Also used : MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MockEndpoint(org.apache.camel.component.mock.MockEndpoint) MBeanServer(javax.management.MBeanServer) ObjectName(javax.management.ObjectName)

Aggregations

ObjectName (javax.management.ObjectName)1515 MBeanServer (javax.management.MBeanServer)691 Test (org.junit.Test)258 MalformedObjectNameException (javax.management.MalformedObjectNameException)168 IOException (java.io.IOException)101 HashMap (java.util.HashMap)99 MockEndpoint (org.apache.camel.component.mock.MockEndpoint)97 Attribute (javax.management.Attribute)94 InstanceNotFoundException (javax.management.InstanceNotFoundException)94 ArrayList (java.util.ArrayList)91 MBeanServerConnection (javax.management.MBeanServerConnection)72 Map (java.util.Map)66 SystemManagementService (org.apache.geode.management.internal.SystemManagementService)66 MBeanInfo (javax.management.MBeanInfo)64 TabularData (javax.management.openmbean.TabularData)55 JMXServiceURL (javax.management.remote.JMXServiceURL)55 MBeanRegistrationException (javax.management.MBeanRegistrationException)53 JMXConnector (javax.management.remote.JMXConnector)53 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)48 Notification (javax.management.Notification)47