Search in sources :

Example 1 with PromiseLatch

use of org.nustaq.kontraktor.util.PromiseLatch in project kontraktor by RuedigerMoeller.

the class GeneratorTest method test.

@Test
public void test() {
    Generator generator = Actors.AsActor(Generator.class);
    try {
        generator.run().await(1000 * 1000l);
    } catch (Exception e) {
        e.printStackTrace();
        Assert.assertTrue(false);
    }
    try {
        generator.run().await(1 * 1000l);
        Assert.assertTrue(false);
    } catch (Exception e) {
        e.printStackTrace();
    }
    // test outside actor thread
    BiConsumer<Long, Boolean> outside = (timout, expectTO) -> {
        // +1 == fin signal
        PromiseLatch finished = new PromiseLatch(5 * 5 + 1);
        generator.generate(100, (intarr, err) -> {
            if (!Actor.isErrorOrComplete(err)) {
                System.out.println("-> [" + intarr[0] + "," + intarr[1] + "]");
            }
            finished.countDown();
        });
        try {
            finished.getPromise().await(timout);
            if (expectTO)
                Assert.assertTrue(false);
        } catch (Exception e) {
            e.printStackTrace();
            if (!expectTO)
                Assert.assertTrue(false);
        }
    };
    outside.accept(1000l, true);
    outside.accept(100 * 1000l, false);
}
Also used : Assert(junit.framework.Assert) BiConsumer(java.util.function.BiConsumer) Test(org.junit.Test) org.nustaq.kontraktor(org.nustaq.kontraktor) PromiseLatch(org.nustaq.kontraktor.util.PromiseLatch) PromiseLatch(org.nustaq.kontraktor.util.PromiseLatch) Test(org.junit.Test)

Example 2 with PromiseLatch

use of org.nustaq.kontraktor.util.PromiseLatch in project kontraktor by RuedigerMoeller.

the class Actors method awaitSettle.

// changed to non recursive due to stackoverflows ..
private static <T> void awaitSettle(final List<IPromise<T>> futures, final IPromise result) {
    PromiseLatch latch = new PromiseLatch(futures.size());
    latch.getPromise().then(() -> result.complete(futures, null));
    futures.forEach(fut -> fut.then(() -> latch.countDown()));
}
Also used : PromiseLatch(org.nustaq.kontraktor.util.PromiseLatch)

Example 3 with PromiseLatch

use of org.nustaq.kontraktor.util.PromiseLatch in project kontraktor by RuedigerMoeller.

the class Actors method awaitSettle.

// end static API
// 
// /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
// helper
// changed to non recursive due to stackoverflows ..
private static <T> void awaitSettle(final IPromise<T>[] futures, final IPromise result) {
    PromiseLatch latch = new PromiseLatch(futures.length);
    latch.getPromise().then(() -> result.complete(futures, null));
    for (int i = 0; i < futures.length; i++) {
        futures[i].then(() -> latch.countDown());
    }
}
Also used : PromiseLatch(org.nustaq.kontraktor.util.PromiseLatch)

Aggregations

PromiseLatch (org.nustaq.kontraktor.util.PromiseLatch)3 BiConsumer (java.util.function.BiConsumer)1 Assert (junit.framework.Assert)1 Test (org.junit.Test)1 org.nustaq.kontraktor (org.nustaq.kontraktor)1