Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current Restore this Version View Page History

« Previous Version 5 Current »

When testing asynchronous services it is generally necessary to block runtime shutdown until a message has been processed or a callback received. Since message reception may happen on a different thread than the forward call, a race condition may occur where runtime shutdown is initiated before processing has completed.

The iTest Plugin provides the ability to define a latch in an test composite that the runtime will wait on prior to initiating shutdown. The latch can be released from test code when necessary conditions are met.

The latch component can implement any interface with an await() method:

public interface LatchService {
    void countDown();

    void await() throws InterruptedException;
}

@Scope("COMPOSITE")
public class LatchServiceImpl implements LatchService {
    private CountDownLatch latch = new CountDownLatch(1);

    public void countDown() {
        latch.countDown();
    }

    public void await() throws InterruptedException {
        latch.await();
    }
}

Note it is important the latch service implementation be composite scope; otherwise different instances will be returned to the runtime and test code, resulting in the runtime latch never being released.

The latch service is configured in a test composite using the name "F3LatchService":

   <component name="F3LatchService">
        <implementation.java class="org.fabric3.async.test.LatchServiceImpl"/>
    </component>

When integration tests are run, the runtime will block on the await() method after initiating JUnit test components. Test code is then responsible for invoking the countDown() method when asynchronous test processing has completed.