I just released Awaitility 1.7.0 and one of the big new features is the ability to use non-fixed poll intervals. A poll interval tells Awaitility how often it should evaluate the condition that is supplied to the until
method. Previously you could only specify a poll interval at a fixed rate like this:
with().pollInterval(150, TimeUnit.MILLISECONDS).
await().until(() -> someConditionIsFulfilled());
This means that `someConditionIsFulfilled` is evaluated (approximately) every 150th millisecond. I many situations this is just fine but imagine that `someConditionIsFulfilled` could take a while, perhaps it involves a network call or invokes a (slow) database. So Awaitility now also ships with other kinds of poll intervals, the FibonacciPollInterval and IterativePollInterval that allows for various back-off strategies.
Fibonacci
The FibonacciPollInterval generates a non-linear poll interval based on the fibonacci sequence. This is useful if it’s likely that the condition completes fast but if not we should back-off gracefully. To use this poll interval we can do like this:
with().pollInterval(fibonacci()).await().until(..);
where `fibonacci` is statically imported from `com.jayway.awaitility.pollinterval.FibonacciPollInterval`. This will generate a poll interval of `1, 1, 2, 3, 5, 8, 13, ..` milliseconds. To change the time unit to use, for example to seconds instead of milliseconds you can do:
with().pollInterval(fibonacci(TimeUnit.SECONDS)).await().until(..);
Or a bit more english-like:
with().pollInterval(fibonacci().with().timeUnit(SECONDS)).await().until(..);
Iterative
This poll interval creates a sequence generated by a function and a start duration. The function is free to do anything it wants with the duration, for example multiplying it by 2:
await().with().pollInterval(iterative(duration -> duration.multiply(2)),
Duration.FIVE_HUNDRED_MILLISECONDS).until(..);
or a bit more english-like:
await().with().pollInterval(
iterative(duration -> duration.multiply(2)).with().startDuration(FIVE_HUNDRED_MILLISECONDS)
).until(..);
This generates a poll interval sequence that looks like this (ms): `500, 1000, 2000, 4000, 8000, 16000, …`
Custom
If fibonacci or iterative poll interval won’t do it for you it’s possible to roll your own implementation. We can do this by implementing the PollInterval interface that ships with Awaitility. This is a functional interface so in Java 8 we can for example do like this:
await().with().pollInterval((__, previous) -> previous.multiply(2).plus(1)).until(..);
In this example we create a `PollInterval` that is implemented as a (bi-) function that takes the previous poll interval duration and multiplies it by 2 and adds 1. `__` just signals that we don’t care about the poll count that is also provided by the `PollInterval` interface. Poll count is required when creating poll intervals that are not (only) interested in the previous duration but rather generates its duration based on the number of times it has been called. For example the `FibonacciPollInterval` uses only the poll count:
await().with().pollInterval((pollCount, __) -> new Duration(fib(pollCount), MILLISECONDS)).until(..);
With this approach you should be able to create all kinds of different poll interval sequences, for example sinus, parabolic and (true) exponential sequences if required.
Conclusion
Non-fixed poll intervals can be very useful in certain situations. Awaitility ships with some basic non-fixed poll intervals but it should be possible to create tailer made sequences that suits your unique use case if required.
22 thoughts on “Non-fixed poll intervals in Awaitility”
Very nicely done – thanks!
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
OvEvI1ysPyG
aTjuM4Ljpmh
L3i0idztTgl
92NmlKsawHN
Your point of view caught my eye and was very interesting. Thanks. I have a question for you.
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article.
Your article helped me a lot, is there any more related content? Thanks!
Non-fixed poll intervals in Awaitility – Coding all the things
nsdkphfwf http://www.gd37pl236z12soy6h86agwc4u2x616g8s.org/
[url=http://www.gd37pl236z12soy6h86agwc4u2x616g8s.org/]unsdkphfwf[/url]
ansdkphfwf
coffee robot
QS Погружной Насос
roody.jp
QS-HF1 Погружной Насос
coffee robot
cheap www onekick ru adidas Climacool Adifom lace-up sneakers
cheap onekick shop adidas Ultraboost CC 1 DNA sneakers
rep onekick reps adidas Centennial RM sneakers
QS-3 Погружной Насос
csgo case opening
Injection Molding
Injection Molding
rep onekick.ru reps adidas x Darryl Brown Campus 80 sneakers
QS-5E Погружной Насос
rep one kick shoes adidas x Human Made Solar Hu Glide sneakers
QS-4 Погружной Насос
Wireless Voice Control WIFI Smart Bulb Socket
retrolike.net
Portable USB Charging Touch Living Room Bedside Table Lamp
coffee robot machine
coffee robot machine
WIFI Bluetooth Voice Control Smart Light Bulbs
coffee robot machine
White Gold Light Source Bed Side Led Nordic Style Table Lamp
Modern LED Touch Aluminum Bedside Portable Table Lamp
rep model louis vuitton GUCCI Jackie 1961 medium tote bag
coffee robot machine
cheap louis vuitton overview Gucci TOTE BAG-35*26*13cm
cheap louis vuitton beginning Gucci OPHIDIA MEDIUM TOTE BAG
coffee robot machine
rep louis vuitton started GUCCI Gucci GG Supreme Monogram Tote Bag
rep creator of louis vuitton Gucci OPHIDIA MEDIUM TOTE BAG
cheap og bags ru HOT SALE-GUCCI GG matelassé leather top handle bag
cheap ogbags ru website HOT SALE-GUCCI GG matelassé leather top handle bag
csgo case opening
Grinding Train Wheels
Commercial Hotel Restaurant Food Warmer Lamp 4 Head
cheap tb bags HOT SALE-GUCCI Off The Grid sling backpack
Food Warmer Lamp N01H Table Lamp Style W/O Tray
coffee robot
radyoyayini.com
famous rubber keychain
cheap ogbags HOT SALE-GUCCI Aphrodite medium shoulder bag
Food Warmer Lamp M01H Table Lamp Style With Marble Tray
cheap ogbags.ru website HOT SALE-GUCCI GG matelassé leather top handle bag
Commercial Hotel Restaurant Food Warmer Lamp 3 Head
Food Warmer Lamp Q01H Table Lamp Style W/O Tray
Atlas Copco Compressor Dealers
Atlas Copco compressor distributors
Atlas Copco compressor distributors
cheap cheap gucci tennis shoes LV Bags 2409YA0163
affordable cheap gucci t shirt LV Bags 2409YA0160
Atlas Copco compressor distributors
cheap cheap gucci sweatsuit LV Bags 2409YA0159
Pure Graphite Gasket
Atlas Copco compressor distributors
iestore.uk
Corrugated Gasket with PTFE Coated
Graphite Gasket Reinforced with tanged metal
Atlas Copco compressor distributors
cheap cheap gucci tops LV Bags 2410YA0182
affordable cheap gucci things LV Bags 2409YA0054
Corrugated Gasket with Graphite Coating
Corrugated metal gaskets
csgo case opening
famous rubber keychain
http://www.isotop.com.br
Directional Control Valve
coffee robot
Pressure Relief Valve
Rep goodkicks.ru shoes New Balance 9060 “White Taro” sneakers
best rubber keychain
Pressure Valve
Cheap good kicks ru New Balance WRPD sneakers
Camping Folding Box With Handle
Beverage filling machine
80% Off Sale good kicks New Balance x JJJJound 990v3 “Brown” sneakers
Pressure Reducing Valve
Rep goodkick.ru shoes New Balance 327 “White Black” sneakers
Cheap goodkicks reps New Balance 1906R logo-patch sneakers
Injection Molding
affordable prime outlet norfolk Vans, Baskets FILMORE HI PRESSED FLORAL, blanc, femmes
Atlas Copco Compressor Dealers
фланец приварной плоский
csgo case opening
cheap yeezy company Vans, Espadrille FILMORE HI, piment rouge, hommes
affordable kicks under cost Vans, Espadrille WARD RAINBOW CHECKERED, filles
best rubber keychain
Beverage filling machine
cheap jersey outlets tinton falls Vans, Baskets hautes à lacets FILMORE HI, noir résine, hommes
большой фланец
http://www.west.com.do
Колено из нержавеющей стали
Фланцы из нержавеющей стали
cheap logo adidas white Vans, Baskets CALDRONE, noir blanc, hommes
Фланцевая заглушка BL
I am extremely inspired with your writing abilities and also with the structure in your weblog. Is this a paid topic or did you customize it your self? Either way stay up the excellent high quality writing, it’s uncommon to look a nice blog like this one these days!
I’m really inspired with your writing talents and also
with the layout in your weblog. Is that this a paid
topic or did you customize it yourself? Anyway stay up the nice
quality writing, it’s rare to see a nice weblog like this one these days.
Beacons AI!