EmbeddedSensorObservationPeriod implements IEmbeddedSensorObservationPeriod { @Override public boolean recordProcessor(final IMessageProcessor mp, final long time) throws EmbeddedSensorStrategyException, InvalidArgumentException { if (isCountLimited() && !isStartedAt(time)) { return false; } if (!incrementCount()) { strategy.updatePeriod(state, mp, time); return false; } else { return true; } } EmbeddedSensorObservationPeriod(final long start, final long end, final long nItems, final IEmbeddedSensorStrategy<TState> strategy); @Override EmbeddedSensorObservationPeriod<TState> nextPeriod(final long inclTime); @Override boolean isTimeCompleted(final long time); @Override boolean recordProcessor(final IMessageProcessor mp, final long time); @Override IObject createMessage();  }
@Test public void Should_notRecordDataBeforePeriodStartIfRecordsCountIsLimited() throws Exception { IEmbeddedSensorObservationPeriod esop = new EmbeddedSensorObservationPeriod<>(100, 200, 4, strategyMock); assertFalse(esop.recordProcessor(processors[0], 50)); verify(strategyMock, times(0)).updatePeriod(any(), any(), anyLong()); }
@Test public void Should_recordDataAfterPeriodStart() throws Exception { IEmbeddedSensorObservationPeriod esop = new EmbeddedSensorObservationPeriod<>(100, 200, 4, strategyMock); assertFalse(esop.recordProcessor(processors[0], 150)); verify(strategyMock).updatePeriod(same(states[0]), same(processors[0]), eq(150L)); }
@Test public void Should_limitCountOfRecords() throws Exception { IEmbeddedSensorObservationPeriod esop = new EmbeddedSensorObservationPeriod<>(100, 200, 2, strategyMock); assertFalse(esop.recordProcessor(processors[0], 150)); assertFalse(esop.recordProcessor(processors[1], 150)); assertTrue(esop.recordProcessor(processors[2], 150)); verify(strategyMock).updatePeriod(same(states[0]), same(processors[0]), eq(150L)); verify(strategyMock).updatePeriod(same(states[0]), same(processors[1]), eq(150L)); verify(strategyMock, times(0)).updatePeriod(same(states[0]), same(processors[2]), eq(150L)); }