Package org.jboss.as.test.clustering.cluster.ejb3.stateless.bean

Examples of org.jboss.as.test.clustering.cluster.ejb3.stateless.bean.Stateless


     * @throws Exception
     */
    @Test
    public void testAnnotationBasedClusteredBeanDeployment() throws Exception {
        final Context ctx = new InitialContext();
        final ClusteredBean clusteredBean = (ClusteredBean) ctx.lookup("java:module/" + ClusteredBean.class.getSimpleName() + "!" + ClusteredBean.class.getName());
        final int NUM_TIMES = 5;
        for (int i = 0; i < NUM_TIMES; i++) {
            clusteredBean.increment();
        }
        Assert.assertEquals("Unexpected count on stateful bean", clusteredBean.getCount(), NUM_TIMES);
    }
View Full Code Here


     * @throws Exception
     */
    @Test
    public void testDDBasedClusteredBeanDeployment() throws Exception {
        final Context ctx = new InitialContext();
        final DDBasedClusteredBean ddBasedClusteredBean = (DDBasedClusteredBean) ctx.lookup("java:module/" + DDBasedClusteredBean.class.getSimpleName() + "!" + DDBasedClusteredBean.class.getName());
        final int NUM_TIMES = 5;
        for (int i = 0; i < NUM_TIMES; i++) {
            ddBasedClusteredBean.increment();
        }
        Assert.assertEquals("Unexpected count on stateful bean", ddBasedClusteredBean.getCount(), NUM_TIMES);
    }
View Full Code Here

    private int count;

    @Override
    public CounterResult increment() {
        this.count++;
        return new CounterResult(this.count, getNodeName());
    }
View Full Code Here

    }

    @Override
    public CounterResult decrement() {
        this.count--;
        return new CounterResult(this.count, getNodeName());
    }
View Full Code Here

        return new CounterResult(this.count, getNodeName());
    }

    @Override
    public CounterResult getCount() {
        return new CounterResult(this.count, getNodeName());
    }
