Search in sources :

Example 11 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jmxtrans by jmxtrans.

the class JMXConnectionTest method connectorIsClosed.

@Test
public void connectorIsClosed() throws IOException {
    MBeanServerConnection mBeanServerConnection = mock(MBeanServerConnection.class);
    JMXConnector jmxConnector = mock(JMXConnector.class);
    JMXConnection jmxConnection = new JMXConnection(jmxConnector, mBeanServerConnection);
    jmxConnection.close();
    verify(jmxConnector).close();
}
Also used : JMXConnection(com.googlecode.jmxtrans.connections.JMXConnection) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 12 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jmxtrans by jmxtrans.

the class ServerTests method testConnectionRepoolingOk.

@Test
public void testConnectionRepoolingOk() throws Exception {
    @SuppressWarnings("unchecked") GenericKeyedObjectPool<JmxConnectionProvider, JMXConnection> pool = mock(GenericKeyedObjectPool.class);
    Server server = Server.builder().setHost("host.example.net").setPort("4321").setLocal(true).setPool(pool).build();
    MBeanServerConnection mBeanConn = mock(MBeanServerConnection.class);
    JMXConnection conn = mock(JMXConnection.class);
    when(conn.getMBeanServerConnection()).thenReturn(mBeanConn);
    when(pool.borrowObject(server)).thenReturn(conn);
    Query query = mock(Query.class);
    Iterable<ObjectName> objectNames = Lists.emptyList();
    when(query.queryNames(mBeanConn)).thenReturn(objectNames);
    server.execute(query);
    verify(pool, never()).invalidateObject(server, conn);
    InOrder orderVerifier = inOrder(pool);
    orderVerifier.verify(pool).borrowObject(server);
    orderVerifier.verify(pool).returnObject(server, conn);
}
Also used : JMXConnection(com.googlecode.jmxtrans.connections.JMXConnection) InOrder(org.mockito.InOrder) JmxConnectionProvider(com.googlecode.jmxtrans.connections.JmxConnectionProvider) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName) Test(org.junit.Test)

Example 13 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jmxtrans by jmxtrans.

the class ServerTests method testConnectionRepoolingSkippedOnError_andErrorClosingConnectionIsIgnored.

@Test
public void testConnectionRepoolingSkippedOnError_andErrorClosingConnectionIsIgnored() throws Exception {
    @SuppressWarnings("unchecked") GenericKeyedObjectPool<JmxConnectionProvider, JMXConnection> pool = mock(GenericKeyedObjectPool.class);
    Server server = Server.builder().setHost("host.example.net").setPort("4321").setLocal(true).setPool(pool).build();
    MBeanServerConnection mBeanConn = mock(MBeanServerConnection.class);
    JMXConnection conn = mock(JMXConnection.class);
    when(conn.getMBeanServerConnection()).thenReturn(mBeanConn);
    doThrow(new IOException()).when(conn).close();
    when(pool.borrowObject(server)).thenReturn(conn);
    Query query = mock(Query.class);
    IOException e = mock(IOException.class);
    when(query.queryNames(mBeanConn)).thenThrow(e);
    try {
        server.execute(query);
        fail("No exception got throws");
    } catch (IOException e2) {
        if (e != e2) {
            fail("Wrong exception thrown (" + e + " instead of mock");
        }
    }
    verify(conn).close();
    verify(pool, never()).returnObject(server, conn);
    InOrder orderVerifier = inOrder(pool);
    orderVerifier.verify(pool).borrowObject(server);
    orderVerifier.verify(pool).invalidateObject(server, conn);
}
Also used : JMXConnection(com.googlecode.jmxtrans.connections.JMXConnection) InOrder(org.mockito.InOrder) JmxConnectionProvider(com.googlecode.jmxtrans.connections.JmxConnectionProvider) IOException(java.io.IOException) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 14 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jmxtrans by jmxtrans.

the class MBeanServerConnectionFactoryTest method connectionIsCreatedForRemoteServer.

