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


Java FakeTicker类代码示例

本文整理汇总了Java中com.google.common.testing.FakeTicker的典型用法代码示例。如果您正苦于以下问题:Java FakeTicker类的具体用法?Java FakeTicker怎么用?Java FakeTicker使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: checkExpiration

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
private void checkExpiration(LoadingCache<String, Integer> cache, WatchedCreatorLoader loader,
    FakeTicker ticker, CountingRemovalListener<String, Integer> removalListener) {

  for (int i = 0; i < 10; i++) {
    assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
  }

  for (int i = 0; i < 10; i++) {
    loader.reset();
    assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
    assertFalse("Creator should not have been called @#" + i, loader.wasCalled());
  }

  CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);

  assertEquals("Map must be empty by now", 0, cache.size());
  assertEquals("Eviction notifications must be received", 10,
      removalListener.getCount());

  CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);
  // ensure that no new notifications are sent
  assertEquals("Eviction notifications must be received", 10,
      removalListener.getCount());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:25,代码来源:CacheExpirationTest.java

示例2: setup

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
@Before
public void setup() {
    MockitoAnnotations.initMocks(this);

    doNothing().when(mockCallback).accept(any(MockFailure.class));

    ticker = new FakeTicker();
    ticker.advance(ThreadLocalRandom.current().nextLong());
    doReturn(ticker).when(mockContext).ticker();

    final ClientActorConfig mockConfig = AccessClientUtil.newMockClientActorConfig();
    doReturn(mockConfig).when(mockContext).config();

    doReturn(mock(MessageSlicer.class)).when(mockContext).messageSlicer();

    mockActor = TestProbe.apply(actorSystem);
    mockBackendInfo = new BackendInfo(mockActor.ref(), 0, ABIVersion.current(), 5);
    mockRequest = new MockRequest(mockIdentifier, mockReplyTo);
    mockRequest2 = new MockRequest(mockIdentifier, mockReplyTo);
    mockResponse = mockRequest.toRequestFailure(mockCause);
    mockResponseEnvelope = new FailureEnvelope(mockResponse, 0, 0, 0);
    mockCookie = ThreadLocalRandom.current().nextLong();

    queue = new ConnectingClientConnection<>(mockContext, mockCookie);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:26,代码来源:ConnectingClientConnectionTest.java

示例3: testDelegate

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
@Test
public void testDelegate() throws Exception {
    FakeTicker ticker = new FakeTicker();
    CircuitBreaker circuitBreaker = new CircuitBreakerBuilder(remoteServiceName)
            .ticker(ticker)
            .build();

    @SuppressWarnings("unchecked")
    Client<RpcRequest, RpcResponse> delegate = mock(Client.class);
    when(delegate.execute(any(), any())).thenReturn(successRes);

    CircuitBreakerMapping mapping = (ctx, req) -> circuitBreaker;
    CircuitBreakerClient<RpcRequest, RpcResponse> stub = new CircuitBreakerClient<>(delegate, mapping);

    stub.execute(ctx, req);

    verify(delegate, times(1)).execute(eq(ctx), eq(req));
}
 
开发者ID:line,项目名称:armeria,代码行数:19,代码来源:CircuitBreakerClientTest.java

示例4: checkExpiration

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
private void checkExpiration(
    LoadingCache<String, Integer> cache,
    WatchedCreatorLoader loader,
    FakeTicker ticker,
    CountingRemovalListener<String, Integer> removalListener) {

  for (int i = 0; i < 10; i++) {
    assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
  }

  for (int i = 0; i < 10; i++) {
    loader.reset();
    assertEquals(Integer.valueOf(VALUE_PREFIX + i), cache.getUnchecked(KEY_PREFIX + i));
    assertFalse("Creator should not have been called @#" + i, loader.wasCalled());
  }

  CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);

  assertEquals("Map must be empty by now", 0, cache.size());
  assertEquals("Eviction notifications must be received", 10, removalListener.getCount());

  CacheTesting.expireEntries((LoadingCache<?, ?>) cache, EXPIRING_TIME, ticker);
  // ensure that no new notifications are sent
  assertEquals("Eviction notifications must be received", 10, removalListener.getCount());
}
 
