Skip to content

Commit

Permalink
WFLY-4255 Allow Arquillian to specify a timeout value for the WildFly…
Browse files Browse the repository at this point in the history
… clean shutdown mechanism when shutting down a server

WFLY-3532 Reenable RemoteFailoverTestCase stabilized by graceful shutdown arquillian support
  • Loading branch information
rhusar committed Jul 26, 2016
1 parent 27e5ef0 commit 38225f8
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 40 deletions.
Expand Up @@ -76,6 +76,7 @@ public interface ClusteringTestConstants {
* Timeouts.
*/
int GRACE_TIME_TO_REPLICATE = TimeoutUtil.adjust(3000);
int GRACEFUL_SHUTDOWN_TIMEOUT = TimeoutUtil.adjust(15);

/**
* TODO: This will be removed.
Expand Down
Expand Up @@ -23,6 +23,7 @@

import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.as.arquillian.api.WildFlyContainerController;
import org.jboss.logging.Logger;

/**
Expand Down Expand Up @@ -84,6 +85,18 @@ public static void stop(ContainerController controller, String... containers) {
}
}

public static void stop(int timeout, WildFlyContainerController controller, String... containers) {
for (String container : containers) {
try {
log.info("Stopping container=" + container + ", timeout=" + timeout);
controller.stop(container, timeout);
log.info("Stopped container=" + container + ", timeout=" + timeout);
} catch (Throwable e) {
log.error("Failed to stop containers", e);
}
}
}

public static void stop(ContainerController controller, Deployer deployer, String container, String deployment) {
try {
log.info("Stopping deployment=" + deployment + ", container=" + container);
Expand Down
Expand Up @@ -26,10 +26,10 @@

import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.jboss.arquillian.container.test.api.ContainerController;
import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.as.arquillian.api.WildFlyContainerController;
import org.jboss.as.test.clustering.ClusteringTestConstants;
import org.jboss.as.test.clustering.NodeUtil;
import org.jboss.as.web.session.RoutingSupport;
Expand Down Expand Up @@ -75,7 +75,7 @@ protected static Map.Entry<String, String> parseSessionRoute(HttpResponse respon
}

@ArquillianResource
protected ContainerController controller;
protected WildFlyContainerController controller;
@ArquillianResource
protected Deployer deployer;

Expand Down Expand Up @@ -111,6 +111,10 @@ protected void stop(String... containers) {
NodeUtil.stop(this.controller, containers);
}

protected void stop(int timeout, String... containers) {
NodeUtil.stop(timeout, this.controller, containers);
}

protected void deploy(String... deployments) {
NodeUtil.deploy(this.deployer, deployments);
}
Expand Down Expand Up @@ -153,7 +157,7 @@ public void stop(String... nodes) {
ClusterAbstractTestCase.this.stop(this.getContainers(nodes));
}

private String[] getContainers(String... nodes) {
String[] getContainers(String... nodes) {
String[] containers = new String[nodes.length];
for (int i = 0; i < nodes.length; ++i) {
String node = nodes[i];
Expand All @@ -167,6 +171,13 @@ private String[] getContainers(String... nodes) {
}
}

public class GracefulRestartLifecycle extends RestartLifecycle {
@Override
public void stop(String... nodes) {
ClusterAbstractTestCase.this.stop(GRACEFUL_SHUTDOWN_TIMEOUT, this.getContainers(nodes));
}
}

public class RedeployLifecycle implements Lifecycle {
@Override
public void start(String... nodes) {
Expand Down
Expand Up @@ -290,10 +290,18 @@ public void testStatefulFailover() throws Exception {
}
}

@InSequence(3)
@Test
@Ignore("WFLY-3532")
public void testConcurrentFailover() throws Exception {
public void testGracefulShutdownConcurrentFailover() throws Exception {
this.testConcurrentFailover(new GracefulRestartLifecycle());
}

@Test
@Ignore("Needs graceful undeploy support")
public void testGracefulUndeployConcurrentFailover() throws Exception {
this.testConcurrentFailover(new RedeployLifecycle());
}

public void testConcurrentFailover(Lifecycle lifecycle) throws Exception {
ContextSelector<EJBClientContext> selector = EJBClientContextSelector.setup(CLIENT_PROPERTIES);
try (EJBDirectory directory = new RemoteEJBDirectory(MODULE_NAME)) {
Incrementor bean = directory.lookupStateful(SlowToDestroyStatefulIncrementorBean.class, Incrementor.class);
Expand All @@ -310,37 +318,7 @@ public void testConcurrentFailover() throws Exception {
Future<?> future = executor.scheduleWithFixedDelay(new IncrementTask(bean, count, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
latch.await();

undeploy(this.findDeployment(target));

future.cancel(false);
try {
future.get();
} catch (CancellationException e) {
// Ignore
}

deploy(this.findDeployment(target));

latch = new CountDownLatch(1);
future = executor.scheduleWithFixedDelay(new IncrementTask(bean, count, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
latch.await();

stop(this.findContainer(target));

future.cancel(false);
try {
future.get();
} catch (CancellationException e) {
// Ignore
}

start(this.findContainer(target));

latch = new CountDownLatch(1);
future = executor.scheduleWithFixedDelay(new LookupTask(directory, SlowToDestroyStatefulIncrementorBean.class, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
latch.await();

undeploy(this.findDeployment(target));
lifecycle.stop(target);

future.cancel(false);
try {
Expand All @@ -349,13 +327,13 @@ public void testConcurrentFailover() throws Exception {
// Ignore
}

deploy(this.findDeployment(target));
lifecycle.start(target);

latch = new CountDownLatch(1);
future = executor.scheduleWithFixedDelay(new LookupTask(directory, SlowToDestroyStatefulIncrementorBean.class, latch), 0, INVOCATION_WAIT, TimeUnit.MILLISECONDS);
latch.await();

stop(this.findContainer(target));
lifecycle.stop(target);

future.cancel(false);
try {
Expand All @@ -364,7 +342,7 @@ public void testConcurrentFailover() throws Exception {
// Ignore
}

start(this.findContainer(target));
lifecycle.start(target);
} finally {
executor.shutdownNow();
}
Expand Down

0 comments on commit 38225f8

Please sign in to comment.