@Override public boolean isFulFilled() throws IllegalStateException { mid.set(tracker.getNextMessageId()); return 0 <= mid.get(); } });
@Test public void testGetNextMessageIdFailsIfAllMidsAreInUse() throws Exception { // GIVEN a tracker whose MIDs are half in use NetworkConfig config = NetworkConfig.createStandardWithoutFile(); GroupedMessageIdTracker tracker = new GroupedMessageIdTracker(INITIAL_MID, config); for (int i = 0; i < TOTAL_NO_OF_MIDS / 2; i++) { int mid = tracker.getNextMessageId(); assertThat(mid, is(not(-1))); } // THEN using the complete other half should not be possible for (int i = 0; i < TOTAL_NO_OF_MIDS / 2; i++) { int mid = tracker.getNextMessageId(); if (0 > mid) return; } fail("mids should run out."); }
int nextMid = tracker.getNextMessageId(); if (nextMid < 0) break; int nextMid = tracker.getNextMessageId(); assertThat(nextMid, is(not(-1)));