Esempio n. 1
0
 private void initXceStorm() {
   nodeUsers = new ConcurrentHashMap<Integer, Integer>();
   nodeUserListener = new XceStormNodeUserListenerImpl();
   try {
     XceStormAdapter.getInstance().subscribe(XceStormNodeUserListenerImpl.key, nodeUserListener);
   } catch (Exception e) {
     // TODO: Logger 一下
   }
 }
Esempio n. 2
0
  @Test
  public void test() {
    try {
      System.out.println("start testing ...");
      XceStormListenerExample listener = new XceStormListenerExample();
      int original = 0;
      ObserverPrx[] observers = XceStormAdapter.getInstance().query("Test").get("Test");
      if (observers != null) {
        original = observers.length;
      }
      XceStormAdapter.getInstance().subscribe("Test", listener);
      Thread.sleep(1000);
      Assert.assertEquals(
          original + 1, XceStormAdapter.getInstance().query("Test").get("Test").length);

      Map<String, String> properties = new HashMap<String, String>();
      Date now = new Date();
      properties.put("key", now.toString());
      XceStormAdapter.getInstance().notify("Test", properties);
      Thread.sleep(1000);
      listener.assertMessageSentAndReceived(now.toString());

      XceStormAdapter.getInstance().unsubscribe("Test", listener);
      Thread.sleep(1000);
      Assert.assertEquals(original, XceStormAdapter.getInstance().query("Test").get("Test").length);

      XceStormAdapter.getInstance().subscribe("Test", listener);
      Thread.sleep(1000);
      Assert.assertEquals(
          original + 1, XceStormAdapter.getInstance().query("Test").get("Test").length);
      XceStormAdapter.getInstance().destroy();
      XceStormAdapter.getInstance().notify("Test", properties);
      Thread.sleep(3 * 60 * 1000);
      Assert.assertEquals(original, XceStormAdapter.getInstance().query("Test").get("Test").length);
      // Thread.sleep(30 * 60 * 1000);
      // Assert.assertEquals(original, XceStormAdapter.getInstance()
      // .query("Test").get("Test").length);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }