Skip to content

Commit

Permalink
Add test case variants that use ClientEJBDirectory.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Sep 28, 2017
1 parent c1d7b52 commit 065438e
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 146 deletions.
@@ -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());
}
}
}
}
Expand Up @@ -27,20 +27,28 @@
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;

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.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.
Expand All @@ -54,20 +62,28 @@ 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<EJBDirectory, Exception> directoryProvider;
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;
AbstractRemoteStatelessEJBFailoverTestCase(ExceptionSupplier<EJBDirectory, Exception> directoryProvider, Class<? extends Incrementor> beanClass, UnaryOperator<Callable<Void>> configurator) {
this.directoryProvider = directoryProvider;
this.beanClass = beanClass;
this.configurator = configurator;
}

@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
Expand Down
Expand Up @@ -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;
Expand All @@ -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<Callable<Void>> configurator) {
super(MODULE_NAME, SecureStatelessIncrementorBean.class, configurator);
super(() -> new RemoteEJBDirectory(MODULE_NAME), SecureStatelessIncrementorBean.class, configurator);
}
}

@@ -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));
}
}
@@ -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());
}
}
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 065438e

Please sign in to comment.