Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[WIP] tck multithread failures #673

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription;
import org.jboss.shrinkwrap.api.Archive;

Expand All @@ -32,7 +34,7 @@ public class DeploymentScenario {
private final List<Deployment> deployments;

public DeploymentScenario() {
this.deployments = new ArrayList<Deployment>();
this.deployments = new CopyOnWriteArrayList<>();
}

public DeploymentScenario addDeployment(DeploymentDescription deployment) {
Expand Down Expand Up @@ -314,4 +316,4 @@ private void validateNotSameArchiveAndSameTarget(DeploymentDescription deploymen
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
package org.jboss.arquillian.container.test.impl.client;

import java.lang.reflect.Method;
import java.util.Objects;

import org.jboss.arquillian.container.spi.Container;
import org.jboss.arquillian.container.spi.ContainerRegistry;
import org.jboss.arquillian.container.spi.client.deployment.Deployment;
Expand Down Expand Up @@ -136,12 +138,11 @@ private void createContext(EventContext<? extends TestEvent> context) {
* TODO: This should not rely on direct Reflection, but rather access the metadata through some
* common metadata layer.
*/

private void lookup(Method method, ResultCallback callback) {
DeploymentTargetDescription deploymentTarget = locateDeployment(method);

ContainerRegistry containerRegistry = this.containerRegistry.get();
DeploymentScenario deploymentScenario = this.deploymentScenario.get();
DeploymentScenario deploymentScenario = Objects.requireNonNull(this.deploymentScenario.get(), "deploymentScenario cannot be null");

Deployment deployment = deploymentScenario.deployment(deploymentTarget);
if (deployment == null && deploymentTarget != DeploymentTargetDescription.DEFAULT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@
*/
package org.jboss.arquillian.core.impl;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jboss.arquillian.core.spi.EventContext;
import org.jboss.arquillian.core.spi.InvocationException;
import org.jboss.arquillian.core.spi.NonManagedObserver;
Expand All @@ -32,8 +33,8 @@
*/
public class EventContextImpl<T> implements EventContext<T> {
private ManagerImpl manager;
private List<ObserverMethod> interceptors;
private List<ObserverMethod> observers;
private List<ObserverMethod> interceptors = new CopyOnWriteArrayList<>();
private List<ObserverMethod> observers = new CopyOnWriteArrayList<>();
private NonManagedObserver<T> nonManagedObserver;
private RuntimeLogger runtimeLogger;

Expand Down Expand Up @@ -70,8 +71,12 @@ public EventContextImpl(ManagerImpl manager, List<ObserverMethod> interceptors,
Validate.notNull(runtimeLogger, "Runtime logger must be specified");

this.manager = manager;
this.interceptors = interceptors == null ? new ArrayList<ObserverMethod>() : interceptors;
this.observers = observers == null ? new ArrayList<ObserverMethod>() : observers;
if(interceptors!=null) {
this.interceptors.addAll(interceptors);
}
if(observers!=null) {
this.observers.addAll(observers);
}
this.nonManagedObserver = nonManagedObserver;
this.event = event;
this.runtimeLogger = runtimeLogger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@
import java.util.List;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;

import org.jboss.arquillian.core.api.Injector;
import org.jboss.arquillian.core.api.annotation.ApplicationScoped;
import org.jboss.arquillian.core.api.event.ManagerStarted;
Expand Down Expand Up @@ -70,13 +72,13 @@ public class ManagerImpl implements Manager {
new ArquillianThreadLocal<Set<Class<? extends Throwable>>>() {
@Override
protected Set<Class<? extends Throwable>> initialValue() {
return new HashSet<Class<? extends Throwable>>();
return new HashSet<>();
}
};

ManagerImpl(final Collection<Class<? extends Context>> contextClasses, final Collection<Class<?>> extensionClasses) {
this.contexts = new ArrayList<Context>();
this.extensions = new ArrayList<Extension>();
this.contexts = new CopyOnWriteArrayList<>();
this.extensions = new CopyOnWriteArrayList<>();
this.runtimeLogger = new RuntimeLogger();

try {
Expand Down Expand Up @@ -129,7 +131,7 @@ public <T> void fire(T event, NonManagedObserver<T> nonManagedObserver) {
context.activate();
activatedApplicationContext = true;
}
new EventContextImpl<T>(this, interceptorObservers, observers, nonManagedObserver, event,
new EventContextImpl<>(this, interceptorObservers, observers, nonManagedObserver, event,
runtimeLogger).proceed();
} catch (Exception e) {
Throwable fireException = e;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
public class JUnitJupiterTestClassLifecycleManager implements ExtensionContext.Store.CloseableResource {
private static final String MANAGER_KEY = "testRunnerManager";

private TestRunnerAdaptor adaptor;
private volatile TestRunnerAdaptor adaptor;

private Throwable caughtInitializationException;

private JUnitJupiterTestClassLifecycleManager() {
private JUnitJupiterTestClassLifecycleManager() throws Exception {
initializeAdaptor();
}

static JUnitJupiterTestClassLifecycleManager getManager(ExtensionContext context) throws Exception {
Expand All @@ -22,7 +23,6 @@ static JUnitJupiterTestClassLifecycleManager getManager(ExtensionContext context
if (instance == null) {
instance = new JUnitJupiterTestClassLifecycleManager();
store.put(MANAGER_KEY, instance);
instance.initializeAdaptor();
}
// no, initialization has been attempted before and failed, refuse
// to do anything else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@
*/
package org.jboss.arquillian.test.impl;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.jboss.arquillian.core.api.Instance;
import org.jboss.arquillian.core.api.InstanceProducer;
import org.jboss.arquillian.core.api.annotation.Inject;
Expand Down Expand Up @@ -59,7 +60,7 @@ public class TestContextHandler {

// Since there can be multiple AfterTestLifecycleEvents (After/AfterRules)
// and we don't know which is the last one, perform the clean up in AfterClass.
private Map<Class<?>, Set<Object>> activatedTestContexts = new HashMap<Class<?>, Set<Object>>();
private Map<Class<?>, Set<Object>> activatedTestContexts = new ConcurrentHashMap<>();

public void createSuiteContext(@Observes(precedence = 100) EventContext<SuiteEvent> context) {
SuiteContext suiteContext = this.suiteContextInstance.get();
Expand Down