Package org.jgroups.util

Examples of org.jgroups.util.Promise


*/
@Test(groups=Global.FUNCTIONAL)
public class PromiseTest {

    public static void testGetResultNoTimeout() {
        final Promise p=new Promise();
        Object result;
        new ResultSetter(p, 500).start();
        result=p.getResult(0);
        Assert.assertEquals(Boolean.TRUE, result);
    }
View Full Code Here


        Assert.assertEquals(Boolean.TRUE, result);
    }


    public static void testGetResultNoTimeout_ResultAlreadySet() {
        final Promise p=new Promise();
        Object result;
        new ResultSetter(p, 1).start();
        Util.sleep(100);
        result=p.getResult(0);
        Assert.assertEquals(Boolean.TRUE, result);
    }
View Full Code Here

        Assert.assertEquals(Boolean.TRUE, result);
    }

    @Test(expectedExceptions=TimeoutException.class)
    public static void testGetResultWithTimeout() throws TimeoutException {
        final Promise p=new Promise();
        p.getResultWithTimeout(500);
    }
View Full Code Here

    }



    public static void testGetResultWithTimeoutNoException() {
        final Promise p=new Promise();
        Object ret=p.getResult(500);
        assert ret == null;
    }
View Full Code Here

        assert ret == null;
    }


    public static void testGetResultWithTimeoutAndInterrupt() {
        final Promise p=new Promise();
        new Interrupter(Thread.currentThread(), 100).start();
        Object result=p.getResult(500);
        assert result == null;
    }
View Full Code Here

    }



    public static void testGetResultWithTimeoutAndResultSetter() {
        final Promise p=new Promise();
        Thread t=new Thread() {
            public void run() {
                Util.sleep(500);
                System.out.println("-- setting promise to \"Bela\"");
                p.setResult("Bela");
            }
        };
        t.start();
        long start=System.currentTimeMillis(), stop;
        Object result=p.getResult(100000);
        stop=System.currentTimeMillis();
        System.out.println("-- waited for " + (stop-start) + "ms, result is " + result);
        assert result != null;
        Assert.assertEquals("Bela", result);
        assert !(p.hasResult()) : "promise was reset after getResult()";
    }
View Full Code Here

            executed=true;
        }
    }

    public void testImmediateExecution() {
        Promise p=new Promise();
        ImmediateTask task=new ImmediateTask(p);
        timer.add(task);
        try {
            long start=System.currentTimeMillis(), stop;
            p.getResultWithTimeout(5);
            stop=System.currentTimeMillis();
            System.out.println("task took " + (stop-start) + "ms");
        }
        catch(TimeoutException e) {
            fail("ran into timeout - task should have executed immediately");
View Full Code Here

        if(stopped == false) return;

        timer.start();

        if(start_promise == null)
            start_promise=new Promise();
        else
            start_promise.reset();

        down(new Event(Event.START));
        start_result=start_promise.getResult(0);
View Full Code Here

        }

        if(stopped) return;

        if(stop_promise == null)
            stop_promise=new Promise();
        else
            stop_promise.reset();

        down(new Event(Event.STOP));
        stop_promise.getResult(5000);
View Full Code Here

     * bug, which used to leave pbcast.NAKACK in a broken state after
     * DISCONNECT. Because of this problem, the channel couldn't be used to
     * multicast messages.
     **/
    public void testDisconnectConnectSendTwo() throws Exception {
        final Promise msgPromise=new Promise();
        JChannel coordinator=new JChannel(props);
        coordinator.connect("testgroup");
        PullPushAdapter ppa=
                new PullPushAdapter(coordinator,
                                    new PromisedMessageListener(msgPromise));
        ppa.start();

        channel=new JChannel(props);
        channel.connect("testgroup1");
        channel.disconnect();
        channel.connect("testgroup");
        channel.send(new Message(null, null, "payload"));
        Message msg=(Message)msgPromise.getResult(20000);
        assertTrue(msg != null);
        assertEquals("payload", msg.getObject());
        ppa.stop();
        coordinator.close();
        channel.close();
View Full Code Here

TOP

Related Classes of org.jgroups.util.Promise

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.