本文整理汇总了Java中com.jayway.awaitility.Awaitility类的典型用法代码示例。如果您正苦于以下问题:Java Awaitility类的具体用法?Java Awaitility怎么用?Java Awaitility使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Awaitility类属于com.jayway.awaitility包,在下文中一共展示了Awaitility类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: willGetNothingIfTheReaderFails
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
@Test
public void willGetNothingIfTheReaderFails() {
when(datasetDao.exists(dataset.getId())).thenReturn(true);
Subscriber subscriber = new Subscriber(dataset.getId());
when(reader.read(dataset, select, asOf.applyAsOf(where), "", -1))
.thenReturn(Observable.error(new RuntimeException("boom!")));
long subscriptionInterval = 50L;
subscriptionManager.start(
dataset, Optional.of(subscriptionInterval), LocalDateTime.now(), select, where);
// have to wait for the async call to came through ...
Awaitility.await()
.atMost((subscriptionInterval + 1000), TimeUnit.MILLISECONDS)
.until(subscriber::isFailed);
assertThat(subscriber.getPayloads().isEmpty(), is(true));
}
示例2: testTopicState
import com.jayway.awaitility.Awaitility; //导入依赖的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();
}
示例3: checkCreatedListener
import com.jayway.awaitility.Awaitility; //导入依赖的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);
}
示例4: checkExpiredListener
import com.jayway.awaitility.Awaitility; //导入依赖的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);
}
示例5: checkUpdatedListener
import com.jayway.awaitility.Awaitility; //导入依赖的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);
}
示例6: checkRemovedListener
import com.jayway.awaitility.Awaitility; //导入依赖的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);
}
示例7: testStopThreads
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
@Test
public void testStopThreads() {
SystemFailure.signalCacheCreate();
SystemFailure.startThreads();
long start = System.nanoTime();
Thread watchDog = SystemFailure.getWatchDogForTest();
Thread proctor = SystemFailure.getProctorForTest();
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> watchDog.isAlive());
Awaitility.await().atMost(30, TimeUnit.SECONDS).until(() -> proctor.isAlive());
SystemFailure.stopThreads();
long elapsed = System.nanoTime() - start;
assertTrue("Waited too long to shutdown: " + elapsed,
elapsed < TimeUnit.MILLISECONDS.toNanos(LONG_WAIT));
assertFalse(watchDog.isAlive());
assertFalse(proctor.isAlive());
}
示例8: testRepeatedExecution
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
@Test
public void testRepeatedExecution() throws InterruptedException {
ex = new ScheduledThreadPoolExecutorWithKeepAlive(50, 1, TimeUnit.SECONDS,
Executors.defaultThreadFactory());
final AtomicInteger counter = new AtomicInteger();
Runnable run = new Runnable() {
public void run() {
counter.incrementAndGet();
}
};
ScheduledFuture f = ex.scheduleAtFixedRate(run, 0, 1, TimeUnit.SECONDS);
Awaitility.await().atMost(30, TimeUnit.SECONDS)
.until(() -> assertEquals("Task was not executed repeatedly", true, counter.get() > 1));
Awaitility.await().atMost(30, TimeUnit.SECONDS)
.until(() -> assertEquals("The task could not be cancelled", true, f.cancel(true)));
Awaitility.await().atMost(30, TimeUnit.SECONDS)
.until(() -> assertEquals("Task was not cancelled within 30 sec", true, f.isCancelled()));
int oldValue = counter.get();
Thread.sleep(5000);
assertEquals("Task was not cancelled", oldValue, counter.get());
}
示例9: testBlockingPutAndTake
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
/**
* Tests the effect of a put which is blocked because of capacity constraint & subsequent passage
* because of take operation
*
*/
@Test
public void testBlockingPutAndTake()
throws InterruptedException, IOException, ClassNotFoundException {
HARegionQueueAttributes hrqa = new HARegionQueueAttributes();
hrqa.setBlockingQueueCapacity(1);
final HARegionQueue hrq = this.createHARegionQueue("testBlockingPutAndTake", hrqa);
hrq.setPrimary(true);// fix for 40314 - capacity constraint is checked for primary only.
EventID id1 = new EventID(new byte[] {1}, 1, 1);
hrq.put(new ConflatableObject("key1", "val1", id1, false, "testing"));
Thread t1 = new Thread(new Runnable() {
public void run() {
try {
EventID id2 = new EventID(new byte[] {1}, 1, 2);
hrq.put(new ConflatableObject("key1", "val2", id2, false, "testing"));
} catch (Exception e) {
encounteredException = true;
}
}
});
t1.start();
Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> t1.isAlive());
Conflatable conf = (Conflatable) hrq.take();
assertNotNull(conf);
Awaitility.await().atMost(1, TimeUnit.MINUTES).until(() -> !t1.isAlive());
}
示例10: testUpdationOfMessageSyncInterval
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
/**
* This tests whether the messageSyncInterval for QueueRemovalThread is refreshed properly when
* set/updated using cache's setter API
*/
@Test
public void testUpdationOfMessageSyncInterval() throws Exception {
int initialMessageSyncInterval = 5;
cache.setMessageSyncInterval(initialMessageSyncInterval);
createHARegionQueue("testUpdationOfMessageSyncInterval");
assertEquals("messageSyncInterval not set properly", initialMessageSyncInterval,
HARegionQueue.getMessageSyncInterval());
int updatedMessageSyncInterval = 10;
cache.setMessageSyncInterval(updatedMessageSyncInterval);
Awaitility.await().atMost(1, TimeUnit.MINUTES)
.until(() -> assertEquals("messageSyncInterval not updated.", updatedMessageSyncInterval,
HARegionQueue.getMessageSyncInterval()));
}
示例11: ackedEventsShouldBeRemovedFromTheQueueEventuallyEvenIfNoNewMessagesAreSent
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
@Test
public void ackedEventsShouldBeRemovedFromTheQueueEventuallyEvenIfNoNewMessagesAreSent()
throws Exception {
int num = 10;
CacheListener slowListener = new SlowListener();
vm1.invoke(() -> DurableClientQueueSizeDUnitTest.closeCache());
vm2.invoke(DurableClientQueueSizeDUnitTest.class, "createClientCache",
new Object[] {vm2.getHost(), new Integer[] {port0, port1}, "300", Boolean.TRUE,
Boolean.FALSE, slowListener});
vm2.invoke(() -> DurableClientQueueSizeDUnitTest.doRI());
vm2.invoke(() -> DurableClientQueueSizeDUnitTest.readyForEvents());
vm0.invoke(() -> DurableClientQueueSizeDUnitTest.doPutsIntoRegion(REGION_NAME, num));
vm0.invoke(() -> Awaitility.waitAtMost(45, TimeUnit.SECONDS).until(() -> {
CacheClientProxy ccp = DurableClientQueueSizeDUnitTest.getCacheClientProxy(MY_DURABLE_CLIENT);
assertEquals(0, ccp.getQueueSize());
assertEquals(0, ccp.getQueueSizeStat());
}));
}
示例12: validate
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
public void validate(int creates, int updates, int invalidates, int destroys) {
// Wait for the last destroy event to arrive.
try {
Awaitility.await().atMost(5, TimeUnit.SECONDS).until(() -> {
return (destroys == m_destroys);
});
} catch (Exception ex) {
// The event is not received in a given wait time.
// The check will be done below to report the valid reason.
}
GemFireCacheImpl.getInstance().getLogger()
.info(m_name + ": creates: expected=" + creates + ", actual=" + m_creates);
GemFireCacheImpl.getInstance().getLogger()
.info(m_name + ": updates: expected=" + updates + ", actual=" + m_updates);
GemFireCacheImpl.getInstance().getLogger()
.info(m_name + ": invalidates: expected=" + invalidates + ", actual=" + m_invalidates);
GemFireCacheImpl.getInstance().getLogger()
.info(m_name + ": destroys: expected=" + destroys + ", actual=" + m_destroys);
assertEquals("Creates :", creates, m_creates);
assertEquals("Updates :", updates, m_updates);
assertEquals("Invalidates :", invalidates, m_invalidates);
assertEquals("Destroys :", destroys, m_destroys);
}
示例13: test_MetadataServiceCallAccuracy_FromDestroyOp
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
@Test
public void test_MetadataServiceCallAccuracy_FromDestroyOp() {
Integer port0 =
(Integer) member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(0, 4));
Integer port1 =
(Integer) member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(0, 4));
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.createClient(port0));
createClient(port1);
member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.putIntoSinglePR());
member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.printView());
member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.printView());
final ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
cms.satisfyRefreshMetadata_TEST_ONLY(false);
region.destroy(new Integer(0));
region.destroy(new Integer(1));
region.destroy(new Integer(2));
region.destroy(new Integer(3));
Awaitility.waitAtMost(60, TimeUnit.SECONDS)
.until(() -> cms.isRefreshMetadataTestOnly() == true);
}
示例14: testMetadataFetchOnlyThroughputAll
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
@Test
public void testMetadataFetchOnlyThroughputAll() {
Integer port0 =
(Integer) member0.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
Integer port1 =
(Integer) member1.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
Integer port2 =
(Integer) member2.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
Integer port3 =
(Integer) member3.invoke(() -> PartitionedRegionSingleHopDUnitTest.createServer(3, 4));
createClient(port0, port1, port2, port3);
putAll();
ClientMetadataService cms = ((GemFireCacheImpl) cache).getClientMetadataService();
final Map<String, ClientPartitionAdvisor> regionMetaData = cms.getClientPRMetadata_TEST_ONLY();
Awaitility.waitAtMost(60, TimeUnit.SECONDS).until(() -> (regionMetaData.size() == 1));
assertTrue(regionMetaData.containsKey(region.getFullPath()));
final ClientPartitionAdvisor prMetaData = regionMetaData.get(region.getFullPath());
Awaitility.waitAtMost(60, TimeUnit.SECONDS)
.until(() -> (prMetaData.getBucketServerLocationsMap_TEST_ONLY().size() == 4));
}
示例15: evictionDestroyOpEventsNotPropogatedByDefault
import com.jayway.awaitility.Awaitility; //导入依赖的package包/类
@Test
public void evictionDestroyOpEventsNotPropogatedByDefault() {
// For Replicated Region with eviction-destroy op.
// Number of expected events 2. Two for create and none for eviction destroy.
createRegionAeqAndPopulate(false /* isPR */, false /* forwardExpirationDestroy */,
true /* eviction */, false /* evictionOverflow */, false /* expirationDestroy */,
false /* expirationInvalidate */);
// Wait for region to evict/expire events.
Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> assertEquals(1, region.size()));
// Validate events that are not queued.
// This guarantees that eviction/expiration is performed and events are
// sent all the way to Gateway.
Awaitility.await().atMost(60, TimeUnit.SECONDS)
.until(() -> assertEquals(1, getEventsNotQueuedSize(aeqId)));
// The AQListner should get expected events.
Awaitility.await().atMost(60, TimeUnit.SECONDS).until(() -> assertEquals(2, events.size()));
}