MasterRegistrationManagerImplTest.java
Go to the documentation of this file.
00001 
00004 package org.ros.internal.node.server.master;
00005 
00006 import static org.junit.Assert.assertEquals;
00007 import static org.junit.Assert.assertFalse;
00008 import static org.junit.Assert.assertNull;
00009 import static org.junit.Assert.assertTrue;
00010 import static org.mockito.Mockito.mock;
00011 import static org.mockito.Mockito.verify;
00012 
00013 import com.google.common.collect.Sets;
00014 
00015 import org.junit.Before;
00016 import org.junit.Test;
00017 import org.mockito.Mockito;
00018 import org.ros.namespace.GraphName;
00019 import org.ros.node.topic.Subscriber;
00020 
00021 import java.net.URI;
00022 
00028 public class MasterRegistrationManagerImplTest {
00029 
00030   private MasterRegistrationManagerImpl masterRegistrationManager;
00031   private MasterRegistrationListener registrationListener;
00032 
00033   @Before
00034   public void setup() {
00035     registrationListener = mock(MasterRegistrationListener.class);
00036     masterRegistrationManager = new MasterRegistrationManagerImpl(registrationListener);
00037   }
00038 
00044   @Test
00045   public void testRegisterOnlyPublisher() throws Exception {
00046     GraphName nodeName = GraphName.of("/node");
00047     URI nodeSlaveUri = new URI("http://localhost:12345");
00048     GraphName topicName = GraphName.of("/topic");
00049     String topicMessageType = "topic/Message";
00050 
00051     TopicRegistrationInfo topic =
00052         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00053             topicMessageType);
00054 
00055     assertTrue(topic.getSubscribers().isEmpty());
00056 
00057     assertEquals(topicMessageType, topic.getMessageType());
00058 
00059     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00060     assertTrue(node.hasRegistrations());
00061     assertTrue(node.getSubscribers().isEmpty());
00062     assertEquals(Sets.newHashSet(topic), node.getPublishers());
00063 
00064     // Make sure only publisher in the topic is the topic we got for the node
00065     // name
00066     assertEquals(Sets.newHashSet(node), topic.getPublishers());
00067 
00068     // No attempt for node shutdown
00069     verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00070   }
00071 
00077   @Test
00078   public void testRegisterOnlySubscriber() throws Exception {
00079     GraphName nodeName = GraphName.of("/node");
00080     URI nodeSlaveUri = new URI("http://localhost:12345");
00081     GraphName topicName = GraphName.of("/topic");
00082     String topicMessageType = "topic/Message";
00083 
00084     TopicRegistrationInfo topic =
00085         masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00086             topicMessageType);
00087 
00088     assertTrue(topic.getPublishers().isEmpty());
00089 
00090     assertEquals(topicMessageType, topic.getMessageType());
00091 
00092     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00093     assertTrue(node.hasRegistrations());
00094     assertTrue(node.getPublishers().isEmpty());
00095     assertEquals(Sets.newHashSet(topic), node.getSubscribers());
00096 
00097     // Make sure only subscriber in the topic is the topic we got for the node
00098     // name
00099     assertEquals(Sets.newHashSet(node), topic.getSubscribers());
00100 
00101     // No attempt for node shutdown
00102     verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00103   }
00104 
00111   @Test
00112   public void testOnlySubscriberWildcard() throws Exception {
00113     GraphName nodeName = GraphName.of("/node");
00114     URI nodeSlaveUri = new URI("http://localhost:12345");
00115     GraphName topicName = GraphName.of("/topic");
00116 
00117     TopicRegistrationInfo topic =
00118         masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00119             Subscriber.TOPIC_MESSAGE_TYPE_WILDCARD);
00120 
00121     // The important result. All of the others are to make sure the wildcard
00122     // didn't
00123     // screw anything else up.
00124     assertNull(topic.getMessageType());
00125 
00126     assertTrue(topic.getPublishers().isEmpty());
00127 
00128     // Make sure subscriber was still registered.
00129     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00130     assertTrue(node.hasRegistrations());
00131     assertTrue(node.getPublishers().isEmpty());
00132     assertEquals(Sets.newHashSet(topic), node.getSubscribers());
00133 
00134     // No attempt for node shutdown
00135     verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00136   }
00137 
00145   @Test
00146   public void testSubscriberSubscriber() throws Exception {
00147     GraphName topicName = GraphName.of("/topic");
00148 
00149     GraphName nodeName1 = GraphName.of("/node1");
00150     URI nodeSlaveUri1 = new URI("http://localhost:12345");
00151     String topicMessageType1 = "topic/Message1";
00152 
00153     TopicRegistrationInfo topic1 =
00154         masterRegistrationManager.registerSubscriber(nodeName1, nodeSlaveUri1, topicName,
00155             topicMessageType1);
00156 
00157     GraphName nodeName2 = GraphName.of("/node2");
00158     URI nodeSlaveUri2 = new URI("http://localhost:54321");
00159     String topicMessageType2 = "topic/Message2";
00160 
00161     TopicRegistrationInfo topic2 =
00162         masterRegistrationManager.registerSubscriber(nodeName2, nodeSlaveUri2, topicName,
00163             topicMessageType2);
00164 
00165     // This is the important test. The message type should be the second
00166     // registration's type.
00167     assertEquals(topicMessageType2, topic2.getMessageType());
00168 
00169     // Two topic descriptions should be the same
00170     assertTrue(topic1 == topic2);
00171 
00172     // Check everything else to make sure stayed the same.
00173     assertTrue(topic1.getPublishers().isEmpty());
00174     NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName1);
00175     assertTrue(node1.hasRegistrations());
00176     assertTrue(node1.getPublishers().isEmpty());
00177     assertEquals(Sets.newHashSet(topic1), node1.getSubscribers());
00178 
00179     assertTrue(topic2.getPublishers().isEmpty());
00180     NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName2);
00181     assertTrue(node2.hasRegistrations());
00182     assertTrue(node2.getPublishers().isEmpty());
00183     assertEquals(Sets.newHashSet(topic1), node2.getSubscribers());
00184 
00185     // No attempt for node shutdown
00186     verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00187     verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00188   }
00189 
00197   @Test
00198   public void testSubscriberSubscriberWildcard() throws Exception {
00199     GraphName topicName = GraphName.of("/topic");
00200 
00201     GraphName nodeName1 = GraphName.of("/node1");
00202     URI nodeSlaveUri1 = new URI("http://localhost:12345");
00203     String topicMessageType1 = "msgs/Message";
00204 
00205     TopicRegistrationInfo topic1 =
00206         masterRegistrationManager.registerSubscriber(nodeName1, nodeSlaveUri1, topicName,
00207             topicMessageType1);
00208 
00209     GraphName nodeName2 = GraphName.of("/node2");
00210     URI nodeSlaveUri2 = new URI("http://localhost:54321");
00211 
00212     TopicRegistrationInfo topic2 =
00213         masterRegistrationManager.registerSubscriber(nodeName2, nodeSlaveUri2, topicName,
00214             Subscriber.TOPIC_MESSAGE_TYPE_WILDCARD);
00215 
00216     assertTrue(topic1.getPublishers().isEmpty());
00217 
00218     // Two topic information objects should be the same
00219     assertTrue(topic1 == topic2);
00220 
00221     assertEquals(topicMessageType1, topic1.getMessageType());
00222 
00223     // Make sure subscribers were still registered for both nodes.
00224     NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName1);
00225     assertTrue(node1.hasRegistrations());
00226     assertTrue(node1.getPublishers().isEmpty());
00227     assertEquals(Sets.newHashSet(topic1), node1.getSubscribers());
00228 
00229     NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName2);
00230     assertTrue(node2.hasRegistrations());
00231     assertTrue(node2.getPublishers().isEmpty());
00232     assertEquals(Sets.newHashSet(topic1), node2.getSubscribers());
00233 
00234     // No attempt for node shutdown
00235     verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00236     verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00237   }
00238 
00245   @Test
00246   public void testSubscriberPublisher() throws Exception {
00247     GraphName topicName = GraphName.of("/topic");
00248 
00249     GraphName nodeNameSubscriber = GraphName.of("/node1");
00250     URI nodeSlaveUriSubscriber = new URI("http://localhost:12345");
00251     String topicMessageTypeSubscriber = "msgs/Message1";
00252 
00253     TopicRegistrationInfo topicSubscriber =
00254         masterRegistrationManager.registerSubscriber(nodeNameSubscriber, nodeSlaveUriSubscriber,
00255             topicName, topicMessageTypeSubscriber);
00256 
00257     GraphName nodeNamePublisher = GraphName.of("/node2");
00258     URI nodeSlaveUriPublisher = new URI("http://localhost:54321");
00259     String topicMessageTypePublisher = "msgs/Message2";
00260 
00261     TopicRegistrationInfo topicPublisher =
00262         masterRegistrationManager.registerPublisher(nodeNamePublisher, nodeSlaveUriPublisher,
00263             topicName, topicMessageTypePublisher);
00264 
00265     // Should be only one topic info object since the same topic type
00266     assertTrue(topicSubscriber == topicPublisher);
00267 
00268     // Publisher will beat out subscriber message type
00269     assertEquals(topicMessageTypePublisher, topicSubscriber.getMessageType());
00270 
00271     // Make sure node info objects have everything
00272     NodeRegistrationInfo node1 =
00273         masterRegistrationManager.getNodeRegistrationInfo(nodeNameSubscriber);
00274     assertTrue(node1.hasRegistrations());
00275     assertTrue(node1.getPublishers().isEmpty());
00276     assertEquals(Sets.newHashSet(topicSubscriber), node1.getSubscribers());
00277 
00278     NodeRegistrationInfo node2 =
00279         masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher);
00280     assertTrue(node2.hasRegistrations());
00281     assertTrue(node2.getSubscribers().isEmpty());
00282     assertEquals(Sets.newHashSet(topicSubscriber), node2.getPublishers());
00283 
00284     // No attempt for node shutdown
00285     verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00286     verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00287   }
00288 
00295   @Test
00296   public void testPublisherSubscriber() throws Exception {
00297     GraphName topicName = GraphName.of("/topic");
00298 
00299     GraphName nodeNamePublisher = GraphName.of("/node2");
00300     URI nodeSlaveUriPublisher = new URI("http://localhost:54321");
00301     String topicMessageTypePublisher = "msgs/Message2";
00302 
00303     TopicRegistrationInfo topicPublisher =
00304         masterRegistrationManager.registerPublisher(nodeNamePublisher, nodeSlaveUriPublisher,
00305             topicName, topicMessageTypePublisher);
00306 
00307     GraphName nodeNameSubscriber = GraphName.of("/node1");
00308     URI nodeSlaveUriSubscriber = new URI("http://localhost:12345");
00309     String topicMessageTypeSubscriber = "msgs/Message1";
00310 
00311     TopicRegistrationInfo topicSubscriber =
00312         masterRegistrationManager.registerSubscriber(nodeNameSubscriber, nodeSlaveUriSubscriber,
00313             topicName, topicMessageTypeSubscriber);
00314 
00315     // Should be only one topic info object since the same topic type
00316     assertTrue(topicSubscriber == topicPublisher);
00317 
00318     // Publisher message type stayed
00319     assertEquals(topicMessageTypePublisher, topicSubscriber.getMessageType());
00320 
00321     // Make sure node info objects have everything
00322     NodeRegistrationInfo node1 =
00323         masterRegistrationManager.getNodeRegistrationInfo(nodeNameSubscriber);
00324     assertTrue(node1.hasRegistrations());
00325     assertTrue(node1.getPublishers().isEmpty());
00326     assertEquals(Sets.newHashSet(topicSubscriber), node1.getSubscribers());
00327 
00328     NodeRegistrationInfo node2 =
00329         masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher);
00330     assertTrue(node2.hasRegistrations());
00331     assertTrue(node2.getSubscribers().isEmpty());
00332     assertEquals(Sets.newHashSet(topicSubscriber), node2.getPublishers());
00333 
00334     // No attempt for node shutdown
00335     verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00336     verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00337   }
00338 
00345   @Test
00346   public void testPublisherPublisher() throws Exception {
00347     GraphName topicName = GraphName.of("/topic");
00348 
00349     GraphName nodeNamePublisher1 = GraphName.of("/node1");
00350     URI nodeSlaveUriPublisher1 = new URI("http://localhost:54321");
00351     String topicMessageTypePublisher1 = "msgs/Message1";
00352 
00353     TopicRegistrationInfo topicPublisher1 =
00354         masterRegistrationManager.registerPublisher(nodeNamePublisher1, nodeSlaveUriPublisher1,
00355             topicName, topicMessageTypePublisher1);
00356 
00357     GraphName nodeNamePublisher2 = GraphName.of("/node2");
00358     URI nodeSlaveUriPublisher2 = new URI("http://localhost:12345");
00359     String topicMessageTypePublisher2 = "msgs/Message2";
00360 
00361     TopicRegistrationInfo topicPublisher2 =
00362         masterRegistrationManager.registerPublisher(nodeNamePublisher2, nodeSlaveUriPublisher2,
00363             topicName, topicMessageTypePublisher2);
00364 
00365     // Should be only one topic info object since the same topic type
00366     assertTrue(topicPublisher2 == topicPublisher1);
00367 
00368     // Second message type better have won.
00369     assertEquals(topicMessageTypePublisher2, topicPublisher2.getMessageType());
00370 
00371     // Make sure node info objects have everything
00372     NodeRegistrationInfo node1 =
00373         masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher2);
00374     assertTrue(node1.hasRegistrations());
00375     assertTrue(node1.getSubscribers().isEmpty());
00376     assertEquals(Sets.newHashSet(topicPublisher2), node1.getPublishers());
00377 
00378     NodeRegistrationInfo node2 =
00379         masterRegistrationManager.getNodeRegistrationInfo(nodeNamePublisher1);
00380     assertTrue(node2.hasRegistrations());
00381     assertTrue(node2.getSubscribers().isEmpty());
00382     assertEquals(Sets.newHashSet(topicPublisher2), node2.getPublishers());
00383 
00384     // Both publishers in topic
00385     assertEquals(Sets.newHashSet(node1, node2), topicPublisher1.getPublishers());
00386 
00387     // No attempt for node shutdown
00388     verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00389     verify(registrationListener, Mockito.never()).onNodeReplacement(node2);
00390   }
00391 
00398   @Test
00399   public void testNodeNameRepeated() throws Exception {
00400     GraphName nodeName = GraphName.of("/node1");
00401 
00402     GraphName topicName1 = GraphName.of("/topic1");
00403     URI nodeSlaveUri1 = new URI("http://localhost:54321");
00404     String topicMessageType1 = "msgs/Message1";
00405 
00406     TopicRegistrationInfo topic1 =
00407         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri1, topicName1,
00408             topicMessageType1);
00409 
00410     NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00411 
00412     URI nodeSlaveUri2 = new URI("http://localhost:12345");
00413     GraphName topicName2 = GraphName.of("/topic2");
00414     String topicMessageType2 = "msgs/Message2";
00415 
00416     TopicRegistrationInfo topic2 =
00417         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri2, topicName2,
00418             topicMessageType2);
00419 
00420     NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00421 
00422     // Make sure node1 signaled a replacement
00423     verify(registrationListener, Mockito.times(1)).onNodeReplacement(node1);
00424 
00425     // Should be two topics.
00426     assertFalse(topic2 == topic1);
00427 
00428     // Definitely second registration's message type better be the current
00429     // message type.
00430     assertEquals(topicMessageType2, topic2.getMessageType());
00431 
00432     // TopicSystemState one should have no publishers at all
00433     assertTrue(topic1.getPublishers().isEmpty());
00434 
00435     // Node 2 is fully there.
00436     assertTrue(node2.hasRegistrations());
00437     assertTrue(node2.getSubscribers().isEmpty());
00438     assertEquals(Sets.newHashSet(topic2), node2.getPublishers());
00439   }
00440 
00446   @Test
00447   public void testSinglePublisherRemoved() throws Exception {
00448     GraphName nodeName = GraphName.of("/node1");
00449     GraphName topicName = GraphName.of("/topic1");
00450     URI nodeSlaveUri = new URI("http://localhost:54321");
00451     String topicMessageType = "msgs/Message1";
00452 
00453     TopicRegistrationInfo topic =
00454         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00455             topicMessageType);
00456 
00457     masterRegistrationManager.unregisterPublisher(nodeName, topicName);
00458 
00459     // TopicSystemState should have no publishers at all
00460     assertTrue(topic.getPublishers().isEmpty());
00461 
00462     // Node should have been deleted.
00463     assertNull(masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00464   }
00465 
00471   @Test
00472   public void testTwoPublishersOneRemoved() throws Exception {
00473     GraphName nodeName = GraphName.of("/node1");
00474     URI nodeSlaveUri = new URI("http://localhost:54321");
00475 
00476     GraphName topicName1 = GraphName.of("/topic1");
00477     String topicMessageType1 = "msgs/Message1";
00478 
00479     TopicRegistrationInfo topic1 =
00480         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName1,
00481             topicMessageType1);
00482 
00483     GraphName topicName2 = GraphName.of("/topic2");
00484     String topicMessageType2 = "msgs/Message2";
00485 
00486     TopicRegistrationInfo topic2 =
00487         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName2,
00488             topicMessageType2);
00489 
00490     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00491 
00492     // Delete the first
00493     masterRegistrationManager.unregisterPublisher(nodeName, topicName1);
00494 
00495     // TopicSystemState 1 should have no publishers at all. TopicSystemState 2 will have 1 publisher,
00496     // and the node will show this published topic.
00497     assertTrue(topic1.getPublishers().isEmpty());
00498     assertEquals(Sets.newHashSet(topic2), node.getPublishers());
00499     assertEquals(Sets.newHashSet(node), topic2.getPublishers());
00500   }
00501 
00507   @Test
00508   public void testSingleSubscriberRemoved() throws Exception {
00509     GraphName nodeName = GraphName.of("/node1");
00510     GraphName topicName = GraphName.of("/topic1");
00511     URI nodeSlaveUri = new URI("http://localhost:54321");
00512     String topicMessageType = "msgs/Message1";
00513 
00514     TopicRegistrationInfo topic =
00515         masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00516             topicMessageType);
00517 
00518     masterRegistrationManager.unregisterSubscriber(nodeName, topicName);
00519 
00520     // TopicSystemState one should have no subscribers at all
00521     assertTrue(topic.getSubscribers().isEmpty());
00522 
00523     // Node should have been deleted.
00524     assertNull(masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00525   }
00526 
00532   @Test
00533   public void testTwoSubscribersOneRemoved() throws Exception {
00534     GraphName nodeName = GraphName.of("/node1");
00535     URI nodeSlaveUri = new URI("http://localhost:54321");
00536 
00537     GraphName topicName1 = GraphName.of("/topic1");
00538     String topicMessageType1 = "msgs/Message1";
00539 
00540     TopicRegistrationInfo topic1 =
00541         masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName1,
00542             topicMessageType1);
00543 
00544     GraphName topicName2 = GraphName.of("/topic2");
00545     String topicMessageType2 = "msgs/Message2";
00546 
00547     TopicRegistrationInfo topic2 =
00548         masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName2,
00549             topicMessageType2);
00550 
00551     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00552 
00553     // Delete the first
00554     masterRegistrationManager.unregisterSubscriber(nodeName, topicName1);
00555 
00556     // TopicSystemState 1 should have no subscribers at all. TopicSystemState 2 will have 1
00557     // subscriber,
00558     // and the node will show this subscribed topic.
00559     assertTrue(topic1.getSubscribers().isEmpty());
00560     assertEquals(Sets.newHashSet(topic2), node.getSubscribers());
00561     assertEquals(Sets.newHashSet(node), topic2.getSubscribers());
00562   }
00563 
00569   @Test
00570   public void testSubscriberTwice() throws Exception {
00571     GraphName topicName = GraphName.of("/topic");
00572 
00573     GraphName nodeName = GraphName.of("/node");
00574     URI nodeSlaveUri = new URI("http://localhost:12345");
00575     String topicMessageType = "topic/Message";
00576 
00577     TopicRegistrationInfo topic1 =
00578         masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00579             topicMessageType);
00580     NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00581 
00582     TopicRegistrationInfo topic2 =
00583         masterRegistrationManager.registerSubscriber(nodeName, nodeSlaveUri, topicName,
00584             topicMessageType);
00585     NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00586 
00587     // This is the important test. Nothing should have changed.
00588     assertTrue(topic1 == topic2);
00589     assertTrue(node1 == node2);
00590 
00591     // Check everything else to make sure stayed the same.
00592     assertTrue(topic1.getPublishers().isEmpty());
00593     assertTrue(node1.hasRegistrations());
00594     assertTrue(node1.getPublishers().isEmpty());
00595     assertEquals(Sets.newHashSet(topic1), node1.getSubscribers());
00596 
00597     // No attempt for node shutdown
00598     verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00599   }
00600 
00606   @Test
00607   public void testPublisherTwice() throws Exception {
00608     GraphName topicName = GraphName.of("/topic");
00609 
00610     GraphName nodeName = GraphName.of("/node");
00611     URI nodeSlaveUri = new URI("http://localhost:12345");
00612     String topicMessageType = "topic/Message";
00613 
00614     TopicRegistrationInfo topic1 =
00615         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00616             topicMessageType);
00617     NodeRegistrationInfo node1 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00618 
00619     TopicRegistrationInfo topic2 =
00620         masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri, topicName,
00621             topicMessageType);
00622     NodeRegistrationInfo node2 = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00623 
00624     // This is the important test. Nothing should have changed, the exact
00625     // objects should come back.
00626     assertTrue(topic1 == topic2);
00627     assertTrue(node1 == node2);
00628 
00629     // Check everything else to make sure stayed the same.
00630     assertTrue(topic1.getSubscribers().isEmpty());
00631     assertTrue(node1.hasRegistrations());
00632     assertTrue(node1.getSubscribers().isEmpty());
00633     assertEquals(Sets.newHashSet(topic1), node1.getPublishers());
00634 
00635     // No attempt for node shutdown
00636     verify(registrationListener, Mockito.never()).onNodeReplacement(node1);
00637   }
00638 
00644   @Test
00645   public void testRegisterOnlyService() throws Exception {
00646     GraphName nodeName = GraphName.of("/node");
00647     URI nodeSlaveUri = new URI("http://localhost:12345");
00648     GraphName serviceName = GraphName.of("/service");
00649     URI serviceUri = new URI("http://foo");
00650 
00651     ServiceRegistrationInfo service =
00652         masterRegistrationManager.registerService(nodeName, nodeSlaveUri, serviceName, serviceUri);
00653 
00654     assertEquals(serviceName, service.getServiceName());
00655 
00656     assertEquals(serviceUri, service.getServiceUri());
00657 
00658     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00659     assertTrue(node.hasRegistrations());
00660     assertEquals(Sets.newHashSet(service), node.getServices());
00661 
00662     // Make sure only publisher in the topic is the topic we got for the node
00663     // name
00664     assertEquals(node, service.getNode());
00665 
00666     // No attempt for node shutdown
00667     verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00668   }
00669 
00675   @Test
00676   public void testRegisterUnregisterService() throws Exception {
00677     GraphName nodeName = GraphName.of("/node");
00678     URI nodeSlaveUri = new URI("http://localhost:12345");
00679     GraphName serviceName = GraphName.of("/service");
00680     URI serviceUri = new URI("http://foo");
00681 
00682     masterRegistrationManager.registerService(nodeName, nodeSlaveUri, serviceName, serviceUri);
00683 
00684     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00685 
00686     masterRegistrationManager.unregisterService(nodeName, serviceName, serviceUri);
00687 
00688     assertNull(masterRegistrationManager.getServiceRegistrationInfo(serviceName));
00689     assertNull(masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00690 
00691     // No attempt for node shutdown
00692     verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00693   }
00694 
00701   @Test
00702   public void testRegisterUnregisterServiceWithPublisher() throws Exception {
00703     GraphName nodeName = GraphName.of("/node");
00704     URI nodeSlaveUri = new URI("http://localhost:12345");
00705     GraphName serviceName = GraphName.of("/service");
00706     URI serviceUri = new URI("http://foo");
00707     GraphName topicName = GraphName.of("/topic");
00708     String topicMessageType = "foo/Bar";
00709 
00710     masterRegistrationManager.registerService(nodeName, nodeSlaveUri, serviceName, serviceUri);
00711     masterRegistrationManager
00712         .registerPublisher(nodeName, nodeSlaveUri, topicName, topicMessageType);
00713 
00714     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00715 
00716     masterRegistrationManager.unregisterService(nodeName, serviceName, serviceUri);
00717 
00718     assertNull(masterRegistrationManager.getServiceRegistrationInfo(serviceName));
00719     assertEquals(node, masterRegistrationManager.getNodeRegistrationInfo(nodeName));
00720     assertTrue(node.getServices().isEmpty());
00721 
00722     // No attempt for node shutdown
00723     verify(registrationListener, Mockito.never()).onNodeReplacement(node);
00724   }
00725 
00732   @Test
00733   public void testRegisterServiceReplaceNode() throws Exception {
00734     GraphName nodeName = GraphName.of("/node");
00735     URI nodeSlaveUri1 = new URI("http://localhost:12345");
00736     GraphName serviceName = GraphName.of("/service");
00737     URI serviceUri = new URI("http://foo");
00738     GraphName topicName = GraphName.of("/topic");
00739     String topicMessageType = "foo/Bar";
00740 
00741     URI nodeSlaveUri2 = new URI("http://localhost:54321");
00742 
00743     masterRegistrationManager.registerService(nodeName, nodeSlaveUri1, serviceName, serviceUri);
00744     masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri1, topicName,
00745         topicMessageType);
00746 
00747     NodeRegistrationInfo node = masterRegistrationManager.getNodeRegistrationInfo(nodeName);
00748 
00749     masterRegistrationManager.registerPublisher(nodeName, nodeSlaveUri2, topicName,
00750         topicMessageType);
00751 
00752     assertNull(masterRegistrationManager.getServiceRegistrationInfo(serviceName));
00753     assertTrue(masterRegistrationManager.getNodeRegistrationInfo(nodeName).getServices().isEmpty());
00754 
00755     // No attempt for node shutdown
00756     verify(registrationListener).onNodeReplacement(node);
00757   }
00758 }


rosjava_core
Author(s):
autogenerated on Wed Aug 26 2015 16:06:49