Search in sources :

Example 1 with FinalizationPredicate

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();
    }
}
Also used : FinalizationPredicate(com.google.common.testing.GcFinalization.FinalizationPredicate)

Example 2 with FinalizationPredicate

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();
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) CounterReference(io.grpc.xds.SharedCallCounterMap.CounterReference) FinalizationPredicate(com.google.common.testing.GcFinalization.FinalizationPredicate) Test(org.junit.Test)

Example 3 with FinalizationPredicate

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());
}
Also used : FinalizationPredicate(com.google.common.testing.GcFinalization.FinalizationPredicate) WeakHashMap(java.util.WeakHashMap)

Example 4 with FinalizationPredicate

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();
    }
}
Also used : FinalizationPredicate(com.google.common.testing.GcFinalization.FinalizationPredicate)

Example 5 with FinalizationPredicate

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());
}
Also used : FinalizationPredicate(com.google.common.testing.GcFinalization.FinalizationPredicate) WeakHashMap(java.util.WeakHashMap)

Aggregations

FinalizationPredicate (com.google.common.testing.GcFinalization.FinalizationPredicate)7 Test (org.junit.Test)3 CounterReference (io.grpc.xds.SharedCallCounterMap.CounterReference)2 WeakHashMap (java.util.WeakHashMap)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 ManagedChannel (io.grpc.ManagedChannel)1 ManagedChannelReference (io.grpc.internal.ManagedChannelOrphanWrapper.ManagedChannelReference)1 ReferenceQueue (java.lang.ref.ReferenceQueue)1 ArrayList (java.util.ArrayList)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Filter (java.util.logging.Filter)1 LogRecord (java.util.logging.LogRecord)1 Logger (java.util.logging.Logger)1