Package com.atlassian.confluence.it.rpc
Class EventWaitingLatch
- java.lang.Object
-
- com.atlassian.confluence.it.rpc.EventWaitingLatch
-
public class EventWaitingLatch extends Object
Latch that allows acceptance testing code to wait for a specific Confluence event to be published on the server side before proceeding with assertions.This is useful when assertions need to be made on the output of a long running process on the server that clearly indicates its completion using an event.
Usage:
EventWaitingLatch latch = new EventWaitingLatch(MyEvent.class, 60000, rpc); try { latch.registerListener(); ... insert code that invokes long running process on server side ... latch.await(); ... insert test assertions ... } finally { latch.clearListener(); }
It is important that the latch is instantiated before the start of the long running process. If constructed after, there is a small chance that the event being listened for is fired before latch is ready to receive it.
-
-
Constructor Summary
Constructors Constructor Description EventWaitingLatch(@NonNull String eventClassName, long timeoutMs, @NonNull ConfluenceRpc rpc)
EventWaitingLatch(@NonNull String eventClassName, @NonNull TimePeriod timeout, @NonNull ConfluenceRpc rpc)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static void
clearAllLatches(ConfluenceRpc rpc)
It's advisable to clear all latches in a tearDown if multiple latches will be active concurrently.void
registerListener()
void
unregisterListener()
boolean
waitForEvent()
Blocks until event is received.
-
-
-
Constructor Detail
-
EventWaitingLatch
public EventWaitingLatch(@NonNull String eventClassName, long timeoutMs, @NonNull ConfluenceRpc rpc)
-
EventWaitingLatch
public EventWaitingLatch(@NonNull String eventClassName, @NonNull TimePeriod timeout, @NonNull ConfluenceRpc rpc)
-
-
Method Detail
-
waitForEvent
public boolean waitForEvent()
Blocks until event is received. Returns true if this happens within the timeout, false otherwise.- Returns:
- true if the event is received within the timeout, false otherwise.
-
clearAllLatches
public static void clearAllLatches(ConfluenceRpc rpc)
It's advisable to clear all latches in a tearDown if multiple latches will be active concurrently.
-
registerListener
public void registerListener()
-
unregisterListener
public void unregisterListener()
-
-