diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatefulEJBFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatefulEJBFailoverTestCase.java new file mode 100644 index 000000000000..85a0e59ab14a --- /dev/null +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatefulEJBFailoverTestCase.java @@ -0,0 +1,154 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.clustering.cluster.ejb.remote; + +import java.util.PropertyPermission; + +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.as.test.clustering.cluster.ClusterAbstractTestCase; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.IncrementorBean; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Result; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.StatefulIncrementorBean; +import org.jboss.as.test.clustering.ejb.EJBDirectory; +import org.jboss.as.test.shared.TimeoutUtil; +import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.wildfly.common.function.ExceptionSupplier; + +/** + * Validates failover behavior of a remotely accessed @Stateful EJB. + * @author Paul Ferraro + */ +@RunWith(Arquillian.class) +@RunAsClient +public abstract class AbstractRemoteStatefulEJBFailoverTestCase extends ClusterAbstractTestCase { + private static final int COUNT = 20; + private static final long CLIENT_TOPOLOGY_UPDATE_WAIT = TimeoutUtil.adjust(5000); + + static Archive createDeployment(String moduleName) { + return ShrinkWrap.create(JavaArchive.class, moduleName + ".jar") + .addPackage(EJBDirectory.class.getPackage()) + .addClasses(Result.class, Incrementor.class, IncrementorBean.class, StatefulIncrementorBean.class) + .addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new PropertyPermission(NODE_NAME_PROPERTY, "read")), "permissions.xml") + ; + } + + private final ExceptionSupplier directoryProvider; + + protected AbstractRemoteStatefulEJBFailoverTestCase(ExceptionSupplier directoryProvider) { + this.directoryProvider = directoryProvider; + } + + @Test + public void test() throws Exception { + try (EJBDirectory directory = this.directoryProvider.get()) { + Incrementor bean = directory.lookupStateful(StatefulIncrementorBean.class, Incrementor.class); + + Result result = bean.increment(); + String target = result.getNode(); + int count = 1; + + Assert.assertEquals(count++, result.getValue().intValue()); + + // Bean should retain weak affinity for this node + for (int i = 0; i < COUNT; ++i) { + result = bean.increment(); + Assert.assertEquals(count++, result.getValue().intValue()); + Assert.assertEquals(String.valueOf(i), target, result.getNode()); + } + + undeploy(this.findDeployment(target)); + + Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT); + + result = bean.increment(); + // Bean should failover to other node + String failoverTarget = result.getNode(); + + Assert.assertEquals(count++, result.getValue().intValue()); + Assert.assertNotEquals(target, failoverTarget); + + deploy(this.findDeployment(target)); + + // Allow sufficient time for client to receive new topology + Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT); + + result = bean.increment(); + String failbackTarget = result.getNode(); + Assert.assertEquals(count++, result.getValue().intValue()); + // Bean should retain weak affinity for this node + Assert.assertEquals(failoverTarget, failbackTarget); + + result = bean.increment(); + // Bean may have acquired new weak affinity + target = result.getNode(); + Assert.assertEquals(count++, result.getValue().intValue()); + + // Bean should retain weak affinity for this node + for (int i = 0; i < COUNT; ++i) { + result = bean.increment(); + Assert.assertEquals(count++, result.getValue().intValue()); + Assert.assertEquals(String.valueOf(i), target, result.getNode()); + } + + stop(this.findContainer(target)); + + result = bean.increment(); + // Bean should failover to other node + failoverTarget = result.getNode(); + + Assert.assertEquals(count++, result.getValue().intValue()); + Assert.assertNotEquals(target, failoverTarget); + + start(this.findContainer(target)); + + // Allow sufficient time for client to receive new topology + Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT); + + result = bean.increment(); + failbackTarget = result.getNode(); + Assert.assertEquals(count++, result.getValue().intValue()); + // Bean should retain weak affinity for this node + Assert.assertEquals(failoverTarget, failbackTarget); + + result = bean.increment(); + // Bean may have acquired new weak affinity + target = result.getNode(); + Assert.assertEquals(count++, result.getValue().intValue()); + + // Bean should retain weak affinity for this node + for (int i = 0; i < COUNT; ++i) { + result = bean.increment(); + Assert.assertEquals(count++, result.getValue().intValue()); + Assert.assertEquals(String.valueOf(i), target, result.getNode()); + } + } + } +} diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatelessEJBFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatelessEJBFailoverTestCase.java index 3e374949dbd2..b7ea204997bf 100644 --- a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatelessEJBFailoverTestCase.java +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatelessEJBFailoverTestCase.java @@ -27,6 +27,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.PropertyPermission; import java.util.concurrent.Callable; import java.util.function.UnaryOperator; @@ -34,13 +35,20 @@ import org.jboss.arquillian.junit.Arquillian; import org.jboss.as.test.clustering.cluster.ClusterAbstractTestCase; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.IncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Result; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.SecureStatelessIncrementorBean; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.StatelessIncrementorBean; import org.jboss.as.test.clustering.ejb.EJBDirectory; -import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory; import org.jboss.as.test.shared.TimeoutUtil; +import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils; +import org.jboss.shrinkwrap.api.Archive; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; +import org.wildfly.common.function.ExceptionSupplier; /** * Validates failover behavior of a remotely accessed @Stateless EJB. @@ -54,12 +62,20 @@ public abstract class AbstractRemoteStatelessEJBFailoverTestCase extends Cluster private static final long CLIENT_TOPOLOGY_UPDATE_WAIT = TimeoutUtil.adjust(5000); private static final long INVOCATION_WAIT = TimeoutUtil.adjust(10); - private final String module; + static Archive createDeployment(String moduleName) { + return ShrinkWrap.create(JavaArchive.class, moduleName + ".jar") + .addPackage(EJBDirectory.class.getPackage()) + .addClasses(Result.class, Incrementor.class, IncrementorBean.class, StatelessIncrementorBean.class, SecureStatelessIncrementorBean.class) + .addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new PropertyPermission(NODE_NAME_PROPERTY, "read")), "permissions.xml") + ; + } + + private final ExceptionSupplier directoryProvider; private final Class beanClass; private final UnaryOperator> configurator; - AbstractRemoteStatelessEJBFailoverTestCase(String module, Class beanClass, UnaryOperator> configurator) { - this.module = module; + AbstractRemoteStatelessEJBFailoverTestCase(ExceptionSupplier directoryProvider, Class beanClass, UnaryOperator> configurator) { + this.directoryProvider = directoryProvider; this.beanClass = beanClass; this.configurator = configurator; } @@ -67,7 +83,7 @@ public abstract class AbstractRemoteStatelessEJBFailoverTestCase extends Cluster @Test public void test() throws Exception { this.configurator.apply(() -> { - try (EJBDirectory directory = new RemoteEJBDirectory(this.module)) { + try (EJBDirectory directory = this.directoryProvider.get()) { Incrementor bean = directory.lookupStateless(this.beanClass, Incrementor.class); // Allow sufficient time for client to receive full topology diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AuthContextRemoteStatelessEJBFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AuthContextRemoteStatelessEJBFailoverTestCase.java index 33e5f05a0f34..e552887c108c 100644 --- a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AuthContextRemoteStatelessEJBFailoverTestCase.java +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/AuthContextRemoteStatelessEJBFailoverTestCase.java @@ -22,21 +22,14 @@ package org.jboss.as.test.clustering.cluster.ejb.remote; -import java.util.PropertyPermission; import java.util.concurrent.Callable; import java.util.function.UnaryOperator; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; -import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor; -import org.jboss.as.test.clustering.cluster.ejb.remote.bean.IncrementorBean; -import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Result; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.SecureStatelessIncrementorBean; -import org.jboss.as.test.clustering.ejb.EJBDirectory; -import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils; +import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory; import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; import org.wildfly.security.auth.client.AuthenticationConfiguration; import org.wildfly.security.auth.client.AuthenticationContext; import org.wildfly.security.auth.client.MatchRule; @@ -56,25 +49,17 @@ public abstract class AuthContextRemoteStatelessEJBFailoverTestCase extends Abst @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(CONTAINER_1) public static Archive createDeploymentForContainer1() { - return createDeployment(); + return createDeployment(MODULE_NAME); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(CONTAINER_2) public static Archive createDeploymentForContainer2() { - return createDeployment(); - } - - private static Archive createDeployment() { - return ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar") - .addPackage(EJBDirectory.class.getPackage()) - .addClasses(Result.class, Incrementor.class, IncrementorBean.class, SecureStatelessIncrementorBean.class) - .addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new PropertyPermission(NODE_NAME_PROPERTY, "read")), "permissions.xml") - ; + return createDeployment(MODULE_NAME); } public AuthContextRemoteStatelessEJBFailoverTestCase(UnaryOperator> configurator) { - super(MODULE_NAME, SecureStatelessIncrementorBean.class, configurator); + super(() -> new RemoteEJBDirectory(MODULE_NAME), SecureStatelessIncrementorBean.class, configurator); } } diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatefulEJBFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatefulEJBFailoverTestCase.java new file mode 100644 index 000000000000..bfa642b1cfb3 --- /dev/null +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatefulEJBFailoverTestCase.java @@ -0,0 +1,48 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.clustering.cluster.ejb.remote; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.TargetsContainer; +import org.jboss.as.test.clustering.ejb.ClientEJBDirectory; +import org.jboss.shrinkwrap.api.Archive; + +public class ClientRemoteStatefulEJBFailoverTestCase extends AbstractRemoteStatefulEJBFailoverTestCase { + private static final String MODULE_NAME = "client-remote-stateful-ejb-failover-test"; + + @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) + @TargetsContainer(CONTAINER_1) + public static Archive createDeploymentForContainer1() { + return createDeployment(MODULE_NAME); + } + + @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) + @TargetsContainer(CONTAINER_2) + public static Archive createDeploymentForContainer2() { + return createDeployment(MODULE_NAME); + } + + public ClientRemoteStatefulEJBFailoverTestCase() { + super(() -> new ClientEJBDirectory(MODULE_NAME)); + } +} diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatelessEJBFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatelessEJBFailoverTestCase.java new file mode 100644 index 000000000000..695adc3ce6ee --- /dev/null +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatelessEJBFailoverTestCase.java @@ -0,0 +1,54 @@ +/* + * JBoss, Home of Professional Open Source. + * Copyright 2017, Red Hat, Inc., and individual contributors + * as indicated by the @author tags. See the copyright.txt file in the + * distribution for a full listing of individual contributors. + * + * This is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2.1 of + * the License, or (at your option) any later version. + * + * This software is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this software; if not, write to the Free + * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA + * 02110-1301 USA, or see the FSF site: http://www.fsf.org. + */ + +package org.jboss.as.test.clustering.cluster.ejb.remote; + +import java.util.function.UnaryOperator; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.TargetsContainer; +import org.jboss.as.test.clustering.cluster.ejb.remote.bean.StatelessIncrementorBean; +import org.jboss.as.test.clustering.ejb.ClientEJBDirectory; +import org.jboss.shrinkwrap.api.Archive; + +/** + * @author Paul Ferraro + */ +public class ClientRemoteStatelessEJBFailoverTestCase extends AbstractRemoteStatelessEJBFailoverTestCase { + private static final String MODULE_NAME = "client-remote-stateless-ejb-failover-test"; + + @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) + @TargetsContainer(CONTAINER_1) + public static Archive createDeploymentForContainer1() { + return createDeployment(MODULE_NAME); + } + + @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) + @TargetsContainer(CONTAINER_2) + public static Archive createDeploymentForContainer2() { + return createDeployment(MODULE_NAME); + } + + public ClientRemoteStatelessEJBFailoverTestCase() { + super(() -> new ClientEJBDirectory(MODULE_NAME), StatelessIncrementorBean.class, UnaryOperator.identity()); + } +} diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBConcurrentFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBConcurrentFailoverTestCase.java index 77c67ddc3618..5291e1a97054 100644 --- a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBConcurrentFailoverTestCase.java +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBConcurrentFailoverTestCase.java @@ -31,8 +31,6 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import javax.naming.NamingException; - import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.container.test.api.TargetsContainer; @@ -175,7 +173,7 @@ private class LookupTask implements Runnable { public void run() { try { this.directory.lookupStateful(this.beanClass, Incrementor.class); - } catch (NamingException e) { + } catch (Exception e) { throw new IllegalStateException(e); } finally { this.latch.countDown(); diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBFailoverTestCase.java index 59a1cb617468..f5e2701a48a0 100644 --- a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBFailoverTestCase.java +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatefulEJBFailoverTestCase.java @@ -25,37 +25,24 @@ import java.util.PropertyPermission; import org.jboss.arquillian.container.test.api.Deployment; -import org.jboss.arquillian.container.test.api.RunAsClient; import org.jboss.arquillian.container.test.api.TargetsContainer; -import org.jboss.arquillian.junit.Arquillian; -import org.jboss.as.test.clustering.cluster.ClusterAbstractTestCase; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.IncrementorBean; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Result; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.StatefulIncrementorBean; import org.jboss.as.test.clustering.ejb.EJBDirectory; import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory; -import org.jboss.as.test.shared.TimeoutUtil; import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils; import org.jboss.shrinkwrap.api.Archive; import org.jboss.shrinkwrap.api.ShrinkWrap; import org.jboss.shrinkwrap.api.spec.JavaArchive; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; /** - * Validates failover behavior of a remotely accessed @Stateful EJB. * @author Paul Ferraro */ -@RunWith(Arquillian.class) -@RunAsClient -public class RemoteStatefulEJBFailoverTestCase extends ClusterAbstractTestCase { +public class RemoteStatefulEJBFailoverTestCase extends AbstractRemoteStatefulEJBFailoverTestCase { private static final String MODULE_NAME = "remote-stateful-ejb-failover-test"; - private static final int COUNT = 20; - private static final long CLIENT_TOPOLOGY_UPDATE_WAIT = TimeoutUtil.adjust(5000); - @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(CONTAINER_1) public static Archive createDeploymentForContainer1() { @@ -76,89 +63,7 @@ private static Archive createDeployment() { ; } - @Test - public void test() throws Exception { - try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) { - Incrementor bean = directory.lookupStateful(StatefulIncrementorBean.class, Incrementor.class); - - Result result = bean.increment(); - String target = result.getNode(); - int count = 1; - - Assert.assertEquals(count++, result.getValue().intValue()); - - // Bean should retain weak affinity for this node - for (int i = 0; i < COUNT; ++i) { - result = bean.increment(); - Assert.assertEquals(count++, result.getValue().intValue()); - Assert.assertEquals(String.valueOf(i), target, result.getNode()); - } - - undeploy(this.findDeployment(target)); - - Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT); - - result = bean.increment(); - // Bean should failover to other node - String failoverTarget = result.getNode(); - - Assert.assertEquals(count++, result.getValue().intValue()); - Assert.assertNotEquals(target, failoverTarget); - - deploy(this.findDeployment(target)); - - // Allow sufficient time for client to receive new topology - Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT); - - result = bean.increment(); - String failbackTarget = result.getNode(); - Assert.assertEquals(count++, result.getValue().intValue()); - // Bean should retain weak affinity for this node - Assert.assertEquals(failoverTarget, failbackTarget); - - result = bean.increment(); - // Bean may have acquired new weak affinity - target = result.getNode(); - Assert.assertEquals(count++, result.getValue().intValue()); - - // Bean should retain weak affinity for this node - for (int i = 0; i < COUNT; ++i) { - result = bean.increment(); - Assert.assertEquals(count++, result.getValue().intValue()); - Assert.assertEquals(String.valueOf(i), target, result.getNode()); - } - - stop(this.findContainer(target)); - - result = bean.increment(); - // Bean should failover to other node - failoverTarget = result.getNode(); - - Assert.assertEquals(count++, result.getValue().intValue()); - Assert.assertNotEquals(target, failoverTarget); - - start(this.findContainer(target)); - - // Allow sufficient time for client to receive new topology - Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT); - - result = bean.increment(); - failbackTarget = result.getNode(); - Assert.assertEquals(count++, result.getValue().intValue()); - // Bean should retain weak affinity for this node - Assert.assertEquals(failoverTarget, failbackTarget); - - result = bean.increment(); - // Bean may have acquired new weak affinity - target = result.getNode(); - Assert.assertEquals(count++, result.getValue().intValue()); - - // Bean should retain weak affinity for this node - for (int i = 0; i < COUNT; ++i) { - result = bean.increment(); - Assert.assertEquals(count++, result.getValue().intValue()); - Assert.assertEquals(String.valueOf(i), target, result.getNode()); - } - } + public RemoteStatefulEJBFailoverTestCase() { + super(() -> new RemoteEJBDirectory(MODULE_NAME)); } } diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatelessEJBFailoverTestCase.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatelessEJBFailoverTestCase.java index ceea8a1b496e..3078ac136391 100644 --- a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatelessEJBFailoverTestCase.java +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/cluster/ejb/remote/RemoteStatelessEJBFailoverTestCase.java @@ -22,20 +22,13 @@ package org.jboss.as.test.clustering.cluster.ejb.remote; -import java.util.PropertyPermission; import java.util.function.UnaryOperator; import org.jboss.arquillian.container.test.api.Deployment; import org.jboss.arquillian.container.test.api.TargetsContainer; -import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Incrementor; -import org.jboss.as.test.clustering.cluster.ejb.remote.bean.IncrementorBean; -import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Result; import org.jboss.as.test.clustering.cluster.ejb.remote.bean.StatelessIncrementorBean; -import org.jboss.as.test.clustering.ejb.EJBDirectory; -import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils; +import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory; import org.jboss.shrinkwrap.api.Archive; -import org.jboss.shrinkwrap.api.ShrinkWrap; -import org.jboss.shrinkwrap.api.spec.JavaArchive; /** * Validates failover behavior of a remotely accessed @Stateless EJB. @@ -47,24 +40,16 @@ public class RemoteStatelessEJBFailoverTestCase extends AbstractRemoteStatelessE @Deployment(name = DEPLOYMENT_1, managed = false, testable = false) @TargetsContainer(CONTAINER_1) public static Archive createDeploymentForContainer1() { - return createDeployment(); + return createDeployment(MODULE_NAME); } @Deployment(name = DEPLOYMENT_2, managed = false, testable = false) @TargetsContainer(CONTAINER_2) public static Archive createDeploymentForContainer2() { - return createDeployment(); - } - - private static Archive createDeployment() { - return ShrinkWrap.create(JavaArchive.class, MODULE_NAME + ".jar") - .addPackage(EJBDirectory.class.getPackage()) - .addClasses(Result.class, Incrementor.class, IncrementorBean.class, StatelessIncrementorBean.class) - .addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new PropertyPermission(NODE_NAME_PROPERTY, "read")), "permissions.xml") - ; + return createDeployment(MODULE_NAME); } public RemoteStatelessEJBFailoverTestCase() { - super(MODULE_NAME, StatelessIncrementorBean.class, UnaryOperator.identity()); + super(() -> new RemoteEJBDirectory(MODULE_NAME), StatelessIncrementorBean.class, UnaryOperator.identity()); } } diff --git a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/ejb/ClientEJBDirectory.java b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/ejb/ClientEJBDirectory.java index 10fce23d885b..daa4e2951bc3 100644 --- a/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/ejb/ClientEJBDirectory.java +++ b/testsuite/integration/clustering/src/test/java/org/jboss/as/test/clustering/ejb/ClientEJBDirectory.java @@ -53,12 +53,12 @@ public T lookupStateful(String beanName, Class beanInterface) throws Exce } @Override - public T lookupStateless(String beanName, Class beanInterface) throws Exception { + public T lookupStateless(String beanName, Class beanInterface) { return EJBClient.createProxy(this.createStatelessLocator(beanName, beanInterface)); } @Override - public T lookupSingleton(String beanName, Class beanInterface) throws Exception { + public T lookupSingleton(String beanName, Class beanInterface) { return EJBClient.createProxy(this.createStatelessLocator(beanName, beanInterface)); }