本文整理汇总了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();
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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));
}
示例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));
}
示例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();
}
示例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);
}
示例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);
}
示例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();
}
示例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());
}
示例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;
}
}
示例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);
}
);
}
示例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);
}
);
}