예제 #1
0
  @Test
  public void testStructuredEventWithStartTimeProperty() throws Exception {
    structuredEvent_.header.variable_header = new Property[1];

    Date _now = new Date();

    Any _startTimeAny = getORB().create_any();
    UtcT _startTime = Time.corbaTime(_now);
    UtcTHelper.insert(_startTimeAny, _startTime);

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

    Message _event = messageFactory_.newMessage(structuredEvent_, proxyConsumerMock_);

    assertTrue(_event.hasStartTime());
    assertEquals(_now.getTime(), _event.getStartTime());
  }
예제 #2
0
  public void processEventWithStartTime(long offset) throws Exception {
    final AtomicBoolean failed = new AtomicBoolean(true);

    structuredEvent_.header.variable_header = new Property[1];

    final Date _startTime = new Date(System.currentTimeMillis() + offset);

    Any _startTimeAny = getORB().create_any();
    UtcTHelper.insert(_startTimeAny, Time.corbaTime(_startTime));

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

    final Message _event = messageFactory_.newMessage(structuredEvent_, proxyConsumerMock_);

    final CountDownLatch _latch = new CountDownLatch(1);

    // TODO check if MockTaskProcessor can be used here
    final DefaultTaskFactory _defaultTaskFactory = new DefaultTaskFactory(getConfiguration());
    addDisposable(_defaultTaskFactory);
    DefaultTaskProcessor _taskProcessor =
        new DefaultTaskProcessor(getConfiguration(), _defaultTaskFactory) {
          public void processMessageInternal(Message event) {
            try {
              long _recvTime = System.currentTimeMillis();
              assertEquals(event, _event);
              assertTrue(_recvTime >= _startTime.getTime());

              failed.set(false);
            } finally {
              _latch.countDown();
            }
          }
        };

    _taskProcessor.processMessage(_event);

    _latch.await();

    assertFalse(failed.get());

    _taskProcessor.dispose();
  }
예제 #3
0
  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();
  }