Package com.google.common.base

Examples of com.google.common.base.Ticker


                });
    }

    @Test
    public void willMakeUpTheRefillWhenTimePassed() throws InterruptedException {
        Ticker ticker = mock(Ticker.class);
        LeakyBucket bucket =
                new LeakyBucket(2, refillDuration, refillTimeUnit,
                        new LeakyBucket.TimeTracker(ticker));

        assertThat(bucket.tryAcquire(), Matchers.is(true));
        assertThat(bucket.tryAcquire(), Matchers.is(true));
        assertThat(bucket.tryAcquire(), Matchers.is(false));

        // after twice of refill duration it should've filled up.
        when(ticker.read()).thenReturn(timeOverRefillDuration * 2);

        assertThat(bucket.tryAcquire(), Matchers.is(true));
        assertThat(bucket.tryAcquire(), Matchers.is(true));
    }
View Full Code Here


          final Clock clock) {
        requireNonNull(duration);
        requireNonNull(clock);
        this.reservations = CacheBuilder.newBuilder()
            .expireAfterWrite(duration.as(Time.MINUTES), TimeUnit.MINUTES)
            .ticker(new Ticker() {
              @Override
              public long read() {
                return clock.nowNanos();
              }
            })
View Full Code Here

TOP

Related Classes of com.google.common.base.Ticker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.