Skip to content

Commit

Permalink
Not using own methods for undeploying and deploying
Browse files Browse the repository at this point in the history
- Just blocking oryginal events when needed and pushing on other times
  • Loading branch information
ingwarsw committed Jun 10, 2014
1 parent 6a71549 commit 767cc8c
Showing 1 changed file with 45 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,8 @@
import org.eu.ingwar.tools.arquillian.extension.suite.annotations.ArquillianSuiteDeployment;
import org.eu.ingwar.tools.arquillian.extension.suite.annotations.ArquilianSuiteDeployment;
import java.util.Set;
import org.jboss.arquillian.container.spi.ContainerRegistry;
import org.jboss.arquillian.container.spi.client.deployment.Deployment;
import org.jboss.arquillian.container.spi.client.deployment.DeploymentScenario;
import org.jboss.arquillian.container.spi.event.DeployDeployment;
import org.jboss.arquillian.container.spi.event.DeployManagedDeployments;
import org.jboss.arquillian.container.spi.event.DeploymentEvent;
import org.jboss.arquillian.container.spi.event.UnDeployDeployment;
import org.jboss.arquillian.container.spi.event.UnDeployManagedDeployments;
import org.jboss.arquillian.container.spi.event.container.AfterStart;
import org.jboss.arquillian.container.spi.event.container.BeforeStop;
Expand All @@ -44,7 +39,6 @@
import org.jboss.arquillian.test.spi.TestClass;
import org.jboss.arquillian.test.spi.annotation.ClassScoped;
import org.jboss.arquillian.test.spi.context.ClassContext;

