Package org.rhq.enterprise.communications.command.client

Examples of org.rhq.enterprise.communications.command.client.RemotePojoInvocationFuture


        AgentMain agent2 = m_agent2Test.createAgent(true);

        assert agent1.isStarted() : "agent1 should have been started";
        assert agent2.isStarted() : "agent2 should have been started";

        RemotePojoInvocationFuture future = new RemotePojoInvocationFuture();
        ClientRemotePojoFactory factory = agent1.getClientCommandSender().getClientRemotePojoFactory();
        factory.setAsynch(false, future); // false should still honor annotations - we'll make sure that's true in this test
        ITestAnnotatedPojo pojo = factory.getRemotePojo(ITestAnnotatedPojo.class);

        pojo.volatileMethod("first test");
        assert "first test".equals(future.get());
        assert future.isDone();

        long stopwatch = System.currentTimeMillis();
        assert "first test".equals(future.get(10, TimeUnit.SECONDS)); // make sure its still there
        long test_duration = System.currentTimeMillis() - stopwatch;
        assert test_duration < 750L : "get should have returned immediately: " + test_duration;

        assert future.isDone();
        future.reset();
        assert !future.isDone();

        stopwatch = System.currentTimeMillis();
        try {
            future.get(2, TimeUnit.SECONDS);
            assert false : "The get should have timed out";
        } catch (TimeoutException toe) {
        }

        test_duration = System.currentTimeMillis() - stopwatch;
        assert (test_duration > 1900L) && (test_duration < 2500L) : "Should have timed out after 2 seconds: "
            + test_duration;

        // we want to call throwThrowable asynchronously but it isn't annotated that way, so force async
        // calling this isn't enough - all existing proxies remain as-is - this call only affects newly created remote pojo proxies
        factory.setAsynch(true, future);
        factory.setIgnoreAnnotations(true);

        // test throwing an Error
        Error err = new Error("bogus error for testing");

        // side-test - show that the proxy isn't forcing all methods to be async.
        try {
            pojo.throwThrowable(err);
            assert false : "Should have called this synchronously which should have thrown Error";
        } catch (Error error) {
            // to be expected, the remote pojo proxy is still configured to call throwThrowable synchronously
        }

        // now let's get a new remote pojo proxy that is forced to call everything asynchronously
        pojo = factory.getRemotePojo(ITestAnnotatedPojo.class);
        pojo.throwThrowable(err);

        try {
            future.get();
            assert false : "Should have thrown an exception";
        } catch (ExecutionException ee) {
            assert "bogus error for testing".equals(ee.getCause().getMessage());
            assert ee.getCause() instanceof Error;
        }

        // test throwing an Error
        future.reset();
        pojo.throwThrowable(new RuntimeException("bogus runtime exception for testing"));

        try {
            future.getAndReset();
            assert false : "Should have thrown an exception";
        } catch (ExecutionException ee) {
            assert "bogus runtime exception for testing".equals(ee.getCause().getMessage());
            assert ee.getCause() instanceof RuntimeException;
        }
View Full Code Here

TOP

Related Classes of org.rhq.enterprise.communications.command.client.RemotePojoInvocationFuture

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.