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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations