Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add test case variants that use ClientEJBDirectory.
- Loading branch information
Showing
9 changed files
with
291 additions
and
146 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
...boss/as/test/clustering/cluster/ejb/remote/AbstractRemoteStatefulEJBFailoverTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<EJBDirectory, Exception> directoryProvider; | ||
|
||
protected AbstractRemoteStatefulEJBFailoverTestCase(ExceptionSupplier<EJBDirectory, Exception> 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<Integer> 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()); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
.../jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatefulEJBFailoverTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...jboss/as/test/clustering/cluster/ejb/remote/ClientRemoteStatelessEJBFailoverTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.