public int decRefToStream(final int streamId) { final int count = refCountByStreamIdMap.decrementAndGet(streamId); if (-1 == count) { refCountByStreamIdMap.remove(streamId); throw new IllegalStateException("could not find stream Id to decrement: " + streamId); } return count; }
@Test public void shouldResultInNotEmptyAfterIncAndDecWhenHaveKey() { map.put(1, 1); map.incrementAndGet(1); map.decrementAndGet(1); assertEquals(1, map.get(1)); assertEquals(1, map.size()); }
@Test public void shouldRemoveEntryAfterDecToInitialVal() { map.put(1, INITIAL_VALUE + 1); map.decrementAndGet(1); assertEquals(INITIAL_VALUE, map.get(1)); assertTrue(map.isEmpty()); assertFalse(map.containsKey(1)); }
@Test public void shouldResultInEmptyAfterIncAndDecWhenEmpty() { map.incrementAndGet(1); map.decrementAndGet(1); assertTrue(map.isEmpty()); map.getAndIncrement(1); map.getAndDecrement(1); assertTrue(map.isEmpty()); map.incrementAndGet(1); map.getAndDecrement(1); assertTrue(map.isEmpty()); map.getAndIncrement(1); map.decrementAndGet(1); assertTrue(map.isEmpty()); }
@Test public void shouldContainValueForIncAndDecEntries() { map.incrementAndGet(1); map.getAndIncrement(2); map.getAndAdd(3, 2); map.addAndGet(4, 3); map.decrementAndGet(5); map.getAndDecrement(6); assertTrue(map.containsKey(1)); assertTrue(map.containsKey(2)); assertTrue(map.containsKey(3)); assertTrue(map.containsKey(4)); assertTrue(map.containsKey(5)); assertTrue(map.containsKey(6)); }
public int decRefToStream(final int streamId) { final int count = refCountByStreamIdMap.decrementAndGet(streamId); if (-1 == count) { refCountByStreamIdMap.remove(streamId); throw new IllegalStateException("could not find stream Id to decrement: " + streamId); } return count; }
public int decRefToStream(final int streamId) { final int count = refCountByStreamIdMap.decrementAndGet(streamId); if (-1 == count) { refCountByStreamIdMap.remove(streamId); throw new IllegalStateException("could not find stream Id to decrement: " + streamId); } return count; }