Component state - A few more missing tests
This commit is contained in:
parent
c62d3800e6
commit
7ccae60ba9
1 changed files with 56 additions and 0 deletions
|
@ -515,6 +515,21 @@ public class TestComponentState
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Test: {@link ComponentState#destroy()} on an uninitialised component does nothing */
|
||||||
|
@Test
|
||||||
|
public void testDestroyUninitialised( )
|
||||||
|
{
|
||||||
|
final LCATest lcaTest = new LCATest( );
|
||||||
|
final NewComponentInfo< LCATest > ci = new NewComponentInfo< LCATest >( lcaTest ) //
|
||||||
|
.setLifecycleAction( LifecycleStage.DESTROY , ( o ) -> {
|
||||||
|
o.stage = LifecycleStage.DESTROY;
|
||||||
|
} );
|
||||||
|
final ComponentState cs = TestComponentState.makeState( ci , this.reg , false , false );
|
||||||
|
cs.destroy( );
|
||||||
|
Assert.assertNull( lcaTest.stage );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/** Test: {@link ComponentState#destroy()} re-throws {@link ComponentDestructionException} */
|
/** Test: {@link ComponentState#destroy()} re-throws {@link ComponentDestructionException} */
|
||||||
@Test
|
@Test
|
||||||
public void testDestroyActionExceptionPassthrough( )
|
public void testDestroyActionExceptionPassthrough( )
|
||||||
|
@ -1101,4 +1116,45 @@ public class TestComponentState
|
||||||
Assert.assertFalse( rt.started );
|
Assert.assertFalse( rt.started );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Test: {@link ComponentState#restart()} restarts drivers */
|
||||||
|
@Test
|
||||||
|
public void testRestartDrivers( )
|
||||||
|
{
|
||||||
|
final ComponentState cs1 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true );
|
||||||
|
final ComponentState cs2 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true );
|
||||||
|
cs2.setDriverFor( cs1 );
|
||||||
|
|
||||||
|
this.reg.active = true;
|
||||||
|
cs1.restart( );
|
||||||
|
|
||||||
|
final RestartTest rt = (RestartTest) cs2.getComponent( );
|
||||||
|
Assert.assertTrue( rt.stopped );
|
||||||
|
Assert.assertTrue( rt.started );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/** Test: {@link ComponentState#restart()} stops drivers after normal reverse dependencies and restarts them first */
|
||||||
|
@Test
|
||||||
|
public void testRestartDriversOrder( )
|
||||||
|
{
|
||||||
|
final ComponentState cs1 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true );
|
||||||
|
final ComponentState cs2 = TestComponentState.makeState( RestartTest.getDef( ) , this.reg , true , true );
|
||||||
|
cs2.setDriverFor( cs1 );
|
||||||
|
|
||||||
|
final RestartTest rt = (RestartTest) cs2.getComponent( );
|
||||||
|
NewComponentInfo< Object > ci3 = new NewComponentInfo< Object >( new Object( ) ) //
|
||||||
|
.setLifecycleAction( LifecycleStage.STOP , ( o ) -> {
|
||||||
|
Assert.assertFalse( rt.stopped );
|
||||||
|
}) //
|
||||||
|
.setLifecycleAction( LifecycleStage.START , ( o ) -> {
|
||||||
|
Assert.assertTrue( rt.stopped );
|
||||||
|
Assert.assertTrue( rt.started );
|
||||||
|
}); //
|
||||||
|
final ComponentState cs3 = TestComponentState.makeState( ci3 , this.reg , true , true );
|
||||||
|
cs3.addDependency( cs1 );
|
||||||
|
|
||||||
|
this.reg.active = true;
|
||||||
|
cs1.restart( );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue