下面列出了java.util.concurrent.atomic.LongAdder#intValue() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@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);
}
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;
}
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();
}
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));
}