Merged branch 'jetty-9.4.x' into 'master'.

This commit is contained in:
Simone Bordet 2016-08-19 01:48:29 +02:00
commit 2d5078cc24
1 changed files with 372 additions and 368 deletions

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.util.component;
import static org.hamcrest.CoreMatchers.containsString;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.StringReader;
@ -29,147 +27,94 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.eclipse.jetty.util.TypeUtil;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
public class ContainerLifeCycleTest
{
@Rule
public ExpectedException expectedException = ExpectedException.none();
@Test
public void testStartStopDestroy() throws Exception
public void testStartStop() throws Exception
{
final AtomicInteger destroyed=new AtomicInteger();
final AtomicInteger started=new AtomicInteger();
final AtomicInteger stopped=new AtomicInteger();
ContainerLifeCycle a0=new ContainerLifeCycle();
ContainerLifeCycle a1=new ContainerLifeCycle()
{
@Override
protected void doStart() throws Exception
{
started.incrementAndGet();
super.doStart();
}
@Override
protected void doStop() throws Exception
{
stopped.incrementAndGet();
super.doStop();
}
@Override
public void destroy()
{
destroyed.incrementAndGet();
super.destroy();
}
};
ContainerLifeCycle a0 = new ContainerLifeCycle();
TestContainerLifeCycle a1 = new TestContainerLifeCycle();
a0.addBean(a1);
a0.start();
Assert.assertEquals(1,started.get());
Assert.assertEquals(0,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.start();
Assert.assertEquals(1,started.get());
Assert.assertEquals(0,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.stop();
Assert.assertEquals(1,started.get());
Assert.assertEquals(1,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.start();
Assert.assertEquals(2,started.get());
Assert.assertEquals(1,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(2, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.stop();
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(0,destroyed.get());
a0.destroy();
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(1,destroyed.get());
try
{
a0.start();
expectedException.reportMissingExceptionWithMessage("Expected IllegalStateException");
} catch(IllegalStateException ignore) {
// ignored
}
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(1,destroyed.get());
a0.addBean(a1);
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(1,destroyed.get());
Assert.assertFalse(a0.isManaged(a1));
try
{
a0.start();
expectedException.reportMissingExceptionWithMessage("Expected IllegalStateException");
} catch(IllegalStateException ignore) {
// ignored
}
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(1,destroyed.get());
try
{
a1.start();
expectedException.reportMissingExceptionWithMessage("Expected IllegalStateException");
} catch(IllegalStateException ignore) {
// ignored
}
a0.manage(a1);
Assert.assertEquals(3,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(1,destroyed.get());
a0.removeBean(a1);
Assert.assertEquals(3,started.get());
Assert.assertEquals(3,stopped.get());
Assert.assertEquals(1,destroyed.get());
a0.stop();
a0.destroy();
Assert.assertEquals(3,started.get());
Assert.assertEquals(3,stopped.get());
Assert.assertEquals(1,destroyed.get());
a1.stop();
Assert.assertEquals(3,started.get());
Assert.assertEquals(3,stopped.get());
Assert.assertEquals(1,destroyed.get());
a1.destroy();
Assert.assertEquals(3,started.get());
Assert.assertEquals(3,stopped.get());
Assert.assertEquals(2,destroyed.get());
Assert.assertEquals(2, a1.started.get());
Assert.assertEquals(2, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
}
@Test
public void testStartStopDestroy() throws Exception
{
ContainerLifeCycle a0 = new ContainerLifeCycle();
TestContainerLifeCycle a1 = new TestContainerLifeCycle();
a0.start();
Assert.assertEquals(0, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.addBean(a1);
Assert.assertEquals(0, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
Assert.assertFalse(a0.isManaged(a1));
a0.start();
Assert.assertEquals(0, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a1.start();
a0.manage(a1);
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.removeBean(a1);
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.stop();
a0.destroy();
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a1.stop();
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a1.destroy();
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(1, a1.destroyed.get());
}
@Test(expected = IllegalStateException.class)
public void testIllegalToStartAfterDestroy() throws Exception
{
ContainerLifeCycle container = new ContainerLifeCycle();
@ -178,43 +123,14 @@ public class ContainerLifeCycleTest
container.destroy();
// Should throw IllegalStateException.
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage(containsString("Destroyed"));
container.start();
}
@Test
public void testDisJoint() throws Exception
{
final AtomicInteger destroyed=new AtomicInteger();
final AtomicInteger started=new AtomicInteger();
final AtomicInteger stopped=new AtomicInteger();
ContainerLifeCycle a0=new ContainerLifeCycle();
ContainerLifeCycle a1=new ContainerLifeCycle()
{
@Override
protected void doStart() throws Exception
{
started.incrementAndGet();
super.doStart();
}
@Override
protected void doStop() throws Exception
{
stopped.incrementAndGet();
super.doStop();
}
@Override
public void destroy()
{
destroyed.incrementAndGet();
super.destroy();
}
};
ContainerLifeCycle a0 = new ContainerLifeCycle();
TestContainerLifeCycle a1 = new TestContainerLifeCycle();
// Start the a1 bean before adding, makes it auto disjoint
a1.start();
@ -224,127 +140,127 @@ public class ContainerLifeCycleTest
Assert.assertFalse(a0.isManaged(a1));
a0.start();
Assert.assertEquals(1,started.get());
Assert.assertEquals(0,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.start();
Assert.assertEquals(1,started.get());
Assert.assertEquals(0,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.stop();
Assert.assertEquals(1,started.get());
Assert.assertEquals(0,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(0, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a1.stop();
Assert.assertEquals(1,started.get());
Assert.assertEquals(1,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.start();
Assert.assertEquals(1,started.get());
Assert.assertEquals(1,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.manage(a1);
Assert.assertTrue(a0.isManaged(a1));
a0.stop();
Assert.assertEquals(1,started.get());
Assert.assertEquals(1,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(1, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.start();
Assert.assertEquals(2,started.get());
Assert.assertEquals(1,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(2, a1.started.get());
Assert.assertEquals(1, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.stop();
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(2, a1.started.get());
Assert.assertEquals(2, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a0.unmanage(a1);
Assert.assertFalse(a0.isManaged(a1));
a0.destroy();
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(0,destroyed.get());
Assert.assertEquals(2, a1.started.get());
Assert.assertEquals(2, a1.stopped.get());
Assert.assertEquals(0, a1.destroyed.get());
a1.destroy();
Assert.assertEquals(2,started.get());
Assert.assertEquals(2,stopped.get());
Assert.assertEquals(1,destroyed.get());
Assert.assertEquals(2, a1.started.get());
Assert.assertEquals(2, a1.stopped.get());
Assert.assertEquals(1, a1.destroyed.get());
}
@Test
public void testDumpable() throws Exception
{
ContainerLifeCycle a0 = new ContainerLifeCycle();
String dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
String dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
ContainerLifeCycle aa0 = new ContainerLifeCycle();
a0.addBean(aa0);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," +? org.eclipse.jetty.util.component.ContainerLife");
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " +? org.eclipse.jetty.util.component.ContainerLife");
ContainerLifeCycle aa1 = new ContainerLifeCycle();
a0.addBean(aa1);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," +? org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +? org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump,"");
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " +? org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +? org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, "");
ContainerLifeCycle aa2 = new ContainerLifeCycle();
a0.addBean(aa2,false);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," +? org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +? org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +~ org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump,"");
a0.addBean(aa2, false);
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " +? org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +? org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +~ org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, "");
aa1.start();
a0.start();
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +~ org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +~ org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump,"");
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +~ org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +~ org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, "");
a0.manage(aa1);
a0.removeBean(aa2);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump,"");
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, "");
ContainerLifeCycle aaa0 = new ContainerLifeCycle();
aa0.addBean(aaa0);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump,"");
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, "");
ContainerLifeCycle aa10 = new ContainerLifeCycle();
aa1.addBean(aa10,true);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," += org.eclipse.jetty.util.component.Container");
dump=check(dump,"");
aa1.addBean(aa10, true);
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " += org.eclipse.jetty.util.component.Container");
dump = check(dump, "");
final ContainerLifeCycle a1 = new ContainerLifeCycle();
final ContainerLifeCycle a2 = new ContainerLifeCycle();
@ -357,65 +273,65 @@ public class ContainerLifeCycleTest
public void dump(Appendable out, String indent) throws IOException
{
out.append(this.toString()).append("\n");
dump(out,indent,TypeUtil.asList(new Object[]{a1,a2}),TypeUtil.asList(new Object[]{a3,a4}));
dump(out, indent, TypeUtil.asList(new Object[]{a1, a2}), TypeUtil.asList(new Object[]{a3, a4}));
}
};
a0.addBean(aa,true);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | += org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump,"");
a0.addBean(aa, true);
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | += org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, "");
a2.addBean(aa0,true);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | += org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," | += org.eclipse.jetty.util.component.Conta");
dump=check(dump," | +~ org.eclipse.jetty.util.component.C");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump,"");
a2.addBean(aa0, true);
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | += org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " | += org.eclipse.jetty.util.component.Conta");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.C");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, "");
a2.unmanage(aa0);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | += org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Conta");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump," +- org.eclipse.jetty.util.component.Container");
dump=check(dump,"");
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | += org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.Conta");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, " +- org.eclipse.jetty.util.component.Container");
dump = check(dump, "");
a0.unmanage(aa);
dump=trim(a0.dump());
dump=check(dump,"org.eclipse.jetty.util.component.ContainerLifeCycl");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | +~ org.eclipse.jetty.util.component.Container");
dump=check(dump," += org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump," | += org.eclipse.jetty.util.component.Container");
dump=check(dump," +~ org.eclipse.jetty.util.component.ContainerLife");
dump=check(dump,"");
dump = trim(a0.dump());
dump = check(dump, "org.eclipse.jetty.util.component.ContainerLifeCycl");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | +~ org.eclipse.jetty.util.component.Container");
dump = check(dump, " += org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, " | += org.eclipse.jetty.util.component.Container");
dump = check(dump, " +~ org.eclipse.jetty.util.component.ContainerLife");
dump = check(dump, "");
}
@Test
public void listenerTest() throws Exception
{
@ -423,9 +339,9 @@ public class ContainerLifeCycleTest
final Queue<String> operation = new ConcurrentLinkedQueue<>();
final Queue<Container> parent = new ConcurrentLinkedQueue<>();
final Queue<Object> child = new ConcurrentLinkedQueue<>();
Container.Listener listener= new Container.Listener()
{
Container.Listener listener = new Container.Listener()
{
@Override
public void beanRemoved(Container p, Object c)
{
@ -434,7 +350,7 @@ public class ContainerLifeCycleTest
parent.add(p);
child.add(c);
}
@Override
public void beanAdded(Container p, Object c)
{
@ -443,30 +359,51 @@ public class ContainerLifeCycleTest
parent.add(p);
child.add(c);
}
public @Override String toString() {return "listener";}
public
@Override
String toString()
{
return "listener";
}
};
ContainerLifeCycle c0 = new ContainerLifeCycle() { public @Override String toString() {return "c0";}};
ContainerLifeCycle c00 = new ContainerLifeCycle() { public @Override String toString() {return "c00";}};
ContainerLifeCycle c0 = new ContainerLifeCycle()
{
public
@Override
String toString()
{
return "c0";
}
};
ContainerLifeCycle c00 = new ContainerLifeCycle()
{
public
@Override
String toString()
{
return "c00";
}
};
c0.addBean(c00);
String b000="b000";
String b000 = "b000";
c00.addBean(b000);
c0.addBean(listener);
Assert.assertEquals("listener",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(c00,child.poll());
Assert.assertEquals("listener", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(c00, child.poll());
Assert.assertEquals("listener",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(listener,child.poll());
Assert.assertEquals("listener", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(listener, child.poll());
Container.InheritedListener inherited= new Container.InheritedListener()
{
Container.InheritedListener inherited = new Container.InheritedListener()
{
@Override
public void beanRemoved(Container p, Object c)
{
@ -475,7 +412,7 @@ public class ContainerLifeCycleTest
parent.add(p);
child.add(c);
}
@Override
public void beanAdded(Container p, Object c)
{
@ -484,83 +421,122 @@ public class ContainerLifeCycleTest
parent.add(p);
child.add(c);
}
public @Override String toString() {return "inherited";}
public
@Override
String toString()
{
return "inherited";
}
};
c0.addBean(inherited);
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(c00,child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(c00, child.poll());
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(listener,child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(listener, child.poll());
Assert.assertEquals("listener",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(inherited,child.poll());
Assert.assertEquals("listener", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(inherited, child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(inherited, child.poll());
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(inherited,child.poll());
c0.start();
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c00,parent.poll());
Assert.assertEquals(b000,child.poll());
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("added",operation.poll());
Assert.assertEquals(c00,parent.poll());
Assert.assertEquals(inherited,child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c00, parent.poll());
Assert.assertEquals(b000, child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("added", operation.poll());
Assert.assertEquals(c00, parent.poll());
Assert.assertEquals(inherited, child.poll());
c0.removeBean(c00);
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("removed",operation.poll());
Assert.assertEquals(c00,parent.poll());
Assert.assertEquals(inherited,child.poll());
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("removed",operation.poll());
Assert.assertEquals(c00,parent.poll());
Assert.assertEquals(b000,child.poll());
Assert.assertEquals("listener",handled.poll());
Assert.assertEquals("removed",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(c00,child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("removed", operation.poll());
Assert.assertEquals(c00, parent.poll());
Assert.assertEquals(inherited, child.poll());
Assert.assertEquals("inherited",handled.poll());
Assert.assertEquals("removed",operation.poll());
Assert.assertEquals(c0,parent.poll());
Assert.assertEquals(c00,child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("removed", operation.poll());
Assert.assertEquals(c00, parent.poll());
Assert.assertEquals(b000, child.poll());
Assert.assertEquals("listener", handled.poll());
Assert.assertEquals("removed", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(c00, child.poll());
Assert.assertEquals("inherited", handled.poll());
Assert.assertEquals("removed", operation.poll());
Assert.assertEquals(c0, parent.poll());
Assert.assertEquals(c00, child.poll());
}
private final class InheritedListenerLifeCycle extends AbstractLifeCycle implements Container.InheritedListener
{
public @Override void beanRemoved(Container p, Object c){}
@Override
public void beanRemoved(Container p, Object c)
{
}
public @Override void beanAdded(Container p, Object c) {}
@Override
public void beanAdded(Container p, Object c)
{
}
public @Override String toString() {return "inherited";}
@Override
public String toString()
{
return "inherited";
}
}
@Test
public void testInheritedListener() throws Exception
{
ContainerLifeCycle c0 = new ContainerLifeCycle() { public @Override String toString() {return "c0";}};
ContainerLifeCycle c00 = new ContainerLifeCycle() { public @Override String toString() {return "c00";}};
ContainerLifeCycle c01 = new ContainerLifeCycle() { public @Override String toString() {return "c01";}};
Container.InheritedListener inherited= new InheritedListenerLifeCycle();
ContainerLifeCycle c0 = new ContainerLifeCycle()
{
public
@Override
String toString()
{
return "c0";
}
};
ContainerLifeCycle c00 = new ContainerLifeCycle()
{
public
@Override
String toString()
{
return "c00";
}
};
ContainerLifeCycle c01 = new ContainerLifeCycle()
{
public
@Override
String toString()
{
return "c01";
}
};
Container.InheritedListener inherited = new InheritedListenerLifeCycle();
c0.addBean(c00);
c0.start();
@ -577,31 +553,59 @@ public class ContainerLifeCycleTest
String trim(String s) throws IOException
{
StringBuilder b=new StringBuilder();
BufferedReader reader=new BufferedReader(new StringReader(s));
StringBuilder b = new StringBuilder();
BufferedReader reader = new BufferedReader(new StringReader(s));
for (String line=reader.readLine();line!=null;line=reader.readLine())
for (String line = reader.readLine(); line != null; line = reader.readLine())
{
if (line.length()>50)
line=line.substring(0,50);
if (line.length() > 50)
line = line.substring(0, 50);
b.append(line).append('\n');
}
return b.toString();
}
String check(String s,String x)
String check(String s, String x)
{
String r=s;
String r = s;
int nl = s.indexOf('\n');
if (nl>0)
if (nl > 0)
{
r=s.substring(nl+1);
s=s.substring(0,nl);
r = s.substring(nl + 1);
s = s.substring(0, nl);
}
Assert.assertEquals(x,s);
Assert.assertEquals(x, s);
return r;
}
private static class TestContainerLifeCycle extends ContainerLifeCycle
{
private final AtomicInteger destroyed = new AtomicInteger();
private final AtomicInteger started = new AtomicInteger();
private final AtomicInteger stopped = new AtomicInteger();
@Override
protected void doStart() throws Exception
{
started.incrementAndGet();
super.doStart();
}
@Override
protected void doStop() throws Exception
{
stopped.incrementAndGet();
super.doStop();
}
@Override
public void destroy()
{
destroyed.incrementAndGet();
super.destroy();
}
}
}