-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix some rawtypes in com.google.common.cache google/guava@310de86 Saturate LongAdder.sum() results to Long.MAX_VALUE during an overflow. google/guava@b28a260 Co-authored-by: Kurt Alfred Kluever <[email protected]>
- Loading branch information
Showing
6 changed files
with
171 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
133 changes: 133 additions & 0 deletions
133
guava/src/test/java/com/google/common/cache/AbstractCacheTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright (C) 2011 The Guava Authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.google.common.cache; | ||
|
||
import com.github.benmanes.caffeine.cache.RemovalCause; | ||
import com.github.benmanes.caffeine.cache.stats.CacheStats; | ||
import com.github.benmanes.caffeine.cache.stats.ConcurrentStatsCounter; | ||
import com.github.benmanes.caffeine.cache.stats.StatsCounter; | ||
|
||
import junit.framework.TestCase; | ||
|
||
/** | ||
* Unit test for {@link AbstractCache}. | ||
* | ||
* @author Charles Fry | ||
*/ | ||
public class AbstractCacheTest extends TestCase { | ||
|
||
public void testEmptySimpleStats() { | ||
StatsCounter counter = new ConcurrentStatsCounter(); | ||
CacheStats stats = counter.snapshot(); | ||
assertEquals(0, stats.requestCount()); | ||
assertEquals(0, stats.hitCount()); | ||
assertEquals(1.0, stats.hitRate()); | ||
assertEquals(0, stats.missCount()); | ||
assertEquals(0.0, stats.missRate()); | ||
assertEquals(0, stats.loadSuccessCount()); | ||
assertEquals(0, stats.loadFailureCount()); | ||
assertEquals(0, stats.loadCount()); | ||
assertEquals(0, stats.totalLoadTime()); | ||
assertEquals(0.0, stats.averageLoadPenalty()); | ||
assertEquals(0, stats.evictionCount()); | ||
} | ||
|
||
public void testSingleSimpleStats() { | ||
StatsCounter counter = new ConcurrentStatsCounter(); | ||
for (int i = 0; i < 11; i++) { | ||
counter.recordHits(1); | ||
} | ||
for (int i = 0; i < 13; i++) { | ||
counter.recordLoadSuccess(i); | ||
} | ||
for (int i = 0; i < 17; i++) { | ||
counter.recordLoadFailure(i); | ||
} | ||
for (int i = 0; i < 23; i++) { | ||
counter.recordMisses(1); | ||
} | ||
for (int i = 0; i < 27; i++) { | ||
counter.recordEviction(1, RemovalCause.SIZE); | ||
} | ||
CacheStats stats = counter.snapshot(); | ||
int requestCount = 11 + 23; | ||
assertEquals(requestCount, stats.requestCount()); | ||
assertEquals(11, stats.hitCount()); | ||
assertEquals(11.0 / requestCount, stats.hitRate()); | ||
int missCount = 23; | ||
assertEquals(missCount, stats.missCount()); | ||
assertEquals(((double) missCount) / requestCount, stats.missRate()); | ||
assertEquals(13, stats.loadSuccessCount()); | ||
assertEquals(17, stats.loadFailureCount()); | ||
assertEquals(13 + 17, stats.loadCount()); | ||
assertEquals(214, stats.totalLoadTime()); | ||
assertEquals(214.0 / (13 + 17), stats.averageLoadPenalty()); | ||
assertEquals(27, stats.evictionCount()); | ||
} | ||
|
||
public void testSimpleStatsOverflow() { | ||
StatsCounter counter = new ConcurrentStatsCounter(); | ||
counter.recordLoadSuccess(Long.MAX_VALUE); | ||
counter.recordLoadSuccess(1); | ||
CacheStats stats = counter.snapshot(); | ||
assertEquals(Long.MAX_VALUE, stats.totalLoadTime()); | ||
} | ||
|
||
public void testSimpleStatsIncrementBy() { | ||
long totalLoadTime = 0; | ||
|
||
ConcurrentStatsCounter counter1 = new ConcurrentStatsCounter(); | ||
for (int i = 0; i < 11; i++) { | ||
counter1.recordHits(1); | ||
} | ||
for (int i = 0; i < 13; i++) { | ||
counter1.recordLoadSuccess(i); | ||
totalLoadTime += i; | ||
} | ||
for (int i = 0; i < 17; i++) { | ||
counter1.recordLoadFailure(i); | ||
totalLoadTime += i; | ||
} | ||
for (int i = 0; i < 19; i++) { | ||
counter1.recordMisses(1); | ||
} | ||
for (int i = 0; i < 23; i++) { | ||
counter1.recordEviction(1, RemovalCause.SIZE); | ||
} | ||
|
||
ConcurrentStatsCounter counter2 = new ConcurrentStatsCounter(); | ||
for (int i = 0; i < 27; i++) { | ||
counter2.recordHits(1); | ||
} | ||
for (int i = 0; i < 31; i++) { | ||
counter2.recordLoadSuccess(i); | ||
totalLoadTime += i; | ||
} | ||
for (int i = 0; i < 37; i++) { | ||
counter2.recordLoadFailure(i); | ||
totalLoadTime += i; | ||
} | ||
for (int i = 0; i < 41; i++) { | ||
counter2.recordMisses(1); | ||
} | ||
for (int i = 0; i < 43; i++) { | ||
counter1.recordEviction(1, RemovalCause.SIZE); | ||
} | ||
|
||
counter1.incrementBy(counter2); | ||
assertEquals(new CacheStats(38, 60, 44, 54, totalLoadTime, 66, 66), counter1.snapshot()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters