WaitingForAncestor extends AbstractLifeCycleManager { @Override public void changeInstanceState( Instance instance, PluginInterface plugin, InstanceStatus newStatus, Map<String,byte[]> fileNameToFileContent ) throws IOException, PluginException { if( newStatus == InstanceStatus.NOT_DEPLOYED ) undeploy( instance, plugin ); else if( newStatus == InstanceStatus.DEPLOYED_STARTED ) start( instance, plugin ); else if( newStatus == InstanceStatus.DEPLOYED_STOPPED ) { instance.setStatus( InstanceStatus.DEPLOYED_STOPPED ); List<Instance> childrenInstances = InstanceHelpers.buildHierarchicalList( instance ); childrenInstances.remove( instance ); for( Instance childInstance : childrenInstances ) { if( childInstance.getStatus() == InstanceStatus.WAITING_FOR_ANCESTOR ) childInstance.setStatus( InstanceStatus.DEPLOYED_STOPPED ); } } } WaitingForAncestor( String appName, IAgentClient messagingClient ); @Override void changeInstanceState(
			Instance instance,
			PluginInterface plugin,
			InstanceStatus newStatus,
			Map<String,byte[]> fileNameToFileContent );  }
@Test public void testUnstableState() throws Exception { IAgentClient messagingClient = Mockito.mock( IAgentClient.class ); WaitingForAncestor wfa = new WaitingForAncestor( "app", messagingClient ); Instance inst = Mockito.mock( Instance.class ); wfa.changeInstanceState( inst, null, InstanceStatus.DEPLOYING, null ); Mockito.verifyZeroInteractions( messagingClient ); Mockito.verifyZeroInteractions( inst ); }
@Test public void test_stopIsPropagatedToChildren_notDeployed() throws Exception { IAgentClient messagingClient = Mockito.mock( IAgentClient.class ); WaitingForAncestor wfa = new WaitingForAncestor( "app", messagingClient ); TestApplication app = new TestApplication(); app.getTomcatVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); app.getTomcat().setStatus( InstanceStatus.WAITING_FOR_ANCESTOR ); wfa.changeInstanceState( app.getTomcat(), null, InstanceStatus.DEPLOYED_STOPPED, null ); Mockito.verifyZeroInteractions( messagingClient ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, app.getTomcatVm().getStatus()); Assert.assertEquals( InstanceStatus.DEPLOYED_STOPPED, app.getTomcat().getStatus()); Assert.assertEquals( InstanceStatus.NOT_DEPLOYED, app.getWar().getStatus()); }
@Test public void test_stopIsPropagatedToChildren_stopped() throws Exception { IAgentClient messagingClient = Mockito.mock( IAgentClient.class ); WaitingForAncestor wfa = new WaitingForAncestor( "app", messagingClient ); TestApplication app = new TestApplication(); app.getTomcatVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); app.getTomcat().setStatus( InstanceStatus.WAITING_FOR_ANCESTOR ); app.getWar().setStatus( InstanceStatus.DEPLOYED_STOPPED ); wfa.changeInstanceState( app.getTomcat(), null, InstanceStatus.DEPLOYED_STOPPED, null ); Mockito.verifyZeroInteractions( messagingClient ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, app.getTomcatVm().getStatus()); Assert.assertEquals( InstanceStatus.DEPLOYED_STOPPED, app.getTomcat().getStatus()); Assert.assertEquals( InstanceStatus.DEPLOYED_STOPPED, app.getWar().getStatus()); }
@Test public void test_stopIsPropagatedToChildren_waitingForAncestor() throws Exception { IAgentClient messagingClient = Mockito.mock( IAgentClient.class ); WaitingForAncestor wfa = new WaitingForAncestor( "app", messagingClient ); TestApplication app = new TestApplication(); app.getTomcatVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); app.getTomcat().setStatus( InstanceStatus.WAITING_FOR_ANCESTOR ); app.getWar().setStatus( InstanceStatus.WAITING_FOR_ANCESTOR ); wfa.changeInstanceState( app.getTomcat(), null, InstanceStatus.DEPLOYED_STOPPED, null ); Mockito.verifyZeroInteractions( messagingClient ); Assert.assertEquals( InstanceStatus.DEPLOYED_STARTED, app.getTomcatVm().getStatus()); Assert.assertEquals( InstanceStatus.DEPLOYED_STOPPED, app.getTomcat().getStatus()); Assert.assertEquals( InstanceStatus.DEPLOYED_STOPPED, app.getWar().getStatus()); }