Tests that use the post-response plugin invocation counter are subject to race conditions. An earlier test can complete successfully with an operation still running in the server, and this operation changes the values of the invocation counters while subsequent tests are running.
A new method InvocationCounterPlugin#waitForPostResponse can be used in a test to wait until an operation has invoked the post-response plugins, so that the operation doesn't interfere with subsequent tests.
| | |
| | | assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0); |
| | | assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0); |
| | | // The post response might not have been called yet. |
| | | // assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1); |
| | | assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1); |
| | | } finally |
| | | { |
| | | LockManager.unlock(entry.getDN(), writeLock); |
| | |
| | | message.getModifyDNResponseProtocolOp(); |
| | | |
| | | assertEquals(modifyResponse.getResultCode(), 80); |
| | | assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1); |
| | | |
| | | try |
| | | { |
| | |
| | | assertEquals(InvocationCounterPlugin.getPreOperationCount(), 0); |
| | | assertEquals(InvocationCounterPlugin.getPostOperationCount(), 0); |
| | | // The post response might not have been called yet. |
| | | // assertEquals(InvocationCounterPlugin.getPostResponseCount(), 1); |
| | | assertEquals(InvocationCounterPlugin.waitForPostResponse(), 1); |
| | | } finally |
| | | { |
| | | LockManager.unlock(entry.getDN(), writeLock); |
| | |
| | | |
| | | |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.List; |
| | | import java.util.Set; |
| | | import java.util.concurrent.atomic.AtomicInteger; |
| | | |
| | |
| | | { |
| | | shutdownCalled = false; |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * Waits up to five seconds until the post-response plugins have been called |
| | | * at least once since the last reset. |
| | | * @return The number of times that the post-response plugins have been |
| | | * called since the last reset. The return value may be zero if the |
| | | * wait timed out. |
| | | * @throws InterruptedException If another thread interrupts this thread. |
| | | */ |
| | | public static int waitForPostResponse() throws InterruptedException |
| | | { |
| | | long timeout = System.currentTimeMillis() + 5000; |
| | | while (postResponseCounter.get() == 0 && |
| | | System.currentTimeMillis() < timeout) |
| | | { |
| | | Thread.sleep(10); |
| | | } |
| | | return postResponseCounter.get(); |
| | | } |
| | | } |
| | | |