| | |
| | | @Test |
| | | public void checkPostConnectDisconnectPlugin() throws Exception |
| | | { |
| | | // Before the test, how many time postconnect and postdisconnect |
| | | // have been called. |
| | | // Before the test, how many time postconnect has been called. |
| | | int postConnectBefore = InvocationCounterPlugin.getPostConnectCount(); |
| | | int postDisconnectBefore = InvocationCounterPlugin.getPostDisconnectCount(); |
| | | |
| | | // Create a new client connection |
| | | HashMap<String, Object> env = new HashMap<>(); |
| | |
| | | } |
| | | assertEquals(postConnectBefore +1, postConnectAfter); |
| | | |
| | | // Check that postDisconnect is not incremented. |
| | | int postDisconnectAfter = InvocationCounterPlugin.getPostDisconnectCount(); |
| | | assertEquals(postDisconnectBefore, postDisconnectAfter); |
| | | // Snapshot the post-disconnect counter just before closing: connections left |
| | | // over from earlier JMX test classes are torn down asynchronously (JMX |
| | | // CLOSED/FAILED notifications), so the counter may move at any time while |
| | | // this test is running. |
| | | int postDisconnectBefore = InvocationCounterPlugin.getPostDisconnectCount(); |
| | | |
| | | // Close the client connection |
| | | opendsConnector.close(); |
| | |
| | | // Check that number of postdisconnect has been incremented. |
| | | // Don't wait more than 5 seconds |
| | | endTime = System.currentTimeMillis() + 5000; |
| | | postDisconnectAfter = postDisconnectBefore; |
| | | int postDisconnectAfter = postDisconnectBefore; |
| | | while (System.currentTimeMillis() < endTime |
| | | && postDisconnectAfter == postDisconnectBefore) |
| | | { |
| | | Thread.sleep(10); |
| | | postDisconnectAfter = InvocationCounterPlugin.getPostDisconnectCount(); |
| | | } |
| | | assertEquals(postDisconnectBefore +1 , postDisconnectAfter); |
| | | // Stray disconnects from earlier test classes may also be counted here, so |
| | | // only require that at least one post-disconnect was recorded. |
| | | assertTrue(postDisconnectAfter > postDisconnectBefore); |
| | | |
| | | // Check that postconnect is not incremented again. |
| | | postConnectAfter = InvocationCounterPlugin.getPostConnectCount(); |