示例#1
0
 private void checkReentrancy(ProxyBusObject proxy) {
   try {
     /* does the proxy implement InterfaceB? */
     InterfaceB intf = proxy.getInterface(InterfaceB.class);
     try {
       String id = intf.methodB();
       assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id);
     } catch (BusException e) {
       // OK we might get ER_BUS_BLOCKING_CALL_NOT_ALLOWED here
       if (!e.getMessage().equals("ER_BUS_BLOCKING_CALL_NOT_ALLOWED")) {
         e.printStackTrace();
         fail("recieved an unexpected BusException.");
       }
     }
     bus.enableConcurrentCallbacks();
     try {
       String id = intf.methodB();
       assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id);
     } catch (BusException e) {
       fail("method invocation failed: " + e);
     }
   } catch (ClassCastException cce) {
     /* no it doesn't -> then it must implement InterfaceA, right? */
     InterfaceA intf = proxy.getInterface(InterfaceA.class);
     try {
       String id = intf.methodA();
       assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id);
     } catch (BusException e) {
       // OK we might get ER_BUS_BLOCKING_CALL_NOT_ALLOWED here
       if (!e.getMessage().equals("ER_BUS_BLOCKING_CALL_NOT_ALLOWED")) {
         e.printStackTrace();
         fail("recieved an unexpected BusException.");
       }
     }
     bus.enableConcurrentCallbacks();
     try {
       String id = intf.methodA();
       assertEquals(proxy.getBusName() + "@" + proxy.getObjPath(), id);
     } catch (BusException e) {
       fail("method invocation failed: " + e);
     }
   }
 }
示例#2
0
  public void testClose() throws Exception {
    Participant provider = new Participant("prov");
    Participant consumer = new Participant("cons");
    final Observer obs = newObserver(consumer, InterfaceA.class);
    final ObserverListener listener = new ObserverListener(consumer);
    obs.registerListener(listener);
    provider.createA(A);
    waitForEvent(listener, provider, A);

    ProxyBusObject pbo = obs.getFirst();
    assertNotNull(pbo);

    obs.close();
    obs.close();
    obs.registerListener(listener);
    assertNull(obs.getFirst());
    assertNull(obs.get(pbo.getBusName(), pbo.getObjPath()));
    assertNull(obs.getNext(pbo));
    obs.unregisterListener(listener);
    obs.unregisterAllListeners();
    obs.close();
    Thread.sleep(100);
    listener.expectInvocations(0);
  }
示例#3
0
 private void unregisterObject(
     Participant provider, ProxyBusObject obj, ObserverListener listener) {
   waitForEvent(listener, provider, obj.getObjPath().substring(TEST_PATH_PREFIX.length()), false);
 }