import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
Expand All @@ -58,7 +52,7 @@
*/
public class ArquillianSuiteExtension implements LoadableExtension {

private static final Logger LOG = Logger.getLogger(ArquillianSuiteExtension.class.getName());
private static final Logger log = Logger.getLogger(ArquillianSuiteExtension.class.getName());
private static Class<?> deploymentClass;

/**
Expand All @@ -70,7 +64,7 @@ public void register(ExtensionBuilder builder) {
if (deploymentClass != null) {
builder.observer(SuiteDeployer.class).context(ExtendedSuiteContextImpl.class);
} else {
LOG.log(Level.WARNING, "arquillian-suite-deployment: Cannot find class annotated with @ArquillianSuiteDeployment, will try normal way..");
log.log(Level.WARNING, "arquillian-suite-deployment: Cannot find class annotated with @ArquillianSuiteDeployment, will try normal way..");
}
}

Expand All @@ -91,7 +85,7 @@ private static Class<?> getDeploymentClass() {
}
if (results.size() > 1) {
for (Class<?> type : results) {
LOG.log(Level.SEVERE, "arquillian-suite-deployment: Duplicated class annotated with @ArquillianSuiteDeployment: {0}", type.getName());
log.log(Level.SEVERE, "arquillian-suite-deployment: Duplicated class annotated with @ArquillianSuiteDeployment: {0}", type.getName());
}
throw new IllegalStateException("Duplicated classess annotated with @ArquillianSuiteDeployment");
}
Expand All @@ -109,71 +103,67 @@ public static class SuiteDeployer {
@ClassScoped
private InstanceProducer<DeploymentScenario> classDeploymentScenario;
@Inject
private Event<DeploymentEvent> deploymentEvent;
@Inject
private Instance<ExtendedSuiteContext> extendedSuiteContext;
private Event<UnDeployManagedDeployments> undeployEvent;
@Inject
private Event<GenerateDeployment> generateDeploymentEvent;
private boolean suiteDeploymentGenerated;
@Inject
private Instance<ExtendedSuiteContext> extendedSuiteContext;
private DeploymentScenario suiteDeploymentScenario;
@ExtendedSuiteScoped
@Inject
private InstanceProducer<DeploymentScenario> suiteDeploymentScenarioInstanceProducer;
private boolean suiteDeploymentGenerated;
private boolean deployDeployments;
private boolean undeployDeployments;

/**
* Method ignoring DeployManagedDeployments events.
* Method ignoring DeployManagedDeployments events if already deployed.
*
* @param ignored Event to ignore
*/
public void blockDeployManagedDeployments(@Observes EventContext<DeployManagedDeployments> ignored) {
debug("Blocking DeployManagedDeployments event {}", ignored.getEvent().toString());
public void blockDeployManagedDeploymentsWhenNeeded(@Observes EventContext<DeployManagedDeployments> eventContext) {
if (deployDeployments) {
debug("NOT Blocking DeployManagedDeployments event {}", eventContext.getEvent().toString());
eventContext.proceed();
deployDeployments = false;
} else {
// Do nothing with event.
debug("Blocking DeployManagedDeployments event {}", eventContext.getEvent().toString());
}
}

/**
* Method ignoring GenerateDeployment events if deployment is already done.
*
* @param eventContext Event to ignore or fire.
*/
public void blockSubsquentGenerateDeployment(@Observes EventContext<GenerateDeployment> eventContext) {
public void blockGenerateDeploymentWhenNeeded(@Observes EventContext<GenerateDeployment> eventContext) {
if (suiteDeploymentGenerated) {
debug("Blocking GenerateDeployment event {}", eventContext.getEvent().toString());
// Do nothing with event.
return;
debug("Blocking GenerateDeployment event {}", eventContext.getEvent().toString());
} else {
debug("NOT Blocking GenerateDeployment event {}", eventContext.getEvent().toString());
eventContext.proceed();
suiteDeploymentGenerated = true;
}
eventContext.proceed();
suiteDeploymentGenerated = true;
}

/**
* Method ignoring UnDeployManagedDeployments events.
* Method ignoring UnDeployManagedDeployments events at runtime.
*
* @param ignored Event to ignore
*/
public void blockUnDeployManagedDeployments(@Observes EventContext<UnDeployManagedDeployments> ignored) {
debug("Blocking UnDeployManagedDeployments event {}", ignored.getEvent().toString());
}

/**
* Deploy event.
* Only at undeploy container we will undeploy all.
*
* @param event event to observe
* @param registry ContainerRegistry
* @param ignored Event to ignore
*/
public void deploy(@Observes(precedence = -200) final AfterStart event, final ContainerRegistry registry) {
executeInClassScope(new Callable<Void>() {
@Override
public Void call() {
for (Deployment d : suiteDeploymentScenario.managedDeploymentsInDeployOrder()) {
debug("DEPLOY: {0} prio {1}", d.getDescription().getName(), d.getDescription().getOrder());
deploymentEvent.fire(new DeployDeployment(registry.getContainer(d.getDescription().getTarget()), d));
}
final ExtendedSuiteContext extendedSuiteContextLocal = SuiteDeployer.this.extendedSuiteContext.get();
if (!extendedSuiteContextLocal.isActive()) {
extendedSuiteContextLocal.deactivate();
}
return null;
}
});
public void blockUnDeployManagedDeploymentsWhenNeeded(@Observes EventContext<UnDeployManagedDeployments> eventContext) {
if (undeployDeployments) {
debug("NOT Blocking UnDeployManagedDeployments event {}", eventContext.getEvent().toString());
eventContext.proceed();
undeployDeployments = false;
} else {
// Do nothing with event.
debug("Blocking UnDeployManagedDeployments event {}", eventContext.getEvent().toString());
}
}

/**
Expand All @@ -186,15 +176,12 @@ public void startup(@Observes(precedence = -100) final AfterStart event) {
executeInClassScope(new Callable<Void>() {
@Override
public Void call() {
try {
generateDeploymentEvent.fire(new GenerateDeployment(new TestClass(deploymentClass)));
suiteDeploymentScenario = classDeploymentScenario.get();
} catch (Exception ex) {
ex.printStackTrace(); // NOPMD
}
generateDeploymentEvent.fire(new GenerateDeployment(new TestClass(deploymentClass)));
suiteDeploymentScenario = classDeploymentScenario.get();
return null;
}
});
deployDeployments = true;
extendedSuiteContext.get().activate();
suiteDeploymentScenarioInstanceProducer.set(suiteDeploymentScenario);
}
Expand All @@ -203,19 +190,11 @@ public Void call() {
* Undeploy event.
*
* @param event event to observe
* @param registry ContainerRegistry
*/
public void undeploy(@Observes final BeforeStop event, final ContainerRegistry registry) {
executeInClassScope(new Callable<Void>() {
@Override
public Void call() {
for (Deployment d : suiteDeploymentScenario.deployedDeploymentsInUnDeployOrder()) {
debug("UNDEPLOY: {0}", d.getDescription().getName());
deploymentEvent.fire(new UnDeployDeployment(registry.getContainer(d.getDescription().getTarget()), d));
}
return null;
}
});
public void undeploy(@Observes final BeforeStop event) {
debug("Catching BeforeStop event {0}", event.toString());
undeployDeployments = true;
undeployEvent.fire(new UnDeployManagedDeployments());
}

/**
Expand Down Expand Up @@ -244,7 +223,7 @@ private void executeInClassScope(Callable<Void> call) {
*/
private void debug(String format, Object... message) {
if (ManagerImpl.DEBUG) {
LOG.log(Level.WARNING, format, message);
log.log(Level.WARNING, format, message);
}
}
}
Expand Down

0 comments on commit 767cc8c

Please sign in to comment.