Java Code Examples for java.util.concurrent.atomic.LongAdder#intValue()

The following examples show how to use java.util.concurrent.atomic.LongAdder#intValue() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiTest.java    From robozonky with Apache License 2.0 6 votes vote down vote up
@Test
void retriesAfterTimeout() {
    final LoanApi mock = mock(LoanApi.class);
    final Api<LoanApi> api = new Api<>(mock);
    final String expected = UUID.randomUUID()
        .toString();
    final LongAdder adder = new LongAdder();
    final Function<LoanApi, String> function = (a) -> {
        adder.add(1);
        if (adder.intValue() > 2) {
            return expected;
        } else if (adder.intValue() == 2) {
            throw new ProcessingException(new IOException());
        } else {
            throw new ProcessingException(new SocketTimeoutException());
        }
    };
    final String result = api.call(function);
    assertThat(result).isSameAs(expected);
}
 
Example 2
Source File: StatisticsInformation.java    From kafka-pubsub-emulator with Apache License 2.0 5 votes vote down vote up
public Float getErrorRating() {
  LongAdder totalMessages = new LongAdder();
  totalMessages.add(this.error.intValue());
  totalMessages.add(this.count.intValue());
  if (totalMessages.intValue() == 0) {
    return 0F;
  }
  return (this.error.floatValue() / totalMessages.floatValue()) * 100;
}
 
Example 3
Source File: BlockCountCollection.java    From uSkyBlock with GNU General Public License v3.0 5 votes vote down vote up
public int add(Material type, byte dataValue, int blockCount) {
    BlockLevelConfig blockLevelConfig = configMap.get(type, dataValue);
    BlockMatch key = blockLevelConfig.getKey();
    LongAdder count = countMap.computeIfAbsent(key, k -> new LongAdder());
    count.add(blockCount);
    return count.intValue();
}
 
Example 4
Source File: EhcacheBasicGetAllTest.java    From ehcache3 with Apache License 2.0 5 votes vote down vote up
static void validateBulkCounters(InternalCache<?, ?> ehcache, int expectedHitCount, int expectedMissCount) {
  LongAdder hitAdder = ehcache.getBulkMethodEntries().get(BulkOps.GET_ALL_HITS);
  LongAdder missAdder = ehcache.getBulkMethodEntries().get(BulkOps.GET_ALL_MISS);
  int hitCount = hitAdder == null ? 0 : hitAdder.intValue();
  int missCount = missAdder == null ? 0 : missAdder.intValue();
  assertThat(hitCount, is(expectedHitCount));
  assertThat(missCount, is(expectedMissCount));
}