use of com.google.common.testing.GcFinalization.FinalizationPredicate in project guava by google.
the class GcFinalizationTest method testAwaitDone_FinalizationPredicate_Interrupted.
public void testAwaitDone_FinalizationPredicate_Interrupted() {
Interruptenator interruptenator = new Interruptenator(Thread.currentThread());
try {
try {
GcFinalization.awaitDone(new FinalizationPredicate() {
@Override
public boolean isDone() {
return false;
}
});
fail("should throw");
} catch (RuntimeException expected) {
assertWrapsInterruptedException(expected);
}
} finally {
interruptenator.shutdown();
Thread.interrupted();
}
}
use of com.google.common.testing.GcFinalization.FinalizationPredicate in project grpc-java by grpc.
the class SharedCallCounterMapTest method gcAndRecreate.
@Test
public void gcAndRecreate() {
// assign to null for GC only
@SuppressWarnings("UnusedVariable") AtomicLong counter = map.getOrCreate(CLUSTER, EDS_SERVICE_NAME);
final CounterReference ref = counters.get(CLUSTER).get(EDS_SERVICE_NAME);
assertThat(counter.get()).isEqualTo(0);
counter = null;
GcFinalization.awaitDone(new FinalizationPredicate() {
@Override
public boolean isDone() {
return ref.isEnqueued();
}
});
map.getOrCreate(CLUSTER, EDS_SERVICE_NAME);
assertThat(counters.get(CLUSTER)).isNotNull();
assertThat(counters.get(CLUSTER).get(EDS_SERVICE_NAME)).isNotNull();
}
use of com.google.common.testing.GcFinalization.FinalizationPredicate in project guava by hceylan.
the class GcFinalizationTest method testAwaitDone_FinalizationPredicate.
public void testAwaitDone_FinalizationPredicate() {
final WeakHashMap<Object, Object> map = new WeakHashMap<Object, Object>();
map.put(new Object(), Boolean.TRUE);
GcFinalization.awaitDone(new FinalizationPredicate() {
public boolean isDone() {
return map.isEmpty();
}
});
assertTrue(map.isEmpty());
}
use of com.google.common.testing.GcFinalization.FinalizationPredicate in project guava by hceylan.
the class GcFinalizationTest method testAwaitDone_FinalizationPredicate_Interrupted.
public void testAwaitDone_FinalizationPredicate_Interrupted() {
Interruptenator interruptenator = new Interruptenator(Thread.currentThread());
try {
try {
GcFinalization.awaitDone(new FinalizationPredicate() {
public boolean isDone() {
return false;
}
});
fail("should throw");
} catch (RuntimeException expected) {
assertWrapsInterruptedException(expected);
}
} finally {
interruptenator.shutdown();
Thread.interrupted();
}
}
use of com.google.common.testing.GcFinalization.FinalizationPredicate in project guava by google.
the class GcFinalizationTest method testAwaitDone_FinalizationPredicate.
public void testAwaitDone_FinalizationPredicate() {
final WeakHashMap<Object, Object> map = new WeakHashMap<>();
map.put(new Object(), Boolean.TRUE);
GcFinalization.awaitDone(new FinalizationPredicate() {
@Override
public boolean isDone() {
return map.isEmpty();
}
});
assertTrue(map.isEmpty());
}
Aggregations