开发者ID:google,项目名称:guava,代码行数:26,代码来源:CacheExpirationTest.java

示例5: testExpiration_invalidateAll

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testExpiration_invalidateAll() {
  FakeTicker ticker = new FakeTicker();
  QueuingRemovalListener<Integer, Integer> listener =
      TestingRemovalListeners.queuingRemovalListener();
  Cache<Integer, Integer> cache =
      CacheBuilder.newBuilder()
          .expireAfterAccess(1, TimeUnit.MINUTES)
          .removalListener(listener)
          .ticker(ticker)
          .build();
  cache.put(1, 1);
  ticker.advance(10, TimeUnit.MINUTES);
  cache.invalidateAll();

  assertThat(listener.poll().getCause()).isEqualTo(RemovalCause.EXPIRED);
}
 
开发者ID:google,项目名称:guava,代码行数:17,代码来源:CacheExpirationTest.java

示例6: testRemovalListener_expired

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testRemovalListener_expired() {
  FakeTicker ticker = new FakeTicker();
  QueuingRemovalListener<Object, Object> listener = queuingRemovalListener();
  LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder()
      .concurrencyLevel(1)
      .expireAfterWrite(3, TimeUnit.NANOSECONDS)
      .ticker(ticker)
      .removalListener(listener));
  assertTrue(listener.isEmpty());

  Object one = new Object();
  Object two = new Object();
  Object three = new Object();
  Object four = new Object();
  Object five = new Object();

  map.put(one, two);
  ticker.advance(1);
  map.put(two, three);
  ticker.advance(1);
  map.put(three, four);
  assertTrue(listener.isEmpty());
  ticker.advance(1);
  map.put(four, five);
  assertNotified(listener, one, two, RemovalCause.EXPIRED);

  assertTrue(listener.isEmpty());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:29,代码来源:LocalCacheTest.java

