Search in sources :

Example 1 with JmxRemoteComponent

use of com.adaptris.core.management.jmx.JmxRemoteComponent in project interlok by adaptris.

the class JmxConnectionTest method testRemoteJmx_Retry.

@Test
public void testRemoteJmx_Retry() throws Exception {
    Integer port = PortManager.nextUnusedPort(23456);
    final JmxRemoteComponent jmxr = new JmxRemoteComponent();
    JmxConnection conn = new JmxConnection();
    try {
        jmxr.init(createProperties(port));
        conn.withJmxServiceUrl(JMXMP_PREFIX + port);
        conn.setConnectionRetryInterval(new TimeInterval(1L, TimeUnit.SECONDS));
        conn.setConnectionAttempts(10);
        Executors.newSingleThreadScheduledExecutor().schedule(new Runnable() {

            @Override
            public void run() {
                try {
                    jmxr.start();
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
        }, 2, TimeUnit.SECONDS);
        LifecycleHelper.prepare(conn);
        LifecycleHelper.init(conn);
        assertNotNull(conn.mbeanServerConnection());
    } finally {
        LifecycleHelper.stopAndClose(conn);
        PortManager.release(port);
        destroy(jmxr);
    }
}
Also used : JmxRemoteComponent(com.adaptris.core.management.jmx.JmxRemoteComponent) TimeInterval(com.adaptris.util.TimeInterval) CoreException(com.adaptris.core.CoreException) Test(org.junit.Test)

Example 2 with JmxRemoteComponent

use of com.adaptris.core.management.jmx.JmxRemoteComponent in project interlok by adaptris.

the class JmxConnectionTest method testRemoteJmx.

@Test
public void testRemoteJmx() throws Exception {
    Integer port = PortManager.nextUnusedPort(12345);
    JmxRemoteComponent jmxr = new JmxRemoteComponent();
    JmxConnection conn = new JmxConnection();
    try {
        jmxr.init(createProperties(port));
        jmxr.start();
        conn.withJmxServiceUrl(JMXMP_PREFIX + port);
        conn.setConnectionRetryInterval(new TimeInterval(2L, TimeUnit.SECONDS));
        conn.setAdditionalDebug(true);
        conn.setConnectionAttempts(5);
        LifecycleHelper.prepare(conn);
        LifecycleHelper.init(conn);
        assertNotNull(conn.mbeanServerConnection());
    } finally {
        LifecycleHelper.stopAndClose(conn);
        PortManager.release(port);
        destroy(jmxr);
    }
}
Also used : JmxRemoteComponent(com.adaptris.core.management.jmx.JmxRemoteComponent) TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 3 with JmxRemoteComponent

use of com.adaptris.core.management.jmx.JmxRemoteComponent in project interlok by adaptris.

the class JmxConnectionTest method testRemoteJMX_WithAuthentication.

@Test
public void testRemoteJMX_WithAuthentication() throws Exception {
    Integer port = PortManager.nextUnusedPort(45678);
    JmxRemoteComponent jmxr = new JmxRemoteComponent();
    JmxConnection conn = new JmxConnection();
    try {
        jmxr.init(createProperties(port, DEFAULT_USERNAME_PASSWORD, DEFAULT_USERNAME_PASSWORD));
        jmxr.start();
        conn.withJmxServiceUrl(JMXMP_PREFIX + port).withUsername(DEFAULT_USERNAME_PASSWORD).withPassword(DEFAULT_USERNAME_PASSWORD);
        conn.setConnectionRetryInterval(new TimeInterval(2L, TimeUnit.SECONDS));
        conn.setAdditionalDebug(true);
        conn.setConnectionAttempts(5);
        LifecycleHelper.prepare(conn);
        LifecycleHelper.init(conn);
        assertNotNull(conn.mbeanServerConnection());
    } finally {
        LifecycleHelper.stopAndClose(conn);
        PortManager.release(port);
        destroy(jmxr);
    }
}
Also used : JmxRemoteComponent(com.adaptris.core.management.jmx.JmxRemoteComponent) TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Example 4 with JmxRemoteComponent

use of com.adaptris.core.management.jmx.JmxRemoteComponent in project interlok by adaptris.

the class JmxConnectionTest method testRemoteJMX_WithAuthentication_AndEnv.

@Test
public void testRemoteJMX_WithAuthentication_AndEnv() throws Exception {
    Integer port = PortManager.nextUnusedPort(56789);
    JmxRemoteComponent jmxr = new JmxRemoteComponent();
    JmxConnection conn = new JmxConnection();
    conn.getJmxProperties().add(new KeyValuePair(JMX_REMOTE_PROFILES, SASL_PLAIN));
    try {
        jmxr.init(createProperties(port, DEFAULT_USERNAME_PASSWORD, DEFAULT_USERNAME_PASSWORD));
        jmxr.start();
        conn.setJmxServiceUrl(JMXMP_PREFIX + port);
        conn.setUsername(DEFAULT_USERNAME_PASSWORD);
        conn.setPassword(DEFAULT_USERNAME_PASSWORD);
        conn.setConnectionRetryInterval(new TimeInterval(2L, TimeUnit.SECONDS));
        conn.setAdditionalDebug(true);
        conn.setConnectionAttempts(5);
        LifecycleHelper.prepare(conn);
        LifecycleHelper.init(conn);
        assertNotNull(conn.mbeanServerConnection());
    } finally {
        LifecycleHelper.stopAndClose(conn);
        PortManager.release(port);
        destroy(jmxr);
    }
}
Also used : JmxRemoteComponent(com.adaptris.core.management.jmx.JmxRemoteComponent) KeyValuePair(com.adaptris.util.KeyValuePair) TimeInterval(com.adaptris.util.TimeInterval) Test(org.junit.Test)

Aggregations

JmxRemoteComponent (com.adaptris.core.management.jmx.JmxRemoteComponent)4 TimeInterval (com.adaptris.util.TimeInterval)4 Test (org.junit.Test)4 CoreException (com.adaptris.core.CoreException)1 KeyValuePair (com.adaptris.util.KeyValuePair)1