@Test public void shouldNotDiscardMessageCausingSequenceError() throws InterruptedException { final List<CombinedBurst> bursts = new ArrayList<CombinedBurst>(); final Lock syncLock = new ReentrantLock(); final Condition allBurstsArrived = syncLock.newCondition(); final int burstsSent = 2; channel.registerBurstListener(new BroadcastListener<CombinedBurst>() { @Override public void receiveMessage(CombinedBurst message) { bursts.add(message); if (bursts.size() >= burstsSent) { try { syncLock.lock(); allBurstsArrived.signalAll(); } finally { syncLock.unlock(); } } } }); @SuppressWarnings("unchecked") BroadcastListener<BurstDataMessage> listener = (BroadcastListener<BurstDataMessage>) new Mirror().on(channel).get().field("burstListener"); byte [] data = new byte[100]; byte magicValue1 = 0x41; int magicIndex1 = 7; data[magicIndex1] = magicValue1; int count = 0; for (BurstDataMessage msg : genBurst(data)) { listener.receiveMessage(msg); if (++count > 2) { break; } } byte [] data2 = new byte[100]; byte magicValue2 = 0x29; int magicIndex2 = 23; data2[magicIndex2] = magicValue2; for (BurstDataMessage msg : genBurst(data2)){ listener.receiveMessage(msg); } try { syncLock.lock(); while (bursts.size() < burstsSent) { if (!allBurstsArrived.await(100, TimeUnit.MILLISECONDS)) { throw new RuntimeException("timeout waiting for bursts to arrive"); } } } finally { syncLock.unlock(); } assertTrue(bursts.get(0).getStatusFlags().contains(StatusFlag.ERROR_SEQUENCE_INVALID)); assertTrue(bursts.get(1).isComplete()); count = 0; for (byte b : bursts.get(0).getData()) { assertEquals(data[count], b); count++; } count = 0; for (byte b : bursts.get(1).getData()) { if (count >= data2.length) { break; } assertEquals(data2[count], b); count++; } boolean receivedAtLeastAsLongSent = (bursts.get(1).getData().length >= data2.length); assertTrue(receivedAtLeastAsLongSent); }
public synchronized void registerBurstListener( BroadcastListener<CombinedBurst> listener) { burstMessenger.addBroadcastListener(listener); }
Channel { public synchronized void registerBurstListener( BroadcastListener<CombinedBurst> listener) { burstMessenger.addBroadcastListener(listener); } }
Channel { public synchronized void registerBurstListener( BroadcastListener<CombinedBurst> listener) { burstMessenger.addBroadcastListener(listener); } Channel(Node parent, int number); }
Channel { public synchronized void registerBurstListener( BroadcastListener<CombinedBurst> listener) { burstMessenger.addBroadcastListener(listener); } Channel(Node parent, int number); Node getParent(); Lock getSendLock(); synchronized String getName(); synchronized void setName(String name); synchronized boolean isFree(); synchronized int getNumber(); synchronized void registerRxListener(
			final BroadcastListener<V> listener, final Class<V> clazz); synchronized void removeRxListener(
			final BroadcastListener<V> listener); synchronized void removeAllRxListeners(); MessageMetaWrapper<StandardMessage> send(ChannelMessage msg); void assign(NetworkKey key, ChannelType type,
			ExtendedAssignment... extended); void assign(Network network, ChannelType type,
			ExtendedAssignment... extended); void setId(int deviceNumber, int deviceType, int transmissionType,
			boolean setPairingFlag); void setId(ChannelId channelId); void setFrequency(int channelFrequency); void setPeriod(int period); void setSearchTimeout(int timeout); StandardMessage sendAndWaitForMessage(final ChannelMessage msg,
			final MessageCondition condition, final Long timeout,
			final TimeUnit timeoutUnit, final Receipt receipt); synchronized void unassign(); synchronized void assign(NetworkKey key,
			ChannelAssignMessage assignMessage); synchronized void open(); synchronized void close(); void sendBurst(byte[] data, Long timeout, TimeUnit timeoutUnit); synchronized void registerBurstListener(
			BroadcastListener<CombinedBurst> listener); synchronized void removeBurstListener(
			BroadcastListener<CombinedBurst> listener); double getChannelPeriod(); long getBurstTimeout(); void setBurstTimeout(long burstTimeout); synchronized ChannelStatusResponse requestStatus(); void registerEventHandler(ChannelEventHandler handler); synchronized void updateExclusionInclusionList(int index, ChannelId id); synchronized void configureExclusionInclusionList(int listSize, boolean exclude); void blacklist(ChannelId [] ids); void whitelist(ChannelId [] ids); void sendAndWaitForResponseNoError(ChannelMessage msg); synchronized void setTransmitPower(int powerLevel); synchronized void setProximitySearchThreshold(int threshold); synchronized void configureFrequencyAgility(int frequency1, int frequency2,  int frequency3); synchronized void setLowPrioirtySearchTimeout(int timeout); synchronized void setSearchPriority(int priority); synchronized void openInRxScanMode(); }
Channel { public synchronized void registerBurstListener( BroadcastListener<CombinedBurst> listener) { burstMessenger.addBroadcastListener(listener); } Channel(Node parent, int number); Node getParent(); Lock getSendLock(); synchronized String getName(); synchronized void setName(String name); synchronized boolean isFree(); synchronized int getNumber(); synchronized void registerRxListener(
			final BroadcastListener<V> listener, final Class<V> clazz); synchronized void removeRxListener(
			final BroadcastListener<V> listener); synchronized void removeAllRxListeners(); MessageMetaWrapper<StandardMessage> send(ChannelMessage msg); void assign(NetworkKey key, ChannelType type,
			ExtendedAssignment... extended); void assign(Network network, ChannelType type,
			ExtendedAssignment... extended); void setId(int deviceNumber, int deviceType, int transmissionType,
			boolean setPairingFlag); void setId(ChannelId channelId); void setFrequency(int channelFrequency); void setPeriod(int period); void setSearchTimeout(int timeout); StandardMessage sendAndWaitForMessage(final ChannelMessage msg,
			final MessageCondition condition, final Long timeout,
			final TimeUnit timeoutUnit, final Receipt receipt); synchronized void unassign(); synchronized void assign(NetworkKey key,
			ChannelAssignMessage assignMessage); synchronized void open(); synchronized void close(); void sendBurst(byte[] data, Long timeout, TimeUnit timeoutUnit); synchronized void registerBurstListener(
			BroadcastListener<CombinedBurst> listener); synchronized void removeBurstListener(
			BroadcastListener<CombinedBurst> listener); double getChannelPeriod(); long getBurstTimeout(); void setBurstTimeout(long burstTimeout); synchronized ChannelStatusResponse requestStatus(); void registerEventHandler(ChannelEventHandler handler); synchronized void updateExclusionInclusionList(int index, ChannelId id); synchronized void configureExclusionInclusionList(int listSize, boolean exclude); void blacklist(ChannelId [] ids); void whitelist(ChannelId [] ids); void sendAndWaitForResponseNoError(ChannelMessage msg); synchronized void setTransmitPower(int powerLevel); synchronized void setProximitySearchThreshold(int threshold); synchronized void configureFrequencyAgility(int frequency1, int frequency2,  int frequency3); synchronized void setLowPrioirtySearchTimeout(int timeout); synchronized void setSearchPriority(int priority); synchronized void openInRxScanMode(); static final int SEARCH_TIMEOUT_NEVER; final static Logger LOGGER; }