示例#4
0
  public void simpleScenario(Participant provider, Participant consumer) {
    provider.createA("justA");
    provider.createB("justB");
    provider.createAB("both");

    final Observer obsA = newObserver(consumer, InterfaceA.class);
    final ObserverListener listenerA = new ObserverListener(consumer);
    obsA.registerListener(listenerA);
    final Observer obsB = newObserver(consumer, InterfaceB.class);
    final ObserverListener listenerB = new ObserverListener(consumer);
    obsB.registerListener(listenerB);
    final Observer obsAB = newObserver(consumer, InterfaceA.class, InterfaceB.class);
    final ObserverListener listenerAB = new ObserverListener(consumer);
    obsAB.registerListener(listenerAB);

    Lambda allDone =
        new Lambda() {
          @Override
          public boolean func() {
            return listenerA.getCounter() == 0
                && listenerB.getCounter() == 0
                && listenerAB.getCounter() == 0;
          }
        };
    /* let provider publish objects on the bus */
    listenerA.expectInvocations(2);
    listenerB.expectInvocations(2);
    listenerAB.expectInvocations(1);

    provider.registerObject("justA");
    provider.registerObject("justB");
    provider.registerObject("both");
    assertTrue(waitForLambda(3000, allDone));

    /* remove justA from the bus */
    listenerA.expectInvocations(1);
    listenerB.expectInvocations(0);
    listenerAB.expectInvocations(0);

    provider.unregisterObject("justA");
    assertTrue(waitForLambda(3000, allDone));

    /* remove "both" from the bus */
    listenerA.expectInvocations(1);
    listenerB.expectInvocations(1);
    listenerAB.expectInvocations(1);

    provider.unregisterObject("both");
    assertTrue(waitForLambda(3000, allDone));

    /* count the number of proxies left in the Observers.
     * There should be 0 in A, 1 in B, 0 in AB */
    assertEquals(0, countProxies(obsA));
    assertEquals(1, countProxies(obsB));
    assertEquals(0, countProxies(obsAB));

    /* remove all listeners */
    obsA.unregisterAllListeners();
    obsB.unregisterAllListeners();
    obsAB.unregisterListener(listenerAB);

    /* remove "justB" and reinstate the other objects */
    listenerA.expectInvocations(0);
    listenerB.expectInvocations(0);
    listenerAB.expectInvocations(0);
    provider.unregisterObject("justB");
    provider.registerObject("justA");
    provider.registerObject("both");

    /* busy-wait for a second at most */
    assertTrue(
        waitForLambda(
            1000,
            new Lambda() {
              @Override
              public boolean func() {
                return 2 == countProxies(obsA)
                    && 1 == countProxies(obsB)
                    && 1 == countProxies(obsAB);
              }
            }));

    /* reinstate listeners & test triggerOnExisting functionality */
    listenerA.expectInvocations(2);
    listenerB.expectInvocations(1);
    listenerAB.expectInvocations(1);
    obsA.registerListener(listenerA);
    obsB.registerListener(listenerB);
    obsAB.registerListener(listenerAB);

    assertTrue(waitForLambda(3000, allDone));

    /* test multiple listeners for same observer */
    final ObserverListener listenerB2 = new ObserverListener(consumer);
    listenerB2.expectInvocations(0);
    obsB.registerListener(listenerB2, false);

    Lambda allDone2 =
        new Lambda() {
          @Override
          public boolean func() {
            return listenerA.getCounter() == 0
                && listenerB.getCounter() == 0
                && listenerB2.getCounter() == 0
                && listenerAB.getCounter() == 0;
          }
        };

    listenerA.expectInvocations(0);
    listenerB.expectInvocations(1);
    listenerB2.expectInvocations(1);
    listenerAB.expectInvocations(0);
    provider.registerObject("justB");
    assertTrue(waitForLambda(1000, allDone2));

    /* are all objects back where they belong? */
    assertEquals(2, countProxies(obsA));
    assertEquals(2, countProxies(obsB));
    assertEquals(1, countProxies(obsAB));

    /* test multiple observers for the same set of interfaces */
    final Observer obsB2 = newObserver(consumer, InterfaceB.class);
    obsB.unregisterListener(
        listenerB2); /* unregister listenerB2 from obsB so we can reuse it here */
    listenerA.expectInvocations(0);
    listenerB.expectInvocations(0);
    listenerB2.expectInvocations(2);
    listenerAB.expectInvocations(0);
    obsB2.registerListener(listenerB2);
    assertTrue(waitForLambda(1000, allDone2));

    /* test Observer::Get() and the proxy creation functionality */
    ProxyBusObject proxy;
    proxy = obsA.get(provider.bus.getUniqueName(), makePath("justA"));
    assertTrue(null != proxy);

    proxy = obsA.get(provider.bus.getUniqueName(), makePath("both"));
    assertTrue(null != proxy);

    /* verify that we can indeed perform method calls */
    InterfaceA intfA = proxy.getInterface(InterfaceA.class);
    try {
      String id = intfA.methodA();
      assertEquals(provider.bus.getUniqueName() + "@" + makePath("both"), id);
    } catch (BusException e) {
      fail("method call failed: " + e);
    }
  }
示例#5
0
 private void checkGet(ProxyBusObject obj, Observer obs) {
   assertSame(obj, obs.get(obj.getBusName(), obj.getObjPath()));
 }