Search in sources :

Example 1 with CounterReference

use of io.grpc.xds.SharedCallCounterMap.CounterReference 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 2 with CounterReference

use of io.grpc.xds.SharedCallCounterMap.CounterReference in project grpc-java by grpc.

the class SharedCallCounterMapTest method autoCleanUp.

@Test
public void autoCleanUp() {
    @SuppressWarnings("UnusedVariable") AtomicLong counter = map.getOrCreate(CLUSTER, EDS_SERVICE_NAME);
    final CounterReference ref = counters.get(CLUSTER).get(EDS_SERVICE_NAME);
    counter = null;
    GcFinalization.awaitDone(new FinalizationPredicate() {

        @Override
        public boolean isDone() {
            return ref.isEnqueued();
        }
    });
    map.cleanQueue();
    assertThat(counters).isEmpty();
}
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)

Aggregations

FinalizationPredicate (com.google.common.testing.GcFinalization.FinalizationPredicate)2 CounterReference (io.grpc.xds.SharedCallCounterMap.CounterReference)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)2 Test (org.junit.Test)2