Skip to content

Commit

Permalink
Test that attempts to replicate the failure
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored and ropalka committed Oct 31, 2017
1 parent c6aa89b commit 8fb595d
Showing 1 changed file with 94 additions and 1 deletion.
Expand Up @@ -29,14 +29,20 @@
import static org.junit.Assert.fail;

import java.lang.reflect.Field;
import java.security.SecureRandom;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

import org.jboss.msc.util.TestServiceListener;
import org.jboss.msc.value.Values;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
Expand All @@ -49,6 +55,7 @@
*/
public class MultipleDependenciesTestCase extends AbstractServiceTest {

public static final String MODULE = "module";
private static Field dependenciesField;
private static final ServiceName firstServiceName = ServiceName.of("firstService");
private static final ServiceName secondServiceName = ServiceName.of("secondService");
Expand All @@ -67,6 +74,92 @@ public static void initDependenciesField() throws Exception {
dependenciesField.setAccessible(true);
}

@Test
public void testSomeThings2() throws Exception {
for(int i = 0; i < 1000; ++i) {

ServiceName s3 = ServiceName.JBOSS.append("s3");
ServiceName s2 = ServiceName.JBOSS.append("s2");
ServiceName s1 = ServiceName.JBOSS.append("s1");
ServiceController<Void> c3 = serviceContainer.addService(s3, new RootService(s3, s2.append(MODULE)))
.install();
ServiceController<Void> c2 = serviceContainer.addService(s2, new RootService(s2, s1.append(MODULE)))
.install();
ServiceController<Void> c1 = serviceContainer.addService(s1, new RootService(s1))
.install();
serviceContainer.awaitStability();
final CountDownLatch latch = new CountDownLatch(1);
c1.addListener(new AbstractServiceListener<Void>() {
@Override
public void transition(ServiceController<? extends Void> controller, ServiceController.Transition transition) {
if (transition.getAfter() == ServiceController.Substate.REMOVED) {
latch.countDown();
}
}
});
c1.setMode(ServiceController.Mode.REMOVE);
latch.await();
c1 = serviceContainer.addService(s1, new RootService(s1))
.install();
if(!serviceContainer.awaitStability(2, TimeUnit.SECONDS)) {
serviceContainer.dumpServices();
Assert.fail();
}
c1.setMode(ServiceController.Mode.REMOVE);
c2.setMode(ServiceController.Mode.REMOVE);
c3.setMode(ServiceController.Mode.REMOVE);
if(!serviceContainer.awaitStability(2, TimeUnit.SECONDS)) {
serviceContainer.dumpServices();
Assert.fail();
}
}
}

private class RootService extends AbstractService<Void> {
final ServiceName baseName;
private final ServiceName[] serviceNames;

private RootService(ServiceName baseName, ServiceName... serviceNames) {
this.baseName = baseName;
this.serviceNames = serviceNames;
}

@Override
public void start(final StartContext context) throws StartException {
ServiceName module = baseName.append(MODULE);
context.getChildTarget().addService(baseName.append("firstModuleUse"), new FirstModuleUseService())
.addDependency(module)
.install();
context.getChildTarget().addService(module, Service.NULL)
.addDependencies(serviceNames)
.install();
}
}

private class FirstModuleUseService extends AbstractService<Void> {

volatile boolean first = true;

@Override
public void start(final StartContext context) throws StartException {
if(first) {
first = false;
} else {
first = true;
context.getController().getParent().addListener(new AbstractServiceListener() {
@Override
public void transition(ServiceController controller, ServiceController.Transition transition) {
if(transition.getAfter() == ServiceController.Substate.DOWN) {
controller.setMode(ServiceController.Mode.ACTIVE);
controller.removeListener(this);
}
}
});
context.getController().getParent().setMode(ServiceController.Mode.NEVER);
}
}
}

@Test
public void test() throws Exception {
serviceContainer.addListener(listener);
Expand Down Expand Up @@ -218,4 +311,4 @@ private List<ServiceControllerImpl<?>> getServiceDependencies(ServiceController<
}
return depInstances;
}
}
}

0 comments on commit 8fb595d

Please sign in to comment.