@Override public void addInstance( ManagedApplication ma, Instance parentInstance, Instance instance ) throws ImpossibleInsertionException, IOException { // Insert it, if possible this.messagingMngr.checkMessagingConfiguration(); if( ! InstanceHelpers.tryToInsertChildInstance( ma.getApplication(), parentInstance, instance )) throw new ImpossibleInsertionException( instance.getName()); // Generate values for random variables, if any this.randomMngr.generateRandomValues( ma.getApplication(), instance ); // Send it to the agent this.logger.fine( "Instance " + InstanceHelpers.computeInstancePath( instance ) + " was successfully added in " + ma.getName() + "." ); Instance scopedInstance = InstanceHelpers.findScopedInstance( instance ); // Store the message because we want to make sure the message is not lost ma.storeAwaitingMessage( instance, new MsgCmdAddInstance( scopedInstance )); ConfigurationUtils.saveInstances( ma ); this.notificationMngr.instance( instance, ma.getApplication(), EventType.CREATED ); }
@Test public void testMessage_addInstance() throws Exception { Instance child = new Instance( "child" ).channel( "channel 4" ).status( InstanceStatus.DEPLOYED_STOPPED ); child.component( new Component( "comp_child" ).installerName( "whatever" )); MsgCmdAddInstance msg = new MsgCmdAddInstance( child ); checkBasics( msg, MsgCmdAddInstance.class ); Instance root = new Instance( "root" ).status( InstanceStatus.DEPLOYED_STARTED ).channel( "channel1" ).channel( "channel2" ); root.component( new Component( "comp_root" ).installerName( "whatever" )); InstanceHelpers.insertChild( root, child ); msg = new MsgCmdAddInstance( child ); checkBasics( msg, MsgCmdAddInstance.class ); msg = new MsgCmdAddInstance( new Instance( "instance without component" )); checkBasics( msg, MsgCmdAddInstance.class ); }
@Test public void testScenarios_publications() throws Exception { InMemoryClient client = new InMemoryClient( new InMemoryRoutingContext(), RecipientKind.DM ); RoboconfMessageQueue queue = new RoboconfMessageQueue(); client.setMessageQueue( queue ); MessagingContext ctx = new MessagingContext( RecipientKind.AGENTS, "domain", "app" ); // Not connected, publications cannot work Message msg = new MsgCmdAddInstance( new Instance( "" )); Assert.assertFalse( client.isConnected()); Assert.assertEquals( 0, queue.size()); client.publish( ctx, msg ); Assert.assertEquals( 0, queue.size()); // Connection client.openConnection(); Assert.assertTrue( client.isConnected()); client.publish( ctx, msg ); Assert.assertEquals( 0, queue.size()); // We need to subscribe to this context to dispatch the message. // The messaging tests verify routing more precisely. client.subscribe( ctx ); client.publish( ctx, msg ); Assert.assertEquals( 1, queue.size()); Assert.assertEquals( msg, queue.element()); }