use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class CacheBuilderTest method testRemovalNotification_clear.
// QueuingRemovalListener
@GwtIncompatible
public void testRemovalNotification_clear() throws InterruptedException {
// If a clear() happens while a computation is pending, we should not get a removal
// notification.
final AtomicBoolean shouldWait = new AtomicBoolean(false);
final CountDownLatch computingLatch = new CountDownLatch(1);
CacheLoader<String, String> computingFunction = new CacheLoader<String, String>() {
@Override
public String load(String key) throws InterruptedException {
if (shouldWait.get()) {
computingLatch.await();
}
return key;
}
};
QueuingRemovalListener<String, String> listener = queuingRemovalListener();
final LoadingCache<String, String> cache = CacheBuilder.newBuilder().concurrencyLevel(1).removalListener(listener).build(computingFunction);
// seed the map, so its segment's count > 0
cache.getUnchecked("a");
shouldWait.set(true);
final CountDownLatch computationStarted = new CountDownLatch(1);
final CountDownLatch computationComplete = new CountDownLatch(1);
new Thread(new Runnable() {
@Override
public void run() {
computationStarted.countDown();
cache.getUnchecked("b");
computationComplete.countDown();
}
}).start();
// wait for the computingEntry to be created
computationStarted.await();
cache.invalidateAll();
// let the computation proceed
computingLatch.countDown();
// don't check cache.size() until we know the get("b") call is complete
computationComplete.await();
// At this point, the listener should be holding the seed value (a -> a), and the map should
// contain the computed value (b -> b), since the clear() happened before the computation
// completed.
assertEquals(1, listener.size());
RemovalNotification<String, String> notification = listener.remove();
assertEquals("a", notification.getKey());
assertEquals("a", notification.getValue());
assertEquals(1, cache.size());
assertEquals("b", cache.getUnchecked("b"));
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class CharMatcherTest method testSmallCharMatcher.
// java.util.Random, java.util.BitSet
@GwtIncompatible
public void testSmallCharMatcher() {
CharMatcher len1 = SmallCharMatcher.from(bitSet("#"), "#");
CharMatcher len2 = SmallCharMatcher.from(bitSet("ab"), "ab");
CharMatcher len3 = SmallCharMatcher.from(bitSet("abc"), "abc");
CharMatcher len4 = SmallCharMatcher.from(bitSet("abcd"), "abcd");
assertTrue(len1.matches('#'));
assertFalse(len1.matches('!'));
assertTrue(len2.matches('a'));
assertTrue(len2.matches('b'));
for (char c = 'c'; c < 'z'; c++) {
assertFalse(len2.matches(c));
}
assertTrue(len3.matches('a'));
assertTrue(len3.matches('b'));
assertTrue(len3.matches('c'));
for (char c = 'd'; c < 'z'; c++) {
assertFalse(len3.matches(c));
}
assertTrue(len4.matches('a'));
assertTrue(len4.matches('b'));
assertTrue(len4.matches('c'));
assertTrue(len4.matches('d'));
for (char c = 'e'; c < 'z'; c++) {
assertFalse(len4.matches(c));
}
Random rand = new Random(1234);
for (int testCase = 0; testCase < 100; testCase++) {
char[] chars = randomChars(rand, rand.nextInt(63) + 1);
CharMatcher m = SmallCharMatcher.from(bitSet(chars), new String(chars));
checkExactMatches(m, chars);
}
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class EnumsTest method testNullPointerExceptions.
// NullPointerTester
@GwtIncompatible
public void testNullPointerExceptions() {
NullPointerTester tester = new NullPointerTester();
tester.testAllPublicStaticMethods(Enums.class);
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class EnumsTest method testGetField.
// reflection
@GwtIncompatible
public void testGetField() {
Field foo = Enums.getField(AnEnum.FOO);
assertEquals("FOO", foo.getName());
assertTrue(foo.isAnnotationPresent(ExampleAnnotation.class));
Field bar = Enums.getField(AnEnum.BAR);
assertEquals("BAR", bar.getName());
assertFalse(bar.isAnnotationPresent(ExampleAnnotation.class));
}
use of com.google.common.annotations.GwtIncompatible in project guava by google.
the class EnumsTest method doTestClassUnloading.
// Create a second ClassLoader and use it to get a second version of the TestEnum class.
// Run Enums.getIfPresent on that other TestEnum and then return a WeakReference containing the
// new ClassLoader. If Enums.getIfPresent does caching that prevents the shadow TestEnum
// (and therefore its ClassLoader) from being unloaded, then this WeakReference will never be
// cleared.
// weak references
@GwtIncompatible
private WeakReference<?> doTestClassUnloading() throws Exception {
URLClassLoader shadowLoader = new URLClassLoader(getClassPathUrls(), null);
@SuppressWarnings("unchecked") Class<TestEnum> shadowTestEnum = (Class<TestEnum>) Class.forName(TestEnum.class.getName(), false, shadowLoader);
assertNotSame(shadowTestEnum, TestEnum.class);
// We can't write Set<TestEnum> because that is a Set of the TestEnum from the original
// ClassLoader.
Set<Object> shadowConstants = new HashSet<>();
for (TestEnum constant : TestEnum.values()) {
Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, constant.name());
assertThat(result).isPresent();
shadowConstants.add(result.get());
}
assertEquals(ImmutableSet.<Object>copyOf(shadowTestEnum.getEnumConstants()), shadowConstants);
Optional<TestEnum> result = Enums.getIfPresent(shadowTestEnum, "blibby");
assertThat(result).isAbsent();
return new WeakReference<>(shadowLoader);
}
Aggregations