@Test
public void connectionIsCreatedForRemoteServer() throws IOException {
    JmxConnectionProvider server = mock(JmxConnectionProvider.class);
    JMXConnector jmxConnector = mock(JMXConnector.class);
    MBeanServerConnection mBeanServerConnection = mock(MBeanServerConnection.class);
    when(server.isLocal()).thenReturn(false);
    when(server.getServerConnection()).thenReturn(jmxConnector);
    when(jmxConnector.getMBeanServerConnection()).thenReturn(mBeanServerConnection);
    JMXConnection jmxConnection = factory.makeObject(server);
    assertThat(jmxConnection.getMBeanServerConnection()).isSameAs(mBeanServerConnection);
}
Also used : JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) Test(org.junit.Test)

Example 15 with MBeanServerConnection

use of javax.management.MBeanServerConnection in project jersey by jersey.

the class Main method main.

public static void main(String[] args) throws Exception {
    //      e.g. "service:jmx:rmi:///jndi/rmi://sysifos.cz.oracle.com:11112/jmxrmi"
    final String jmxUrl = args[0];
    //      e.g. "org.glassfish.jersey.test.performance.interceptor.dynamic:type=DynamicallyBoundInterceptorResource,name=gets"
    final String mBeanName = args[1];
    //      e.g. "OneMinuteRate"
    final String mBeanAttrName = args[2];
    //      e.g. 50
    final int sampleCount = Integer.parseInt(args[3]);
    //      e.g. "phishing.properties"
    final String propertiesFile = args[4];
    System.out.printf("JMX URL = %s\nMBean = %s\nattribute = %s\nsamples = %d\nfilename = %s\n" + "Going to connect...\n", jmxUrl, mBeanName, mBeanAttrName, sampleCount, propertiesFile);
    final JMXServiceURL url = new JMXServiceURL(jmxUrl);
    final JMXConnector jmxc = JMXConnectorFactory.connect(url, null);
    final MBeanServerConnection mBeanServer = jmxc.getMBeanServerConnection();
    final ObjectName mBeanObjectName = new ObjectName(mBeanName);
    System.out.println("Connected...");
    double totalSum = 0;
    int samplesTaken = 0;
    for (int i = 0; i < sampleCount; i++) {
        Thread.sleep(5000);
        Double sample = (Double) mBeanServer.getAttribute(mBeanObjectName, mBeanAttrName);
        System.out.printf("OMR[%d]=%f\n", i, sample);
        totalSum += sample;
        samplesTaken++;
    }
    jmxc.close();
    final double result = totalSum / samplesTaken;
    writeResult(result, propertiesFile);
    System.out.printf("\nAverage=%f\n", result);
}
Also used : JMXServiceURL(javax.management.remote.JMXServiceURL) JMXConnector(javax.management.remote.JMXConnector) MBeanServerConnection(javax.management.MBeanServerConnection) ObjectName(javax.management.ObjectName)

Aggregations

MBeanServerConnection (javax.management.MBeanServerConnection)125 JMXConnector (javax.management.remote.JMXConnector)84 ObjectName (javax.management.ObjectName)73 JMXServiceURL (javax.management.remote.JMXServiceURL)59 JMXConnectorServer (javax.management.remote.JMXConnectorServer)38 Test (org.junit.Test)35 IOException (java.io.IOException)31 MBeanServer (javax.management.MBeanServer)28 HashMap (java.util.HashMap)23 Attribute (javax.management.Attribute)15 NotificationListener (javax.management.NotificationListener)13 MalformedURLException (java.net.MalformedURLException)12 ArrayList (java.util.ArrayList)12 Notification (javax.management.Notification)12 MalformedObjectNameException (javax.management.MalformedObjectNameException)11 Map (java.util.Map)10 List (java.util.List)8 RemoteException (java.rmi.RemoteException)7 LocateRegistry (java.rmi.registry.LocateRegistry)7 Registry (java.rmi.registry.Registry)7