Browse Source

MINOR: Fix integer overflow in LRUCacheBenchmark (#7270)

The jmh LRUCacheBenchmark will exhibit an int overflow when run on a fast machine:

```
java.lang.ArrayIndexOutOfBoundsException: Index -3648 out of bounds for length 10000
	at org.apache.kafka.jmh.cache.LRUCacheBenchmark.testCachePerformance(LRUCacheBenchmark.java:70)
	at org.apache.kafka.jmh.cache.generated.LRUCacheBenchmark_testCachePerformance_jmhTest.testCachePerformance_thrpt_jmhStub(LRUCacheBenchmark_testCachePerformance_jmhTest.java:119)
	at org.apache.kafka.jmh.cache.generated.LRUCacheBenchmark_testCachePerformance_jmhTest.testCachePerformance_Throughput(LRUCacheBenchmark_testCachePerformance_jmhTest.java:83)
```

Reviewers: Jason Gustafson <jason@confluent.io>
pull/7287/head
Lucas Bradstreet 5 years ago committed by Jason Gustafson
parent
commit
fb381cb6c7
  1. 4
      jmh-benchmarks/src/main/java/org/apache/kafka/jmh/cache/LRUCacheBenchmark.java

4
jmh-benchmarks/src/main/java/org/apache/kafka/jmh/cache/LRUCacheBenchmark.java vendored

@ -52,7 +52,7 @@ public class LRUCacheBenchmark { @@ -52,7 +52,7 @@ public class LRUCacheBenchmark {
private LRUCache<String, String> lruCache;
int counter;
private long counter = 0;
@Setup(Level.Trial)
public void setUp() {
@ -66,7 +66,7 @@ public class LRUCacheBenchmark { @@ -66,7 +66,7 @@ public class LRUCacheBenchmark {
@Benchmark
public String testCachePerformance() {
counter++;
int index = counter % DISTINCT_KEYS;
int index = (int) (counter % DISTINCT_KEYS);
String hashkey = keys[index];
lruCache.put(hashkey, values[index]);
return lruCache.get(hashkey);

Loading…
Cancel
Save