Example #1
0
  private void exerciseMonitors() throws IOException, HubTestException, InterruptedException {
    PlasticMonitor mon1 = new PlasticMonitor("mon1", true, null, null);
    PlasticMonitor mon2 = new PlasticMonitor("mon2", false, null, null);
    ApplicationItem[] regApps = PlasticUtils.getRegisteredApplications(hub_);
    ApplicationListModel appList1 = new ApplicationListModel(regApps);
    ApplicationListModel appList2 = new ApplicationListModel(regApps);
    mon1.setListModel(appList1);
    mon2.setListModel(appList2);
    mon1.setHub(hub_);
    mon2.setHub(hub_);
    PlasticConnection conn1 = PlasticUtils.registerRMI(mon1);
    URI id1 = conn1.getId();
    assertTrue(hub_.getRegisteredIds().contains(id1));
    PlasticConnection conn2 = PlasticUtils.registerXMLRPC(mon2);
    URI id2 = conn2.getId();
    assertTrue(hub_.getRegisteredIds().contains(id2));

    Thread.sleep(2000);

    assertTrue(hub_.getRegisteredIds().contains(id1));
    assertTrue(hub_.getRegisteredIds().contains(id2));
    conn1.unregister();
    assertTrue(!hub_.getRegisteredIds().contains(id1));
    conn2.unregister();
    assertTrue(!hub_.getRegisteredIds().contains(id2));
  }
Example #2
0
  /** Runs tests using Counter client applications. */
  private void exerciseCounters() throws HubTestException, IOException, InterruptedException {
    Counter c1 = new Counter();
    Counter c2 = new Counter();
    PlasticConnection conn1 = PlasticUtils.registerRMI(c1);
    URI id1 = conn1.getId();

    assertTrue(hub_.getMessageRegisteredIds(CALC_MSG) != null);
    assertEquals(
        removeMonitorsList(hub_.getMessageRegisteredIds(CALC_MSG)), Collections.singletonList(id1));
    assertEquals(1, removeMonitorsList(hub_.getMessageRegisteredIds(CALC_MSG)).size());
    Object soleId = removeMonitorsList(hub_.getMessageRegisteredIds(CALC_MSG)).get(0);
    assertEquals(id1, soleId);

    assertEquals(
        intMap(new URI[] {id1}, new int[] {0}),
        removeMonitorsMap(hub_.request(id_, CALC_MSG, calcArgs(PLUS, 0))));

    PlasticConnection conn2 = PlasticUtils.registerXMLRPC(c2);
    URI id2 = conn2.getId();
    assertEquals(
        new HashSet(Arrays.asList(new URI[] {id1, id2})),
        new HashSet(removeMonitorsList(hub_.getMessageRegisteredIds(CALC_MSG))));
    assertEquals(
        intMap(new URI[] {id1, id2}, new int[] {10, 10}),
        removeMonitorsMap(hub_.request(id_, CALC_MSG, calcArgs(PLUS, 10))));
    assertEquals(
        intMap(new URI[] {id1, id2}, new int[] {5, 5}),
        removeMonitorsMap(hub_.request(id_, CALC_MSG, calcArgs(MINUS, 5))));
    assertEquals(5, c1.sum_);
    assertEquals(5, c2.sum_);

    assertEquals(
        intMap(new URI[] {id1}, new int[] {95}),
        hub_.requestToSubset(id_, CALC_MSG, calcArgs(PLUS, 90), Arrays.asList(new URI[] {id1})));
    assertEquals(95, c1.sum_);
    assertEquals(5, c2.sum_);

    assertEquals(
        intMap(new URI[] {id2}, new int[] {85}),
        hub_.requestToSubset(id_, CALC_MSG, calcArgs(PLUS, 80), Arrays.asList(new URI[] {id2})));
    assertEquals(95, c1.sum_);
    assertEquals(85, c2.sum_);

    synchronized (lock_) {
      int n1 = c1.nreq_;
      int n2 = c2.nreq_;
      PlasticUtils.singleRequestAsynch("poke", CALC_MSG, calcArgs(MINUS, 5));
      while (c1.nreq_ == n1 || c2.nreq_ == n2) {
        lock_.wait();
      }
    }
    assertEquals(90, c1.sum_);
    assertEquals(80, c2.sum_);

    synchronized (lock_) {
      int n1 = c1.nreq_;
      hub_.requestToSubsetAsynch(
          id_, CALC_MSG, calcArgs(MINUS, 10), Arrays.asList(new URI[] {id1}));
      while (c1.nreq_ == n1) {
        lock_.wait();
      }
    }
    assertEquals(80, c1.sum_);
    assertEquals(80, c2.sum_);

    synchronized (lock_) {
      int n1 = c1.nreq_;
      int n2 = c2.nreq_;
      hub_.requestAsynch(id_, CALC_MSG, calcArgs(PLUS, 21));
      while (c1.nreq_ == n1 || c2.nreq_ == n2) {
        lock_.wait();
      }
    }
    assertEquals(101, c1.sum_);
    assertEquals(101, c2.sum_);

    assertEquals(
        objMap(new URI[] {id1}, new String[] {"counter"}),
        hub_.requestToSubset(
            id_,
            PlasticUtils.createURI("ivo://votech.org/info/getName"),
            new ArrayList(),
            Arrays.asList(new URI[] {id1})));

    assertTrue(hub_.getRegisteredIds().contains(id1));
    assertTrue(hub_.getMessageRegisteredIds(CALC_MSG).contains(id1));
    assertTrue(!hub_.getMessageRegisteredIds(DUMMY_MSG).contains(id1));
    conn1.unregister();
    assertTrue(!hub_.getRegisteredIds().contains(id1));
    assertTrue(!hub_.getMessageRegisteredIds(CALC_MSG).contains(id1));

    assertTrue(hub_.getRegisteredIds().contains(id2));
    assertTrue(hub_.getMessageRegisteredIds(CALC_MSG).contains(id2));
    conn2.unregister();
    assertTrue(!hub_.getRegisteredIds().contains(id2));
    assertTrue(!hub_.getMessageRegisteredIds(CALC_MSG).contains(id2));

    c1.dispose();
    c2.dispose();
  }