Search in sources :

Example 1 with Predicate

use of org.osgi.util.function.Predicate in project aries by apache.

the class AsyncServiceTest method test.

@Test
public void test() throws InterruptedException {
    DelayedEcho raw = new DelayedEcho();
    AsyncService service = new AsyncService(null, es, ses, serviceTracker);
    DelayedEcho mediated = service.mediate(raw, DelayedEcho.class);
    Promise<String> promise = service.call(mediated.echo("Hello World", 1000));
    final CountDownLatch latch = new CountDownLatch(1);
    promise.filter(new Predicate<String>() {

        @Override
        public boolean test(String t) {
            return "Hello World".equals(t);
        }
    }).then(new Success<String, Void>() {

        @Override
        public Promise<Void> call(Promise<String> resolved) throws Exception {
            latch.countDown();
            return null;
        }
    });
    assertTrue(latch.await(5, TimeUnit.SECONDS));
}
Also used : Promise(org.osgi.util.promise.Promise) CountDownLatch(java.util.concurrent.CountDownLatch) Predicate(org.osgi.util.function.Predicate) Test(org.junit.Test)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)1 Test (org.junit.Test)1 Predicate (org.osgi.util.function.Predicate)1 Promise (org.osgi.util.promise.Promise)1