use of com.google.common.annotations.GwtIncompatible in project caffeine by ben-manes.
the class CacheBuilderTest method testRemovalNotification_clear_basher.
// "Basher tests", where we throw a bunch of stuff at a LoadingCache and check basic invariants.
/**
* This is a less carefully-controlled version of {@link #testRemovalNotification_clear} - this is
* a black-box test that tries to create lots of different thread-interleavings, and asserts that
* each computation is affected by a call to {@code clear()} (and therefore gets passed to the
* removal listener), or else is not affected by the {@code clear()} (and therefore exists in the
* cache afterward).
*/
@GwtIncompatible("QueuingRemovalListener")
@SuppressWarnings("FutureReturnValueIgnored")
public void testRemovalNotification_clear_basher() throws InterruptedException {
// If a clear() happens close to the end of computation, one of two things should happen:
// - computation ends first: the removal listener is called, and the cache does not contain the
// key/value pair
// - clear() happens first: the removal listener is not called, and the cache contains the pair
AtomicBoolean computationShouldWait = new AtomicBoolean();
CountDownLatch computationLatch = new CountDownLatch(1);
QueuingRemovalListener<String, String> listener = queuingRemovalListener();
final LoadingCache<String, String> cache = CaffeinatedGuava.build(Caffeine.newBuilder().removalListener(listener).executor(MoreExecutors.directExecutor()), new DelayingIdentityLoader<String>(computationShouldWait, computationLatch));
int nThreads = 100;
int nTasks = 1000;
int nSeededEntries = 100;
Set<String> expectedKeys = Sets.newHashSetWithExpectedSize(nTasks + nSeededEntries);
// entries
for (int i = 0; i < nSeededEntries; i++) {
String s = "b" + i;
cache.getUnchecked(s);
expectedKeys.add(s);
}
computationShouldWait.set(true);
final AtomicInteger computedCount = new AtomicInteger();
ExecutorService threadPool = Executors.newFixedThreadPool(nThreads);
final CountDownLatch tasksFinished = new CountDownLatch(nTasks);
for (int i = 0; i < nTasks; i++) {
final String s = "a" + i;
threadPool.submit(new Runnable() {
@Override
public void run() {
cache.getUnchecked(s);
computedCount.incrementAndGet();
tasksFinished.countDown();
}
});
expectedKeys.add(s);
}
computationLatch.countDown();
// let some computations complete
while (computedCount.get() < nThreads) {
Thread.yield();
}
cache.invalidateAll();
tasksFinished.await();
// Check all of the removal notifications we received: they should have had correctly-associated
// keys and values. (An earlier bug saw removal notifications for in-progress computations,
// which had real keys with null values.)
Map<String, String> removalNotifications = Maps.newHashMap();
for (RemovalNotification<String, String> notification : listener) {
removalNotifications.put(notification.getKey(), notification.getValue());
assertEquals("Unexpected key/value pair passed to removalListener", notification.getKey(), notification.getValue());
}
// notifications for all of them.
for (int i = 0; i < nSeededEntries; i++) {
assertEquals("b" + i, removalNotifications.get("b" + i));
}
// Each of the values added to the map should either still be there, or have seen a removal
// notification.
assertEquals(expectedKeys, Sets.union(cache.asMap().keySet(), removalNotifications.keySet()));
assertTrue(Sets.intersection(cache.asMap().keySet(), removalNotifications.keySet()).isEmpty());
}
use of com.google.common.annotations.GwtIncompatible in project caffeine by ben-manes.
the class CacheBuilderTest method testNullParameters.
@GwtIncompatible("NullPointerTester")
public void testNullParameters() throws Exception {
NullPointerTester tester = new NullPointerTester();
Caffeine<Object, Object> builder = Caffeine.newBuilder();
tester.testAllPublicInstanceMethods(builder);
}
use of com.google.common.annotations.GwtIncompatible in project symja_android_library by axkr.
the class BigIntegerMath method sqrt.
/**
* Returns the square root of {@code x}, rounded with the specified rounding mode.
*
* @throws IllegalArgumentException if {@code x < 0}
* @throws ArithmeticException if {@code mode} is {@link RoundingMode#UNNECESSARY} and
* {@code sqrt(x)} is not an integer
*/
@GwtIncompatible("TODO")
@SuppressWarnings("fallthrough")
public static BigInteger sqrt(BigInteger x, RoundingMode mode) {
checkNonNegative("x", x);
if (fitsInLong(x)) {
return BigInteger.valueOf(LongMath.sqrt(x.longValue(), mode));
}
BigInteger sqrtFloor = sqrtFloor(x);
switch(mode) {
case UNNECESSARY:
// fall through
checkRoundingUnnecessary(sqrtFloor.pow(2).equals(x));
case FLOOR:
case DOWN:
return sqrtFloor;
case CEILING:
case UP:
int sqrtFloorInt = sqrtFloor.intValue();
boolean sqrtFloorIsExact = // fast check mod 2^32
(sqrtFloorInt * sqrtFloorInt == x.intValue()) && // slow exact check
sqrtFloor.pow(2).equals(x);
return sqrtFloorIsExact ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
case HALF_DOWN:
case HALF_UP:
case HALF_EVEN:
BigInteger halfSquare = sqrtFloor.pow(2).add(sqrtFloor);
/*
* We wish to test whether or not x <= (sqrtFloor + 0.5)^2 = halfSquare + 0.25. Since both
* x and halfSquare are integers, this is equivalent to testing whether or not x <=
* halfSquare.
*/
return (halfSquare.compareTo(x) >= 0) ? sqrtFloor : sqrtFloor.add(BigInteger.ONE);
default:
throw new AssertionError();
}
}
use of com.google.common.annotations.GwtIncompatible in project janusgraph by JanusGraph.
the class Stopwatch method toString.
/**
* Returns a string representation of the current elapsed time.
*/
@GwtIncompatible("String.format()")
@Override
public String toString() {
long nanos = elapsedNanos();
TimeUnit unit = chooseUnit(nanos);
double value = (double) nanos / NANOSECONDS.convert(1, unit);
// Too bad this functionality is not exposed as a regular method call
return String.format("%.4g %s", value, abbreviate(unit));
}
use of com.google.common.annotations.GwtIncompatible in project closure-compiler by google.
the class JSModuleGraph method toJson.
/**
* Returns a JSON representation of the JSModuleGraph. Specifically a
* JsonArray of "Modules" where each module has a
* - "name"
* - "dependencies" (list of module names)
* - "transitive-dependencies" (list of module names, deepest first)
* - "inputs" (list of file names)
* @return List of module JSONObjects.
*/
@GwtIncompatible("com.google.gson")
JsonArray toJson() {
JsonArray modules = new JsonArray();
for (JSModule module : getAllModules()) {
JsonObject node = new JsonObject();
node.add("name", new JsonPrimitive(module.getName()));
JsonArray deps = new JsonArray();
node.add("dependencies", deps);
for (JSModule m : module.getDependencies()) {
deps.add(new JsonPrimitive(m.getName()));
}
JsonArray transitiveDeps = new JsonArray();
node.add("transitive-dependencies", transitiveDeps);
for (JSModule m : getTransitiveDepsDeepestFirst(module)) {
transitiveDeps.add(new JsonPrimitive(m.getName()));
}
JsonArray inputs = new JsonArray();
node.add("inputs", inputs);
for (CompilerInput input : module.getInputs()) {
inputs.add(new JsonPrimitive(input.getSourceFile().getOriginalPath()));
}
modules.add(node);
}
return modules;
}
Aggregations