Skip to content

Commit

Permalink
Split RemoteFailoverTestCase into separate tests. Disable reuseForks,…
Browse files Browse the repository at this point in the history
… absent another mechanism to isolate ejb client context between tests.
  • Loading branch information
pferraro committed Jul 7, 2017
1 parent 0709a85 commit 1160293
Show file tree
Hide file tree
Showing 10 changed files with 872 additions and 458 deletions.
17 changes: 14 additions & 3 deletions testsuite/integration/clustering/pom.xml
Expand Up @@ -22,6 +22,7 @@
<jbossas.ts.dir>${jbossas.ts.integ.dir}/..</jbossas.ts.dir> <jbossas.ts.dir>${jbossas.ts.integ.dir}/..</jbossas.ts.dir>
<jbossas.project.dir>${jbossas.ts.dir}/..</jbossas.project.dir> <jbossas.project.dir>${jbossas.ts.dir}/..</jbossas.project.dir>
<surefire.forked.process.timeout>3600</surefire.forked.process.timeout> <surefire.forked.process.timeout>3600</surefire.forked.process.timeout>
<test-group>org/jboss/as/test/clustering/cluster</test-group>
</properties> </properties>


<profiles> <profiles>
Expand Down Expand Up @@ -88,9 +89,11 @@
<phase>test</phase> <phase>test</phase>
<goals><goal>test</goal></goals> <goals><goal>test</goal></goals>
<configuration> <configuration>
<!-- Needed for EJB client tests -->
<reuseForks>false</reuseForks>
<!-- Tests to execute. --> <!-- Tests to execute. -->
<includes> <includes>
<include>org/jboss/as/test/clustering/cluster/**/*TestCase.java</include> <include>${test-group}/**/*TestCase.java</include>
</includes> </includes>


<!-- Parameters to test cases. --> <!-- Parameters to test cases. -->
Expand Down Expand Up @@ -207,8 +210,10 @@
<phase>test</phase> <phase>test</phase>
<goals><goal>test</goal></goals> <goals><goal>test</goal></goals>
<configuration> <configuration>
<!-- Needed for EJB client tests -->
<reuseForks>false</reuseForks>
<includes> <includes>
<include>org/jboss/as/test/clustering/cluster/**/*TestCase.java</include> <include>${test-group}/**/*TestCase.java</include>
</includes> </includes>
<systemPropertyVariables combine.children="append"> <systemPropertyVariables combine.children="append">
<arquillian.launch>clustering-all</arquillian.launch> <arquillian.launch>clustering-all</arquillian.launch>
Expand All @@ -226,6 +231,8 @@
<phase>test</phase> <phase>test</phase>
<goals><goal>test</goal></goals> <goals><goal>test</goal></goals>
<configuration> <configuration>
<!-- Needed for EJB client tests -->
<reuseForks>false</reuseForks>
<includes> <includes>
<include>org/jboss/as/test/clustering/cluster/**/*TestCase.java</include> <include>org/jboss/as/test/clustering/cluster/**/*TestCase.java</include>
</includes> </includes>
Expand All @@ -245,8 +252,10 @@
<phase>test</phase> <phase>test</phase>
<goals><goal>test</goal></goals> <goals><goal>test</goal></goals>
<configuration> <configuration>
<!-- Needed for EJB client tests -->
<reuseForks>false</reuseForks>
<includes> <includes>
<include>org/jboss/as/test/clustering/cluster/**/*TestCase.java</include> <include>${test-group}/**/*TestCase.java</include>
</includes> </includes>
<systemPropertyVariables combine.children="append"> <systemPropertyVariables combine.children="append">
<arquillian.launch>clustering-all</arquillian.launch> <arquillian.launch>clustering-all</arquillian.launch>
Expand Down Expand Up @@ -289,6 +298,8 @@
<phase>test</phase> <phase>test</phase>
<goals><goal>test</goal></goals> <goals><goal>test</goal></goals>
<configuration> <configuration>
<!-- Needed for EJB client tests -->
<reuseForks>false</reuseForks>
<!-- Force the order of tests --> <!-- Force the order of tests -->
<runOrder>reversealphabetical</runOrder> <runOrder>reversealphabetical</runOrder>