示例7: testExpireAfterWrite

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testExpireAfterWrite() {
  FakeTicker ticker = new FakeTicker();
  LocalCache<Object, Object> map = makeLocalCache(createCacheBuilder()
      .concurrencyLevel(1)
      .ticker(ticker)
      .expireAfterWrite(2, TimeUnit.NANOSECONDS));
  Segment<Object, Object> segment = map.segments[0];

  Object key = new Object();
  Object value = new Object();
  map.put(key, value);
  ReferenceEntry<Object, Object> entry = map.getEntry(key);
  assertTrue(map.isLive(entry, ticker.read()));

  segment.writeQueue.add(entry);
  assertSame(value, map.get(key));
  assertSame(entry, segment.writeQueue.peek());
  assertEquals(1, segment.writeQueue.size());

  segment.recordRead(entry, ticker.read());
  segment.expireEntries(ticker.read());
  assertSame(value, map.get(key));
  assertSame(entry, segment.writeQueue.peek());
  assertEquals(1, segment.writeQueue.size());

  ticker.advance(1);
  segment.recordRead(entry, ticker.read());
  segment.expireEntries(ticker.read());
  assertSame(value, map.get(key));
  assertSame(entry, segment.writeQueue.peek());
  assertEquals(1, segment.writeQueue.size());

  ticker.advance(1);
  assertNull(map.get(key));
  segment.expireEntries(ticker.read());
  assertNull(map.get(key));
  assertTrue(segment.writeQueue.isEmpty());
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:39,代码来源:LocalCacheTest.java

示例8: testExpiration_expireAfterWrite

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testExpiration_expireAfterWrite() {
  FakeTicker ticker = new FakeTicker();
  CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
  WatchedCreatorLoader loader = new WatchedCreatorLoader();
  LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
      .expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
      .removalListener(removalListener)
      .ticker(ticker)
      .build(loader);
  checkExpiration(cache, loader, ticker, removalListener);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java

示例9: testExpiration_expireAfterAccess

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testExpiration_expireAfterAccess() {
  FakeTicker ticker = new FakeTicker();
  CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
  WatchedCreatorLoader loader = new WatchedCreatorLoader();
  LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
      .expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
      .removalListener(removalListener)
      .ticker(ticker)
      .build(loader);
  checkExpiration(cache, loader, ticker, removalListener);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java

示例10: testExpiringGet_expireAfterWrite

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testExpiringGet_expireAfterWrite() {
  FakeTicker ticker = new FakeTicker();
  CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
  WatchedCreatorLoader loader = new WatchedCreatorLoader();
  LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
      .expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
      .removalListener(removalListener)
      .ticker(ticker)
      .build(loader);
  runExpirationTest(cache, loader, ticker, removalListener);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java

示例11: testExpiringGet_expireAfterAccess

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testExpiringGet_expireAfterAccess() {
  FakeTicker ticker = new FakeTicker();
  CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
  WatchedCreatorLoader loader = new WatchedCreatorLoader();
  LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
      .expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
      .removalListener(removalListener)
      .ticker(ticker)
      .build(loader);
  runExpirationTest(cache, loader, ticker, removalListener);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java

示例12: testRemovalListener_expireAfterWrite

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testRemovalListener_expireAfterWrite() {
  FakeTicker ticker = new FakeTicker();
  final AtomicInteger evictionCount = new AtomicInteger();
  final AtomicInteger applyCount = new AtomicInteger();
  final AtomicInteger totalSum = new AtomicInteger();

  RemovalListener<Integer, AtomicInteger> removalListener =
      new RemovalListener<Integer, AtomicInteger>() {
        @Override
        public void onRemoval(RemovalNotification<Integer, AtomicInteger> notification) {
          if (notification.wasEvicted()) {
            evictionCount.incrementAndGet();
            totalSum.addAndGet(notification.getValue().get());
          }
        }
      };

  CacheLoader<Integer, AtomicInteger> loader = new CacheLoader<Integer, AtomicInteger>() {
    @Override public AtomicInteger load(Integer key) {
      applyCount.incrementAndGet();
      return new AtomicInteger();
    }
  };

  LoadingCache<Integer, AtomicInteger> cache = CacheBuilder.newBuilder()
      .removalListener(removalListener)
      .expireAfterWrite(10, MILLISECONDS)
      .ticker(ticker)
      .build(loader);

  // Increment 100 times
  for (int i = 0; i < 100; ++i) {
    cache.getUnchecked(10).incrementAndGet();
    ticker.advance(1, MILLISECONDS);
  }

  assertEquals(evictionCount.get() + 1, applyCount.get());
  int remaining = cache.getUnchecked(10).get();
  assertEquals(100, totalSum.get() + remaining);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:41,代码来源:CacheExpirationTest.java

示例13: testRemovalScheduler_expireAfterWrite

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testRemovalScheduler_expireAfterWrite() {
  FakeTicker ticker = new FakeTicker();
  CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
  WatchedCreatorLoader loader = new WatchedCreatorLoader();
  LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
      .expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
      .removalListener(removalListener)
      .ticker(ticker)
      .build(loader);
  runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java

示例14: testRemovalScheduler_expireAfterAccess

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testRemovalScheduler_expireAfterAccess() {
  FakeTicker ticker = new FakeTicker();
  CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
  WatchedCreatorLoader loader = new WatchedCreatorLoader();
  LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
      .expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
      .removalListener(removalListener)
      .ticker(ticker)
      .build(loader);
  runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:12,代码来源:CacheExpirationTest.java

示例15: testRemovalScheduler_expireAfterBoth

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
public void testRemovalScheduler_expireAfterBoth() {
  FakeTicker ticker = new FakeTicker();
  CountingRemovalListener<String, Integer> removalListener = countingRemovalListener();
  WatchedCreatorLoader loader = new WatchedCreatorLoader();
  LoadingCache<String, Integer> cache = CacheBuilder.newBuilder()
      .expireAfterAccess(EXPIRING_TIME, MILLISECONDS)
      .expireAfterWrite(EXPIRING_TIME, MILLISECONDS)
      .removalListener(removalListener)
      .ticker(ticker)
      .build(loader);
  runRemovalScheduler(cache, removalListener, loader, ticker, KEY_PREFIX, EXPIRING_TIME);
}
 
开发者ID:zugzug90,项目名称:guava-mock,代码行数:13,代码来源:CacheExpirationTest.java


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