Skip to content

Commit

Permalink
Fix flaky test due to racy assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-manes committed Mar 23, 2016
1 parent b0cd1a5 commit ebd9287
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1193,12 +1193,6 @@ public int size() {
return data.size();
}

/**
* Returns the number of mappings. The value returned is an estimate; the actual count may differ
* if there are concurrent insertions or removals.
*
* @return the number of mappings
*/
@Override
public long estimatedSize() {
return data.mappingCount();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ interface Eviction<K, V> {
* Note that some implementations may have an internal inherent bound on the maximum total size.
* If the value specified exceeds that bound, then the value is set to the internal maximum.
*
* @param maximum the maximum, interpreted as weighted or unweighted size depending on the
* whether how this cache was constructed
* @param maximum the maximum, interpreted as weighted or unweighted size depending on how this
* cache was constructed
* @throws IllegalArgumentException if the maximum size specified is negative
*/
void setMaximum(@Nonnegative long maximum);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ public void evict_weighted_async(AsyncLoadingCache<Integer, Integer> cache,

ready.set(true);
Awaits.await().untilTrue(done);
assertThat(eviction.weightedSize().getAsLong(), is(10L));
assertThat(cache.synchronous().estimatedSize(), is(2L));
Awaits.await().until(() -> eviction.weightedSize().getAsLong(), is(10L));
Awaits.await().until(() -> cache.synchronous().estimatedSize(), is(2L));
assertThat(context, hasRemovalNotifications(context, 1, RemovalCause.SIZE));
verifyWriter(context, (verifier, writer) -> verifier.deletions(1, RemovalCause.SIZE));
}
Expand All @@ -240,8 +240,8 @@ public void evict_zero_async(AsyncLoadingCache<Integer, List<Integer>> cache,

ready.set(true);
Awaits.await().untilTrue(done);
assertThat(eviction.weightedSize().getAsLong(), is(0L));
assertThat(cache.synchronous().estimatedSize(), is(0L));
Awaits.await().until(() -> eviction.weightedSize().getAsLong(), is(0L));
Awaits.await().until(() -> cache.synchronous().estimatedSize(), is(0L));

assertThat(context, hasRemovalNotifications(context, 1, RemovalCause.SIZE));
verifyWriter(context, (verifier, writer) -> verifier.deletions(1, RemovalCause.SIZE));
Expand Down Expand Up @@ -349,8 +349,8 @@ public void put_asyncWeight(AsyncLoadingCache<Integer, List<Integer>> cache,

ready.set(true);
Awaits.await().untilTrue(done);
assertThat(eviction.weightedSize().getAsLong(), is(5L));
assertThat(cache.synchronous().estimatedSize(), is(1L));
Awaits.await().until(() -> eviction.weightedSize().getAsLong(), is(5L));
Awaits.await().until(() -> cache.synchronous().estimatedSize(), is(1L));
}

@Test(dataProvider = "caches")
Expand Down
2 changes: 1 addition & 1 deletion gradle/dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ ext {
error_prone_annotations: '2.0.8',
flip_tables: '1.0.2',
guava: '19.0',
javapoet: '1.6.0',
javapoet: '1.6.1',
jcache: '1.0.0',
jsr305: '3.0.1',
stream: '2.9.1',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

import javax.annotation.Nullable;

import com.github.benmanes.caffeine.base.UnsafeAccess;
import com.google.common.annotations.GwtCompatible;
import com.google.common.annotations.GwtIncompatible;
import com.google.common.collect.Maps;
Expand Down Expand Up @@ -94,9 +93,8 @@ static <K, V> CacheLoader<K, V> exceptionLoader(final Exception e) {
checkNotNull(e);
return new CacheLoader<K, V>() {
@Override
public V load(K key) {
UnsafeAccess.UNSAFE.throwException(e);
return null; // impossible
public V load(K key) throws Exception {
throw e;
}
};
}
Expand Down

0 comments on commit ebd9287

Please sign in to comment.