Expand Down
@@ -0,0 +1,151 @@
/*
* 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 static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.function.UnaryOperator;

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.Result;
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.ejb.client.ClusterAffinity;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.legacy.JBossEJBProperties;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Validates failover behavior of a remotely accessed @Stateless EJB.
* @author Paul Ferraro
*/
@RunWith(Arquillian.class)
@RunAsClient
public abstract class AbstractRemoteStatelessEJBFailoverTestCase extends ClusterAbstractTestCase {

private static final String CLIENT_PROPERTIES = "org/jboss/as/test/clustering/cluster/ejb/remote/jboss-ejb-client.properties";

private static final int COUNT = 20;
private static final long CLIENT_TOPOLOGY_UPDATE_WAIT = TimeoutUtil.adjust(5000);
private static final long INVOCATION_WAIT = TimeoutUtil.adjust(10);

private final String module;
private final Class<? extends Incrementor> beanClass;
private final UnaryOperator<Callable<Void>> configurator;

AbstractRemoteStatelessEJBFailoverTestCase(String module, Class<? extends Incrementor> beanClass, UnaryOperator<Callable<Void>> configurator) {
this.module = module;
this.beanClass = beanClass;
this.configurator = configurator;
}

@Test
public void test() throws Exception {
JBossEJBProperties.fromClassPath(this.getClass().getClassLoader(), CLIENT_PROPERTIES).runCallable(this.configurator.apply(() -> {
try (EJBDirectory directory = new RemoteEJBDirectory(this.module)) {
Incrementor bean = directory.lookupStateless(this.beanClass, Incrementor.class);
EJBClient.setStrongAffinity(bean, new ClusterAffinity("ejb"));

// Allow sufficient time for client to receive full topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);

List<String> results = new ArrayList<>(COUNT);
for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.add(result.getNode());
Thread.sleep(INVOCATION_WAIT);
}

for (String node : NODES) {
int frequency = Collections.frequency(results, node);
assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
}

undeploy(DEPLOYMENT_1);

for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}

Assert.assertEquals(0, Collections.frequency(results, NODE_1));
Assert.assertEquals(COUNT, Collections.frequency(results, NODE_2));

deploy(DEPLOYMENT_1);

// Allow sufficient time for client to receive new topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);

for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}

for (String node : NODES) {
int frequency = Collections.frequency(results, node);
assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
}

stop(CONTAINER_2);

for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}

Assert.assertEquals(COUNT, Collections.frequency(results, NODE_1));
Assert.assertEquals(0, Collections.frequency(results, NODE_2));

start(CONTAINER_2);

// Allow sufficient time for client to receive new topology
Thread.sleep(CLIENT_TOPOLOGY_UPDATE_WAIT);

for (int i = 0; i < COUNT; ++i) {
Result<Integer> result = bean.increment();
results.set(i, result.getNode());
Thread.sleep(INVOCATION_WAIT);
}

for (String node : NODES) {
int frequency = Collections.frequency(results, node);
assertTrue(String.valueOf(frequency) + " invocations were routed to " + node, frequency > 0);
}
}
return null;
}));
}
}
@@ -0,0 +1,80 @@
/*
* 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 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.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;

/**
* Validates failover behavior of a remotely accessed secure @Stateless EJB.
* @author Paul Ferraro
*/
public abstract class AuthContextRemoteStatelessEJBFailoverTestCase extends AbstractRemoteStatelessEJBFailoverTestCase {
private static final String MODULE_NAME = "secure-remote-stateless-ejb-failover-test";

static final AuthenticationContext AUTHENTICATION_CONTEXT = AuthenticationContext.captureCurrent().with(
MatchRule.ALL.matchAbstractType("ejb", "jboss"),
AuthenticationConfiguration.empty().useName("user1").usePassword("password1")
);

@Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
@TargetsContainer(CONTAINER_1)
public static Archive<?> createDeploymentForContainer1() {
return createDeployment();
}

@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")
;
}

public AuthContextRemoteStatelessEJBFailoverTestCase(UnaryOperator<Callable<Void>> configurator) {
super(MODULE_NAME, SecureStatelessIncrementorBean.class, configurator);
}
}

@@ -0,0 +1,103 @@
/*
* 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 static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.util.PropertyPermission;

import javax.ejb.EJBException;

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.InfinispanExceptionThrowingIncrementorBean;
import org.jboss.as.test.clustering.cluster.ejb.remote.bean.Result;
import org.jboss.as.test.clustering.ejb.EJBDirectory;
import org.jboss.as.test.clustering.ejb.RemoteEJBDirectory;
import org.jboss.as.test.shared.integration.ejb.security.PermissionUtils;
import org.jboss.ejb.client.ClusterAffinity;
import org.jboss.ejb.client.EJBClient;
import org.jboss.ejb.client.legacy.JBossEJBProperties;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

/**
* Test for WFLY-5788.
* @author Radoslav Husar
*/
@RunWith(Arquillian.class)
@RunAsClient
public class ClientExceptionRemoteEJBTestCase extends ClusterAbstractTestCase {
private static final String MODULE_NAME = "client-exception-remote-ejb-test";
private static final String CLIENT_PROPERTIES = "org/jboss/as/test/clustering/cluster/ejb/remote/jboss-ejb-client.properties";

@Deployment(name = DEPLOYMENT_1, managed = false, testable = false)
@TargetsContainer(CONTAINER_1)
public static Archive<?> createDeploymentForContainer1() {
return createDeployment();
}

@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, InfinispanExceptionThrowingIncrementorBean.class)
.setManifest(new StringAsset("Manifest-Version: 1.0\nDependencies: org.infinispan\n"))
.addAsManifestResource(PermissionUtils.createPermissionsXmlAsset(new PropertyPermission(NODE_NAME_PROPERTY, "read")), "permissions.xml")
;
}

@Test
public void test() throws Exception {
JBossEJBProperties.fromClassPath(this.getClass().getClassLoader(), CLIENT_PROPERTIES).runCallable(() -> {
try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = directory.lookupStateful(InfinispanExceptionThrowingIncrementorBean.class, Incrementor.class);
EJBClient.setStrongAffinity(bean, new ClusterAffinity("ejb"));

bean.increment();
} catch (Exception ejbException) {
assertTrue("Expected exception wrapped in EJBException, got " + ejbException.getClass(), ejbException instanceof EJBException);
assertNull("Cause of EJBException has not been removed", ejbException.getCause());
return null;
}
fail("Expected EJBException but didn't catch it");
return null;
});
}
}

0 comments on commit 1160293

Please sign in to comment.