Search in sources :

Example 1 with NanoClock

use of org.activityinfo.legacy.shared.util.NanoClock in project activityinfo by bedatadriven.

the class RemoteDispatcherTest method setUp.

@Before
public void setUp() {
    service = createMock("remoteService", RemoteCommandServiceAsync.class);
    proxy = createMock("proxy", CommandCache.class);
    AuthenticatedUser auth = new AuthenticatedUser(AUTH_TOKEN, 1, "alex@alex.com");
    BackOff backOff = new ExponentialBackOff.Builder().setInitialIntervalMillis(MergingDispatcher.ADVISORY_GET_LOCK_TIMEOUT).setMultiplier(// increase in 2 times
    2).setNanoClock(new NanoClock() {

        @Override
        public long nanoTime() {
            return System.nanoTime();
        }
    }).build();
    dispatcher = new CachingDispatcher(proxyManager, new MergingDispatcher(new RemoteDispatcher(auth, service, "en"), scheduler, backOff));
}
Also used : RemoteCommandServiceAsync(org.activityinfo.legacy.shared.command.RemoteCommandServiceAsync) CommandCache(org.activityinfo.ui.client.dispatch.CommandCache) CachingDispatcher(org.activityinfo.ui.client.dispatch.remote.cache.CachingDispatcher) NanoClock(org.activityinfo.legacy.shared.util.NanoClock) AuthenticatedUser(org.activityinfo.legacy.shared.AuthenticatedUser) BackOff(org.activityinfo.legacy.shared.util.BackOff) ExponentialBackOff(org.activityinfo.legacy.shared.util.ExponentialBackOff) Before(org.junit.Before)

Example 2 with NanoClock

use of org.activityinfo.legacy.shared.util.NanoClock in project activityinfo by bedatadriven.

the class ExponentialBackOffTest method test.

@Test
public void test() throws IOException {
    NanoClock nanoClock = new NanoClock() {

        @Override
        public long nanoTime() {
            return System.nanoTime();
        }
    };
    ExponentialBackOff defaultBackOff = new ExponentialBackOff.Builder().setNanoClock(nanoClock).build();
    ExponentialBackOff backOff = new ExponentialBackOff.Builder().setInitialIntervalMillis(TimeUnit.SECONDS.toMillis(10)).setMultiplier(// increase in 3 times
    2).setNanoClock(nanoClock).build();
    for (int i = 0; i < 10; i++) {
        System.out.println(defaultBackOff.nextBackOffMillis() + " " + backOff.nextBackOffMillis());
    }
}
Also used : NanoClock(org.activityinfo.legacy.shared.util.NanoClock) ExponentialBackOff(org.activityinfo.legacy.shared.util.ExponentialBackOff) Test(org.junit.Test)

Aggregations

ExponentialBackOff (org.activityinfo.legacy.shared.util.ExponentialBackOff)2 NanoClock (org.activityinfo.legacy.shared.util.NanoClock)2 AuthenticatedUser (org.activityinfo.legacy.shared.AuthenticatedUser)1 RemoteCommandServiceAsync (org.activityinfo.legacy.shared.command.RemoteCommandServiceAsync)1 BackOff (org.activityinfo.legacy.shared.util.BackOff)1 CommandCache (org.activityinfo.ui.client.dispatch.CommandCache)1 CachingDispatcher (org.activityinfo.ui.client.dispatch.remote.cache.CachingDispatcher)1 Before (org.junit.Before)1 Test (org.junit.Test)1