private void sendEvent(long startOffset, long timeout, boolean expect) throws Exception {
    structuredEvent_.header.variable_header = new Property[2];

    Date _time = new Date(System.currentTimeMillis() + startOffset);

    Any _startTimeAny = getClientORB().create_any();

    UtcTHelper.insert(_startTimeAny, Time.corbaTime(_time));

    structuredEvent_.header.variable_header[0] = new Property(StartTime.value, _startTimeAny);

    Any _timeoutAny = getClientORB().create_any();
    TimeTHelper.insert(_timeoutAny, timeout);

    structuredEvent_.header.variable_header[1] = new Property(Timeout.value, _timeoutAny);

    StructuredPushSender _sender = new StructuredPushSender(getClientORB());

    _sender.setStructuredEvent(structuredEvent_);

    StructuredPushReceiver _receiver = new StructuredPushReceiver(getClientORB());

    _sender.connect(eventChannel_, false);
    _receiver.connect(eventChannel_, false);

    new Thread(_receiver).start();
    new Thread(_sender).start();

    Thread.sleep(startOffset + 2000);

    if (expect) {
      assertTrue("Receiver should have received something", _receiver.isEventHandled());
    } else {
      assertTrue("Receiver shouldn't have received anything", !_receiver.isEventHandled());
    }

    _receiver.shutdown();
    _sender.shutdown();
  }
Exemple #2
0
  /**
   * test if events are reorderd respecting their priority. a supplier pushes some events with
   * ascending priority into a channel that was setup with OrderPolicy=PriorityOrder. A Consumer
   * receives and checks if the Events are delivered in descending Priority order.
   */
  public void testPriorityOrder() throws Exception {

    // create and setup channel
    IntHolder channelId = new IntHolder();

    Property[] qosProps;

    qosProps = new Property[] {new Property(OrderPolicy.value, priorityOrder)};

    EventChannel channel =
        getEventChannelFactory().create_channel(qosProps, new Property[0], channelId);

    // testdata
    StructuredEvent[] events = new StructuredEvent[10];
    for (int x = 0; x < events.length; ++x) {
      events[x] = new NotificationTestUtils(getClientORB()).getStructuredEvent();

      Any priority = getClientORB().create_any();
      priority.insert_short((short) x);

      events[x].header.variable_header = new Property[] {new Property(Priority.value, priority)};
    }

    final List received = new ArrayList();

    // setup clients
    StructuredPushReceiver receiver =
        new StructuredPushReceiver(this.getClientORB(), events.length) {
          public void push_structured_event(StructuredEvent event) throws Disconnected {
            super.push_structured_event(event);

            received.add(event);
          }
        };

    receiver.connect(channel, false);

    receiver.pushSupplier_.suspend_connection();

    StructuredPushSender sender = new StructuredPushSender(this.getClientORB());

    sender.setStructuredEvent(events);
    sender.setInterval(100);

    sender.connect(channel, false);

    // push events
    sender.run();

    assertFalse(receiver.isEventHandled());

    Thread.sleep(2000);

    receiver.pushSupplier_.resume_connection();

    receiver.setTimeOut(events.length * 1000);

    receiver.run();

    assertTrue(receiver.isEventHandled());

    Thread.sleep(2000);

    while (!received.isEmpty()) {
      StructuredEvent event = (StructuredEvent) received.remove(0);

      Iterator i = received.iterator();
      while (i.hasNext()) {
        short p1 = event.header.variable_header[0].value.extract_short();

        short p2 = ((StructuredEvent) i.next()).header.variable_header[0].value.extract_short();

        assertTrue(p1 + " > " + p2, p1 > p2);
      }
    }
  }