use of com.googlecode.jmxtrans.connections.JmxConnectionProvider in project jmxtrans by jmxtrans.
the class ServerTests method testConnectionRepoolingSkippedOnError_andConnectionIsClosed.
@Test
public void testConnectionRepoolingSkippedOnError_andConnectionIsClosed() 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);
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 com.googlecode.jmxtrans.connections.JmxConnectionProvider 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 com.googlecode.jmxtrans.connections.JmxConnectionProvider 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);
}
Aggregations