• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java FakeTicker类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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:zugzug90,项目名称:guava-mock,代码行数:16,代码来源:CacheExpirationTest.java


示例17: testSetForwarder

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
@Test
public void testSetForwarder() throws Exception {
    final FakeTicker ticker = new FakeTicker();
    ticker.setAutoIncrementStep(1, TimeUnit.MICROSECONDS);
    final Request<?, ?> request = new TransactionPurgeRequest(TRANSACTION_IDENTIFIER, 0L, probe.ref());
    final Consumer<Response<?, ?>> callback = createConsumerMock();
    final ConnectionEntry entry = new ConnectionEntry(request, callback, ticker.read());
    final ReconnectForwarder forwarder = mock(ReconnectForwarder.class);
    queue.setForwarder(forwarder, ticker.read());
    final long secondEnqueueNow = ticker.read();
    queue.enqueueOrForward(entry, secondEnqueueNow);
    verify(forwarder).forwardEntry(entry, secondEnqueueNow);
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:14,代码来源:TransmittingTransmitQueueTest.java


示例18: 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());

    mockActor = TestProbe.apply(actorSystem);
    mockRequest = new MockRequest(mockIdentifier, mockReplyTo);
    mockResponse = mockRequest.toRequestFailure(mockCause);

    entry = new ConnectionEntry(mockRequest, mockCallback, ticker.read());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:16,代码来源:ConnectionEntryTest.java


示例19: setUp

import com.google.common.testing.FakeTicker; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
  ticker = new FakeTicker().setAutoIncrementStep(1, TimeUnit.NANOSECONDS);
  profiler = new Profiler(ticker);
  recordingCallback = new RecordingListener();
  // We don't record anything  before start
  try (ProfilerTask ignore = profiler.start("bar")) {
    profiler.simpleTask("foo", 10, 20);
  }
  assertThat(recordingCallback.events).isEmpty();
  profiler.init(ImmutableList.of(recordingCallback));

}
 
开发者ID:google,项目名称:copybara,代码行数:14,代码来源:ProfilerTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java TreeFactory类代码示例发布时间:2022-05-22
下一篇:
Java SyndFeedOutput类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap