InMemoryClient extends AbstractRoutingClient<LinkedBlockingQueue<Message>> { @Override public void setMessageQueue( RoboconfMessageQueue messageQueue ) { this.ctxToQueue.put( this.ownerId, messageQueue ); } InMemoryClient( InMemoryRoutingContext routingContext, RecipientKind ownerKind ); @Override void setMessageQueue( RoboconfMessageQueue messageQueue ); @Override String getMessagingType();  }
@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" ); Message msg = new MsgCmdAddInstance( new Instance( "" )); Assert.assertFalse( client.isConnected()); Assert.assertEquals( 0, queue.size()); client.publish( ctx, msg ); Assert.assertEquals( 0, queue.size()); client.openConnection(); Assert.assertTrue( client.isConnected()); client.publish( ctx, msg ); Assert.assertEquals( 0, queue.size()); client.subscribe( ctx ); client.publish( ctx, msg ); Assert.assertEquals( 1, queue.size()); Assert.assertEquals( msg, queue.element()); }
@Test public void testSetOwnerProperties_propertiesAreMoved() throws Exception { InMemoryClient client = new InMemoryClient( new InMemoryRoutingContext(), RecipientKind.DM ); RoboconfMessageQueue queue = new RoboconfMessageQueue(); client.setMessageQueue( queue ); client.openConnection(); MessagingContext ctx = new MessagingContext( RecipientKind.AGENTS, "domain", "app" ); client.subscribe( ctx ); String ownerId_1 = client.getOwnerId(); Map<String,Set<MessagingContext>> sub = client.getRoutingContext().subscriptions; Map<String,LinkedBlockingQueue<Message>> ctxToQueue = ((InMemoryRoutingContext) client.getRoutingContext()).ctxToQueue; Assert.assertEquals( queue, ctxToQueue.get( ownerId_1 )); Set<MessagingContext> subscribedContexts = sub.get( ownerId_1 ); Assert.assertNotNull( subscribedContexts ); Assert.assertEquals( 1, subscribedContexts.size()); Assert.assertTrue( subscribedContexts.contains( ctx )); client.setOwnerProperties( RecipientKind.AGENTS, "domain", "app1", "root1" ); String ownerId_2 = client.getOwnerId(); Assert.assertFalse( ownerId_2.equals( ownerId_1 )); Assert.assertEquals( queue, ctxToQueue.get( ownerId_2 )); Assert.assertNull( ctxToQueue.get( ownerId_1 )); Assert.assertNull( sub.get( ownerId_1 )); subscribedContexts = sub.get( ownerId_2 ); Assert.assertNotNull( subscribedContexts ); Assert.assertEquals( 1, subscribedContexts.size()); Assert.assertTrue( subscribedContexts.contains( ctx )); }