当前位置: 首页>>代码示例>>Java>>正文


Java GcFinalization.awaitClear方法代码示例

本文整理汇总了Java中com.google.common.testing.GcFinalization.awaitClear方法的典型用法代码示例。如果您正苦于以下问题:Java GcFinalization.awaitClear方法的具体用法?Java GcFinalization.awaitClear怎么用?Java GcFinalization.awaitClear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.common.testing.GcFinalization的用法示例。


在下文中一共展示了GcFinalization.awaitClear方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testEviction

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction() {
  TestState state = new TestState();
  Key<Integer> key = Key.get(Integer.class);
  Object source = new Object();
  
  WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);

  set.add(key, state, source);
  assertTrue(set.contains(key));
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key).contains(source));

  state = null;

  GcFinalization.awaitFullGc();

  assertFalse(set.contains(Key.get(Integer.class)));
  assertNull(set.getSources(Key.get(Integer.class)));

  // Ensure there are no hanging references.
  key = null;
  GcFinalization.awaitClear(weakKeyRef);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:24,代码来源:WeakKeySetTest.java

示例2: testEviction_nullSource

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testEviction_nullSource() {
  TestState state = new TestState();
  Key<Integer> key = Key.get(Integer.class);
  Object source = null;
  
  WeakReference<Key<Integer>> weakKeyRef = new WeakReference<Key<Integer>>(key);

  set.add(key, state, source);
  assertTrue(set.contains(key));
  assertEquals(1, set.getSources(key).size());
  assertTrue(set.getSources(key).contains(source));

  state = null;

  GcFinalization.awaitFullGc();

  assertFalse(set.contains(Key.get(Integer.class)));
  assertNull(set.getSources(Key.get(Integer.class)));

  // Ensure there are no hanging references.
  key = null;
  GcFinalization.awaitClear(weakKeyRef);
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:24,代码来源:WeakKeySetTest.java

示例3: testWeakKeySet_integration

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testWeakKeySet_integration() {
  Injector parentInjector = Guice.createInjector(new AbstractModule() {
        @Override protected void configure() {
          bind(Integer.class).toInstance(4);
        }
      });
  assertNotBlacklisted(parentInjector, Key.get(String.class));

  Injector childInjector = parentInjector.createChildInjector(new AbstractModule() {
    @Override protected void configure() {
      bind(String.class).toInstance("bar");
    }
  });
  WeakReference<Injector> weakRef = new WeakReference<Injector>(childInjector);
  assertBlacklisted(parentInjector, Key.get(String.class));
  
  // Clear the ref, GC, and ensure that we are no longer blacklisting.
  childInjector = null;
  GcFinalization.awaitClear(weakRef);
  assertNotBlacklisted(parentInjector, Key.get(String.class));
}
 
开发者ID:cgruber,项目名称:guice-old,代码行数:22,代码来源:WeakKeySetTest.java

示例4: invalidatedValuesAreGCedAsExpected

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
@Test
public void invalidatedValuesAreGCedAsExpected() throws Exception {
  SkyKey key = GraphTester.skyKey("a");
  HeavyValue heavyValue = new HeavyValue();
  WeakReference<HeavyValue> weakRef = new WeakReference<>(heavyValue);
  tester.set("a", heavyValue);

  graph = new InMemoryGraphImpl();
  eval(false, key);
  invalidate(graph, new DirtyTrackingProgressReceiver(null), key);

  tester = null;
  heavyValue = null;
  if (gcExpected()) {
    GcFinalization.awaitClear(weakRef);
  } else {
    // Not a reliable check, but better than nothing.
    System.gc();
    Thread.sleep(300);
    assertThat(weakRef.get()).isNotNull();
  }
}
 
开发者ID:bazelbuild,项目名称:bazel,代码行数:23,代码来源:EagerInvalidatorTest.java

示例5: testInputGCedIfUnreferenced

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
@AndroidIncompatible // reference is never cleared under some versions of the emulator
@GwtIncompatible
public void testInputGCedIfUnreferenced() throws Exception {
  SettableFuture<Long> future1 = SettableFuture.create();
  SettableFuture<Long> future2 = SettableFuture.create();
  WeakReference<SettableFuture<Long>> future1Ref = new WeakReference<>(future1);
  WeakReference<SettableFuture<Long>> future2Ref = new WeakReference<>(future2);

  ImmutableList<ListenableFuture<Long>> delegates =
      inCompletionOrder(ImmutableList.<ListenableFuture<Long>>of(future1, future2));

  future1.set(1L);

  future1 = null;
  // First future is complete, should be unreferenced
  GcFinalization.awaitClear(future1Ref);
  ListenableFuture<Long> outputFuture1 = delegates.get(0);
  delegates = null;
  future2 = null;
  // No references to list or other output future, second future should be unreferenced
  GcFinalization.awaitClear(future2Ref);
  outputFuture1.get();
}
 
开发者ID:google,项目名称:guava,代码行数:24,代码来源:FuturesTest.java

示例6: testFreesNextReference

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
@GwtIncompatible // weak references
public void testFreesNextReference() {
  Iterator<Object> itr = new AbstractIterator<Object>() {
    @Override public Object computeNext() {
      return new Object();
    }
  };
  WeakReference<Object> ref = new WeakReference<Object>(itr.next());
  GcFinalization.awaitClear(ref);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:11,代码来源:AbstractIteratorTest.java

示例7: testUnloadableInStaticFieldIfClosed

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testUnloadableInStaticFieldIfClosed() throws Exception {
  Policy oldPolicy = Policy.getPolicy();
  SecurityManager oldSecurityManager = System.getSecurityManager();
  try {
    Policy.setPolicy(new PermissivePolicy());
    System.setSecurityManager(new SecurityManager());
    WeakReference<ClassLoader> loaderRef = doTestUnloadableInStaticFieldIfClosed();
    GcFinalization.awaitClear(loaderRef);
  } finally {
    System.setSecurityManager(oldSecurityManager);
    Policy.setPolicy(oldPolicy);
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:14,代码来源:FinalizableReferenceQueueClassLoaderUnloadingTest.java

示例8: doTestUnloadableInStaticFieldIfClosed

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
private WeakReference<ClassLoader> doTestUnloadableInStaticFieldIfClosed() throws Exception {
  final URLClassLoader myLoader = (URLClassLoader) getClass().getClassLoader();
  final URL[] urls = myLoader.getURLs();
  URLClassLoader sepLoader = new URLClassLoader(urls, myLoader.getParent());

  Class<?> frqC = FinalizableReferenceQueue.class;
  Class<?> sepFrqC = sepLoader.loadClass(frqC.getName());
  assertNotSame(frqC, sepFrqC);

  Class<?> sepFrqSystemLoaderC =
      sepLoader.loadClass(FinalizableReferenceQueue.SystemLoader.class.getName());
  Field disabled = sepFrqSystemLoaderC.getDeclaredField("disabled");
  disabled.setAccessible(true);
  disabled.set(null, true);

  Class<?> frqUserC = FrqUser.class;
  Class<?> sepFrqUserC = sepLoader.loadClass(frqUserC.getName());
  assertNotSame(frqUserC, sepFrqUserC);
  assertSame(sepLoader, sepFrqUserC.getClassLoader());

  Callable<?> sepFrqUser = (Callable<?>) sepFrqUserC.newInstance();
  WeakReference<?> finalizableWeakReference = (WeakReference<?>) sepFrqUser.call();

  GcFinalization.awaitClear(finalizableWeakReference);

  Field sepFrqUserFinalizedF = sepFrqUserC.getField("finalized");
  Semaphore finalizeCount = (Semaphore) sepFrqUserFinalizedF.get(null);
  boolean finalized = finalizeCount.tryAcquire(5, TimeUnit.SECONDS);
  assertTrue(finalized);

  Field sepFrqUserFrqF = sepFrqUserC.getField("frq");
  Closeable frq = (Closeable) sepFrqUserFrqF.get(null);
  frq.close();

  return new WeakReference<ClassLoader>(sepLoader);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:37,代码来源:FinalizableReferenceQueueClassLoaderUnloadingTest.java

示例9: testWeak_afterGC

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testWeak_afterGC() throws InterruptedException {
  Integer canonical = new Integer(5);
  Integer not = new Integer(5);

  Interner<Integer> pool = Interners.newWeakInterner();
  assertSame(canonical, pool.intern(canonical));

  WeakReference<Integer> signal = new WeakReference<Integer>(canonical);
  canonical = null;  // Hint to the JIT that canonical is unreachable

  GcFinalization.awaitClear(signal);
  assertSame(not, pool.intern(not));
}
 
开发者ID:paul-hammant,项目名称:googles-monorepo-demo,代码行数:14,代码来源:InternersTest.java

示例10: testStrongImplementations

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testStrongImplementations() {
  for (Striped<?> striped : strongImplementations()) {
    WeakReference<Object> weakRef = new WeakReference<Object>(striped.get(new Object()));
    WeakReference<Object> garbage = new WeakReference<Object>(new Object());
    GcFinalization.awaitClear(garbage);
    assertNotNull(weakRef.get());
  }
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:9,代码来源:StripedTest.java

示例11: testFreesNextReference

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
public void testFreesNextReference() {
  Iterator<Object> itr = new AbstractIterator<Object>() {
    @Override public Object computeNext() {
      return new Object();
    }
  };
  WeakReference<Object> ref = new WeakReference<Object>(itr.next());
  GcFinalization.awaitClear(ref);
}
 
开发者ID:ypresto,项目名称:miniguava,代码行数:10,代码来源:AbstractIteratorTest.java

示例12: testFreesNextReference

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
@GwtIncompatible("weak references")
@Test
public void testFreesNextReference() {
    Iterator<Object> itr = new AbstractIterator<Object>() {
        @Override public Object computeNext() {
            return new Object();
        }
    };
    WeakReference<Object> ref = new WeakReference<Object>(itr.next());
    GcFinalization.awaitClear(ref);
}
 
开发者ID:synchronoss,项目名称:nio-multipart,代码行数:12,代码来源:AbstractIteratorTest.java

示例13: testFreesNextReference

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
@GwtIncompatible("weak references")
public void testFreesNextReference() {
  Iterator<Object> itr = new AbstractIterator<Object>() {
    @Override public Object computeNext() {
      return new Object();
    }
  };
  WeakReference<Object> ref = new WeakReference<Object>(itr.next());
  GcFinalization.awaitClear(ref);
}
 
开发者ID:sander120786,项目名称:guava-libraries,代码行数:11,代码来源:AbstractIteratorTest.java

示例14: testFreesNextReference

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
@GwtIncompatible // weak references
public void testFreesNextReference() {
  Iterator<Object> itr =
      new AbstractIterator<Object>() {
        @Override
        public Object computeNext() {
          return new Object();
        }
      };
  WeakReference<Object> ref = new WeakReference<>(itr.next());
  GcFinalization.awaitClear(ref);
}
 
开发者ID:google,项目名称:guava,代码行数:13,代码来源:AbstractIteratorTest.java

示例15: doTestUnloadableInStaticFieldIfClosed

import com.google.common.testing.GcFinalization; //导入方法依赖的package包/类
private WeakReference<ClassLoader> doTestUnloadableInStaticFieldIfClosed() throws Exception {
  final ClassLoader myLoader = getClass().getClassLoader();
  URLClassLoader sepLoader = new URLClassLoader(getClassPathUrls(), myLoader.getParent());

  Class<?> frqC = FinalizableReferenceQueue.class;
  Class<?> sepFrqC = sepLoader.loadClass(frqC.getName());
  assertNotSame(frqC, sepFrqC);

  Class<?> sepFrqSystemLoaderC =
      sepLoader.loadClass(FinalizableReferenceQueue.SystemLoader.class.getName());
  Field disabled = sepFrqSystemLoaderC.getDeclaredField("disabled");
  disabled.setAccessible(true);
  disabled.set(null, true);

  Class<?> frqUserC = FrqUser.class;
  Class<?> sepFrqUserC = sepLoader.loadClass(frqUserC.getName());
  assertNotSame(frqUserC, sepFrqUserC);
  assertSame(sepLoader, sepFrqUserC.getClassLoader());

  Callable<?> sepFrqUser = (Callable<?>) sepFrqUserC.newInstance();
  WeakReference<?> finalizableWeakReference = (WeakReference<?>) sepFrqUser.call();

  GcFinalization.awaitClear(finalizableWeakReference);

  Field sepFrqUserFinalizedF = sepFrqUserC.getField("finalized");
  Semaphore finalizeCount = (Semaphore) sepFrqUserFinalizedF.get(null);
  boolean finalized = finalizeCount.tryAcquire(5, TimeUnit.SECONDS);
  assertTrue(finalized);

  Field sepFrqUserFrqF = sepFrqUserC.getField("frq");
  Closeable frq = (Closeable) sepFrqUserFrqF.get(null);
  frq.close();

  return new WeakReference<ClassLoader>(sepLoader);
}
 
开发者ID:google,项目名称:guava,代码行数:36,代码来源:FinalizableReferenceQueueClassLoaderUnloadingTest.java


注:本文中的com.google.common.testing.GcFinalization.awaitClear方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。