コード例 #1
0
 @Test
 public void testGetRuntime() throws Exception {
   ServiceRegistryService service = new ServiceRegistryService();
   RegisteredRuntime rr1 =
       service.register(new ServiceFullName("a", "b", "1"), 100, new HashMap<>());
   RegisteredRuntime rr2 =
       service.register(new ServiceFullName("a", "b", "2"), 101, new HashMap<>());
   RegisteredRuntime rr3 =
       service.register(new ServiceFullName("a", "b", "1"), 103, new HashMap<>());
   assertEquals(rr1, service.getRuntime(rr1.getInstanceSecCode()));
   assertEquals(rr2, service.getRuntime(rr2.getInstanceSecCode()));
   assertEquals(rr3, service.getRuntime(rr3.getInstanceSecCode()));
   assertNull(service.getRuntime("foo"));
 }
コード例 #2
0
 @Test
 public void testStore() throws Exception {
   ServiceRegistryService service = ServiceRegistryServiceTest.getService();
   ServiceRegistryPersistence persistence =
       new ServiceRegistryPersistence(new File(dir, "strg.json"), 1, service, true);
   service.addRegistrationListener(persistence);
   Map<String, Integer> apps = new HashMap<>();
   apps.put("one", 200);
   apps.put("two", 201);
   RegisteredRuntime rr1 = service.register(new ServiceFullName("a", "b", "1"), 100, apps);
   apps.put("one", 202);
   apps.put("two", 203);
   apps.put("three", 203);
   RegisteredRuntime rr2 = service.register(new ServiceFullName("a", "b", "2"), 101, apps);
   apps.clear();
   apps.put("foo", 204);
   apps.put("bar", 205);
   RegisteredRuntime rr3 = service.register(new ServiceFullName("a", "b", "1"), 102, apps);
   persistence.store();
   Collection<Cluster> clusters = persistence.loadClusters();
   assertNotNull(clusters);
   assertEquals(2, clusters.size());
   // Find cluster
   Cluster cl = null;
   for (Cluster cluster : clusters) {
     if ((new ServiceFullName("a", "b", "1")).equals(cluster.getFullName())) {
       cl = cluster;
       break;
     }
   }
   assertNotNull(cl);
   assertNotNull(cl.getRuntimes());
   assertEquals(2, cl.getRuntimes().size());
   // Find runtime
   RegisteredRuntime rr = null;
   for (RegisteredRuntime registeredRuntime : cl.getRuntimes()) {
     if (registeredRuntime.getInstanceId() == rr1.getInstanceId()) {
       rr = registeredRuntime;
       break;
     }
   }
   assertNotNull(rr);
   assertEquals(2, rr.getApplicationPorts().size());
   assertEquals(new Integer(201), rr.getApplicationPorts().get("two"));
 }