/** * This method blocks until the given time has been reached. If the time is null, or it has * already passed, then this method returns immediately. */ public static void waitFor(UtcT time) { if (time != null) { long now = System.currentTimeMillis(); long delta = Time.millisTo(time); long then = now + delta; while (delta > 0) { try { Thread.sleep(delta); } catch (InterruptedException e) { // ignored } delta = then - System.currentTimeMillis(); } } }
@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()); }
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(); }
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(); }