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


Java Duration类代码示例

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


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

示例1: testTopicState

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@Test
public void testTopicState() throws InterruptedException {
    RedissonClient redisson = BaseTest.createInstance();
    
    RTopic<String> stringTopic = redisson.getTopic("test1", StringCodec.INSTANCE);
    for (int i = 0; i < 3; i++) {
        AtomicBoolean stringMessageReceived = new AtomicBoolean();
        int listenerId = stringTopic.addListener(new MessageListener<String>() {
            @Override
            public void onMessage(String channel, String msg) {
                assertThat(msg).isEqualTo("testmsg");
                stringMessageReceived.set(true);
            }
        });
        stringTopic.publish("testmsg");
        
        Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(stringMessageReceived);
        
        stringTopic.removeListener(listenerId);
    }
    
    redisson.shutdown();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:24,代码来源:RedissonTopicTest.java

示例2: checkCreatedListener

import com.jayway.awaitility.Duration; //导入依赖的package包/类
private void checkCreatedListener(RMapCache<Integer, Integer> map, Integer key, Integer value, Runnable runnable) {
    AtomicBoolean ref = new AtomicBoolean();
    int createListener1 = map.addListener(new EntryCreatedListener<Integer, Integer>() {

        @Override
        public void onCreated(EntryEvent<Integer, Integer> event) {
            assertThat(event.getKey()).isEqualTo(key);
            assertThat(event.getValue()).isEqualTo(value);
            
            if (!ref.compareAndSet(false, true)) {
                Assert.fail();
            }
        }
        
    });
    runnable.run();

    Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(ref);
    map.removeListener(createListener1);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:RedissonMapCacheTest.java

示例3: checkExpiredListener

import com.jayway.awaitility.Duration; //导入依赖的package包/类
private void checkExpiredListener(RMapCache<Integer, Integer> map, Integer key, Integer value, Runnable runnable) {
    AtomicBoolean ref = new AtomicBoolean();
    int createListener1 = map.addListener(new EntryExpiredListener<Integer, Integer>() {

        @Override
        public void onExpired(EntryEvent<Integer, Integer> event) {
            assertThat(event.getKey()).isEqualTo(key);
            assertThat(event.getValue()).isEqualTo(value);
            
            if (!ref.compareAndSet(false, true)) {
                Assert.fail();
            }
        }
        
    });
    runnable.run();

    Awaitility.await().atMost(Duration.ONE_MINUTE).untilTrue(ref);
    map.removeListener(createListener1);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:RedissonMapCacheTest.java

示例4: checkUpdatedListener

import com.jayway.awaitility.Duration; //导入依赖的package包/类
private void checkUpdatedListener(RMapCache<Integer, Integer> map, Integer key, Integer value, Integer oldValue, Runnable runnable) {
    AtomicBoolean ref = new AtomicBoolean();
    int createListener1 = map.addListener(new EntryUpdatedListener<Integer, Integer>() {

        @Override
        public void onUpdated(EntryEvent<Integer, Integer> event) {
            assertThat(event.getKey()).isEqualTo(key);
            assertThat(event.getValue()).isEqualTo(value);
            assertThat(event.getOldValue()).isEqualTo(oldValue);
            
            if (!ref.compareAndSet(false, true)) {
                Assert.fail();
            }
        }
        
    });
    runnable.run();

    Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(ref);
    map.removeListener(createListener1);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:22,代码来源:RedissonMapCacheTest.java

示例5: checkRemovedListener

import com.jayway.awaitility.Duration; //导入依赖的package包/类
private void checkRemovedListener(RMapCache<Integer, Integer> map, Integer key, Integer value, Runnable runnable) {
    AtomicBoolean ref = new AtomicBoolean();
    int createListener1 = map.addListener(new EntryRemovedListener<Integer, Integer>() {

        @Override
        public void onRemoved(EntryEvent<Integer, Integer> event) {
            assertThat(event.getKey()).isEqualTo(key);
            assertThat(event.getValue()).isEqualTo(value);
            
            if (!ref.compareAndSet(false, true)) {
                Assert.fail();
            }
        }
        
    });
    runnable.run();

    Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(ref);
    map.removeListener(createListener1);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:21,代码来源:RedissonMapCacheTest.java

示例6: objectExists

import com.jayway.awaitility.Duration; //导入依赖的package包/类
private void objectExists(final ObjectType type, final String key, final String source, final boolean exists) {
    Awaitility.waitAtMost(Duration.FOREVER).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            try {
                sourceContext.setCurrent(Source.master(source));
                databaseHelper.lookupObject(type, key);
                return Boolean.TRUE;
            } catch (EmptyResultDataAccessException e) {
                return Boolean.FALSE;
            } finally {
                sourceContext.removeCurrentSource();
            }
        }
    }, is(exists));
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:17,代码来源:NrtmClientMultipleSourcesTestIntegration.java

示例7: objectExists

import com.jayway.awaitility.Duration; //导入依赖的package包/类
protected void objectExists(final ObjectType type, final String key, final boolean exists) {
    Awaitility.waitAtMost(Duration.FIVE_SECONDS).until(new Callable<Boolean>() {
        @Override
        public Boolean call() throws Exception {
            try {
                sourceContext.setCurrent(Source.master("1-GRS"));
                databaseHelper.lookupObject(type, key);
                return Boolean.TRUE;
            } catch (EmptyResultDataAccessException e) {
                return Boolean.FALSE;
            } finally {
                sourceContext.removeCurrentSource();
            }
        }
    }, is(exists));
}
 
开发者ID:RIPE-NCC,项目名称:whois,代码行数:17,代码来源:AbstractNrtmIntegrationBase.java

示例8: testCommandsOrdering

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@Test
public void testCommandsOrdering() throws InterruptedException {
    RedissonClient redisson1 = BaseTest.createInstance();
    RTopic<Long> topic1 = redisson1.getTopic("topic", LongCodec.INSTANCE);
    AtomicBoolean stringMessageReceived = new AtomicBoolean();
    topic1.addListener((channel, msg) -> {
        assertThat(msg).isEqualTo(123);
        stringMessageReceived.set(true);
    });
    topic1.publish(123L);

    Awaitility.await().atMost(Duration.ONE_SECOND).untilTrue(stringMessageReceived);

    redisson1.shutdown();
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:16,代码来源:RedissonTopicTest.java

示例9: testBatchExecute

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@Test
public void testBatchExecute() {
    RExecutorService e = redisson.getExecutorService("test");
    e.execute(new IncrementRunnableTask("myCounter"), new IncrementRunnableTask("myCounter"), 
                new IncrementRunnableTask("myCounter"), new IncrementRunnableTask("myCounter"));
    
    Awaitility.await().atMost(Duration.FIVE_SECONDS).until(() -> redisson.getAtomicLong("myCounter").get() == 4);
}
 
开发者ID:qq1588518,项目名称:JRediClients,代码行数:9,代码来源:RedissonExecutorServiceTest.java

示例10: setup

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@Before
public void setup() throws Exception {
    MailetContainer mailetContainer = MailetContainer.builder()
        .postmaster("[email protected]" + DEFAULT_DOMAIN)
        .threads(5)
        .addProcessor(CommonProcessors.root())
        .addProcessor(CommonProcessors.error())
        .addProcessor(transportProcessorWithGuessClassificationMailet())
        .addProcessor(CommonProcessors.spam())
        .addProcessor(CommonProcessors.localAddressError())
        .addProcessor(CommonProcessors.relayDenied())
        .addProcessor(CommonProcessors.bounces())
        .addProcessor(CommonProcessors.sieveManagerCheck())
        .build();

    jamesServer = new TemporaryJamesServer(temporaryFolder, mailetContainer,
        new JMXServerModule(),
        binder -> binder.bind(ListeningMessageSearchIndex.class).toInstance(mock(ListeningMessageSearchIndex.class)));
    Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS;
    calmlyAwait = Awaitility.with()
        .pollInterval(slowPacedPollInterval)
        .and()
        .with()
        .pollDelay(slowPacedPollInterval)
        .await()
        .atMost(Duration.ONE_MINUTE);
}
 
开发者ID:linagora,项目名称:openpaas-mailets,代码行数:28,代码来源:ClassificationIntegrationTest.java

示例11: subscribeWithErrorShouldTriggerRetry

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test(timeout = 1000)
public void subscribeWithErrorShouldTriggerRetry() throws Exception {
  
  List<Service> singleService = Arrays.asList(SERVICE1);
  ServiceGroup singleServiceGroup = new ServiceGroup(singleService, Optional.empty());
  
  ConsulClient consulClient = mock(ConsulClient.class);
  when(consulClient.discoverService(any(ServiceRequest.class)))
    .thenThrow(UnknownHostException.class)
    .thenThrow(UnknownHostException.class)
    .thenThrow(UnknownHostException.class)
    .thenReturn(Optional.of(singleServiceGroup))
    .thenThrow(IOException.class)
    .thenThrow(IOException.class)
    .thenReturn(Optional.of(singleServiceGroup));
    
  int[] expectedRetry = {1, 2, 3, 1 ,2};
  
  AtomicInteger callsCounter = new AtomicInteger(0);
  DiscoveryService discoveryService = new DiscoveryService(consulClient, 3, i -> {
    callsCounter.incrementAndGet();
    assertTrue("expected " + expectedRetry[i-1] + " got " + i, i == expectedRetry[i-1]);
    return i;
  }, TimeUnit.MILLISECONDS);
  
  Subscription subscribe = discoveryService.subscribe("pong", update -> {});

  await().pollInterval(new Duration(2, MILLISECONDS))
    .atMost(300, MILLISECONDS)
    .untilAtomic(callsCounter, equalTo(5));
  
  subscribe.unsubscribe();
}
 
开发者ID:totango,项目名称:discovery-agent,代码行数:35,代码来源:DiscoveryServiceTest.java

示例12: startRestfulSchedulerWebapp

import com.jayway.awaitility.Duration; //导入依赖的package包/类
public static void startRestfulSchedulerWebapp(int nbNodes) throws Exception {
    // Kill all children processes on exit
    org.apache.log4j.BasicConfigurator.configure(new org.apache.log4j.varia.NullAppender());
    CookieBasedProcessTreeKiller.registerKillChildProcessesOnShutdown("rest_tests");

    List<String> cmd = new ArrayList<>();
    String javaPath = RestFuncTUtils.getJavaPathFromSystemProperties();
    cmd.add(javaPath);
    cmd.add("-Djava.security.manager");
    cmd.add(CentralPAPropertyRepository.JAVA_SECURITY_POLICY.getCmdLine() + toPath(serverJavaPolicy));

    cmd.add(CentralPAPropertyRepository.PA_HOME.getCmdLine() + getSchedHome());
    cmd.add(PASchedulerProperties.SCHEDULER_HOME.getCmdLine() + getSchedHome());
    cmd.add(PAResourceManagerProperties.RM_HOME.getCmdLine() + getRmHome());

    cmd.add(PAResourceManagerProperties.RM_DB_HIBERNATE_DROPDB.getCmdLine() +
            System.getProperty("rm.deploy.dropDB", "true"));
    cmd.add(PAResourceManagerProperties.RM_DB_HIBERNATE_CONFIG.getCmdLine() + toPath(rmHibernateConfig));

    cmd.add(PASchedulerProperties.SCHEDULER_DB_HIBERNATE_DROPDB.getCmdLine() +
            System.getProperty("scheduler.deploy.dropDB", "true"));
    cmd.add(PASchedulerProperties.SCHEDULER_DB_HIBERNATE_CONFIG.getCmdLine() + toPath(schedHibernateConfig));

    cmd.add(CentralPAPropertyRepository.PA_COMMUNICATION_PROTOCOL.getCmdLine() + "pnp");
    cmd.add(PNPConfig.PA_PNP_PORT.getCmdLine() + "1200");

    cmd.add("-cp");
    cmd.add(getClassPath());
    cmd.add(SchedulerStarter.class.getName());
    cmd.add("-ln");
    cmd.add("" + nbNodes);

    ProcessBuilder processBuilder = new ProcessBuilder(cmd);
    processBuilder.redirectErrorStream(true);
    schedProcess = processBuilder.start();

    ProcessStreamReader out = new ProcessStreamReader("scheduler-output: ", schedProcess.getInputStream());
    out.start();

    // RM and scheduler are on the same url
    String port = "1200";
    String url = "pnp://localhost:" + port + "/";

    // Connect a scheduler client
    SchedulerAuthenticationInterface schedAuth = SchedulerConnection.waitAndJoin(url,
                                                                                 TimeUnit.SECONDS.toMillis(120));
    schedulerPublicKey = schedAuth.getPublicKey();
    Credentials schedCred = RestFuncTUtils.createCredentials("admin", "admin", schedulerPublicKey);
    scheduler = schedAuth.login(schedCred);

    // Connect a rm client
    RMAuthentication rmAuth = RMConnection.waitAndJoin(url, TimeUnit.SECONDS.toMillis(120));
    Credentials rmCredentials = getRmCredentials();
    rm = rmAuth.login(rmCredentials);

    restServerUrl = "http://localhost:8080/rest/";
    restfulSchedulerUrl = restServerUrl + "scheduler";

    await().atMost(Duration.FIVE_MINUTES).until(restIsStarted());
}
 
开发者ID:ow2-proactive,项目名称:scheduling,代码行数:61,代码来源:RestFuncTHelper.java

示例13: matches

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@Override
@SuppressWarnings("unchecked")
public boolean matches(Object item) {
    MockLockCallback callback = (MockLockCallback) item;
    try {
        waitAtMost(Duration.ONE_SECOND).await().until(callback.authentication(), authenticationMatcher);
        waitAtMost(Duration.ONE_SECOND).await().until(callback.canceled(), canceledMatcher);
        waitAtMost(Duration.ONE_SECOND).await().until(callback.error(), errorMatcher);
        return true;
    } catch (ConditionTimeoutException e) {
        return false;
    }
}
 
开发者ID:auth0,项目名称:Lock.Android,代码行数:14,代码来源:AuthenticationCallbackMatcher.java

示例14: beforeTest

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@BeforeMethod
public void beforeTest() {
    Awaitility.await().atMost(Duration.TEN_SECONDS).until(() -> {
                System.out.println("Acquired connections " + client.acquiredConnections());
                assertThat(client.acquiredConnections()).isEqualTo(0);
            }
    );
}
 
开发者ID:codewise,项目名称:RxS3,代码行数:9,代码来源:AsyncS3ClientTest.java

示例15: afterTest

import com.jayway.awaitility.Duration; //导入依赖的package包/类
@AfterMethod
public void afterTest() {
    Awaitility.await().atMost(Duration.TEN_SECONDS).until(() -> {
                System.out.println("Acquired connections " + client.acquiredConnections());
                assertThat(client.acquiredConnections()).isEqualTo(0);
            }
    );
}
 
开发者ID:codewise,项目名称:RxS3,代码行数:9,代码来源:AsyncS3ClientTest.java


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