View Full Code Here

        try {
            final RemoteCounter remoteCounter = context.lookupStateful(DDBasedClusteredSFSB.class, RemoteCounter.class);
            // invoke on the bean a few times
            final int NUM_TIMES = 25;
            for (int i = 0; i < NUM_TIMES; i++) {
                final CounterResult result = remoteCounter.increment();
                logger.info("Counter incremented to " + result.getCount() + " on node " + result.getNodeName());
            }
            final CounterResult result = remoteCounter.getCount();
            Assert.assertNotNull("Result from remote stateful counter was null", result);
            Assert.assertEquals("Unexpected count from remote counter", NUM_TIMES, result.getCount());

            // shutdown the node on which the previous invocation happened
            final int totalCountBeforeShuttingDownANode = result.getCount();
            final String previousInvocationNodeName = result.getNodeName();
            // the value is configured in arquillian.xml of the project
            if (previousInvocationNodeName.equals("node-udp-0")) {
                this.deployer.undeploy(DEPLOYMENT_1);
                this.container.stop(CONTAINER_1);
                container1Stopped = true;
            } else {
                this.deployer.undeploy(DEPLOYMENT_2);
                this.container.stop(CONTAINER_2);
                container2Stopped = true;
            }
            // invoke again
            CounterResult resultAfterShuttingDownANode = remoteCounter.increment();
            Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", resultAfterShuttingDownANode);
            Assert.assertEquals("Unexpected count from remote counter, after shutting down a node", totalCountBeforeShuttingDownANode + 1, resultAfterShuttingDownANode.getCount());
            Assert.assertFalse("Result was received from an unexpected node, after shutting down a node", previousInvocationNodeName.equals(resultAfterShuttingDownANode.getNodeName()));

            // repeat invocations
            final int countBeforeDecrementing = resultAfterShuttingDownANode.getCount();
            final String aliveNode = resultAfterShuttingDownANode.getNodeName();
            for (int i = NUM_TIMES; i > 0; i--) {
                resultAfterShuttingDownANode = remoteCounter.decrement();
                Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", resultAfterShuttingDownANode);
                Assert.assertEquals("Result was received from an unexpected node, after shutting down a node", aliveNode, resultAfterShuttingDownANode.getNodeName());
                logger.info("Counter decremented to " + resultAfterShuttingDownANode.getCount() + " on node " + resultAfterShuttingDownANode.getNodeName());
            }
            final CounterResult finalResult = remoteCounter.getCount();
            Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", finalResult);
            final int finalCount = finalResult.getCount();
            final String finalNodeName = finalResult.getNodeName();
            Assert.assertEquals("Result was received from an unexpected node, after shutting down a node", aliveNode, finalNodeName);
            Assert.assertEquals("Unexpected count from remote counter, after shutting down a node", countBeforeDecrementing - NUM_TIMES, finalCount);
        } finally {
            // reset the selector
            if (previousSelector != null) {
View Full Code Here

        final ContextSelector<EJBClientContext> previousSelector = EJBClientContextSelector.setup("cluster/ejb3/stateful/failover/sfsb-failover-jboss-ejb-client.properties");
        boolean container1Stopped = false;
        boolean container2Stopped = false;
        try {
            final RemoteCounter remoteCounter = context.lookupStateful(DDBasedClusteredSFSB.class, RemoteCounter.class);
            // invoke on the bean a few times
            final int NUM_TIMES = 25;
            for (int i = 0; i < NUM_TIMES; i++) {
                final CounterResult result = remoteCounter.increment();
                logger.info("Counter incremented to " + result.getCount() + " on node " + result.getNodeName());
            }
            final CounterResult result = remoteCounter.getCount();
            Assert.assertNotNull("Result from remote stateful counter was null", result);
            Assert.assertEquals("Unexpected count from remote counter", NUM_TIMES, result.getCount());

            // shutdown the node on which the previous invocation happened
            final int totalCountBeforeShuttingDownANode = result.getCount();
            final String previousInvocationNodeName = result.getNodeName();
            // the value is configured in arquillian.xml of the project
            if (previousInvocationNodeName.equals("node-udp-0")) {
                this.deployer.undeploy(DEPLOYMENT_1);
                this.container.stop(CONTAINER_1);
                container1Stopped = true;
            } else {
                this.deployer.undeploy(DEPLOYMENT_2);
                this.container.stop(CONTAINER_2);
                container2Stopped = true;
            }
            // invoke again
            CounterResult resultAfterShuttingDownANode = remoteCounter.increment();
            Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", resultAfterShuttingDownANode);
            Assert.assertEquals("Unexpected count from remote counter, after shutting down a node", totalCountBeforeShuttingDownANode + 1, resultAfterShuttingDownANode.getCount());
            Assert.assertFalse("Result was received from an unexpected node, after shutting down a node", previousInvocationNodeName.equals(resultAfterShuttingDownANode.getNodeName()));

            // repeat invocations
            final int countBeforeDecrementing = resultAfterShuttingDownANode.getCount();
            final String aliveNode = resultAfterShuttingDownANode.getNodeName();
            for (int i = NUM_TIMES; i > 0; i--) {
                resultAfterShuttingDownANode = remoteCounter.decrement();
                Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", resultAfterShuttingDownANode);
                Assert.assertEquals("Result was received from an unexpected node, after shutting down a node", aliveNode, resultAfterShuttingDownANode.getNodeName());
                logger.info("Counter decremented to " + resultAfterShuttingDownANode.getCount() + " on node " + resultAfterShuttingDownANode.getNodeName());
            }
            final CounterResult finalResult = remoteCounter.getCount();
            Assert.assertNotNull("Result from remote stateful counter, after shutting down a node was null", finalResult);
            final int finalCount = finalResult.getCount();
            final String finalNodeName = finalResult.getNodeName();
            Assert.assertEquals("Result was received from an unexpected node, after shutting down a node", aliveNode, finalNodeName);
            Assert.assertEquals("Unexpected count from remote counter, after shutting down a node", countBeforeDecrementing - NUM_TIMES, finalCount);
View Full Code Here

        this.deploy(0);

        final ContextSelector<EJBClientContext> selector = EJBClientContextSelector.setup(CLIENT_PROPERTIES);
       
        try {
            Stateless bean = context.lookupStateless(StatelessBean.class, Stateless.class);
           
            assertEquals(NODES[0], bean.getNodeName());

            this.start(1);
            this.deploy(1);

            // Allow ample time for topology change to propagate to client
            Thread.sleep(GRACE_TIME_TO_MEMBERSHIP_CHANGE);
           
            this.stop(0);
           
            assertEquals(NODES[1], bean.getNodeName());
        } finally {
            // reset the selector
            if (selector != null) {
                EJBClientContext.setSelector(selector);
            }
View Full Code Here

        this.deploy(0);

        final ContextSelector<EJBClientContext> selector = EJBClientContextSelector.setup(CLIENT_PROPERTIES);
       
        try {
            Stateless bean = context.lookupStateless(StatelessBean.class, Stateless.class);
           
            assertEquals(NODES[0], bean.getNodeName());

            this.start(1);
            this.deploy(1);
           
            // Allow ample time for topology change to propagate to client
            Thread.sleep(GRACE_TIME_TO_MEMBERSHIP_CHANGE);
           
            this.undeploy(0);
           
            assertEquals(NODES[1], bean.getNodeName());
        } finally {
            // reset the selector
            if (selector != null) {
                EJBClientContext.setSelector(selector);
            }
View Full Code Here

TOP

Related Classes of org.jboss.as.test.clustering.cluster.ejb3.stateless.bean.Stateless

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.