本文整理汇总了Java中com.jcabi.aspects.RetryOnFailure类的典型用法代码示例。如果您正苦于以下问题:Java RetryOnFailure类的具体用法?Java RetryOnFailure怎么用?Java RetryOnFailure使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RetryOnFailure类属于com.jcabi.aspects包,在下文中一共展示了RetryOnFailure类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getAddress
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
@RetryOnFailure(attempts = 5, delay = 1, unit = TimeUnit.MINUTES)
public Address getAddress(double lat, double lng) throws IOException {
LatLng query = new LatLng(lat, lng);
for (LatLng entry : addressCache.keySet()) {
if (LatLngTool.distance(entry, query, LengthUnit.METER) < 30) {
return addressCache.get(entry);
}
}
// cannot find the place in the cache. Sleep a while and query the
// OpenStreetMap.
LoggerFactory.getLogger(this.getClass()).trace("Query {}", query);
Address newAddress = nominatimClient.getAddress(lng, lat);
addressCache.put(query, newAddress);
return newAddress;
}
示例2: validatesHtmlDocument
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* DefaultHtmlValidator can validate HTML document.
*
* @throws Exception If something goes wrong inside
*/
@Test
@RetryOnFailure(verbose = false)
public void validatesHtmlDocument() throws Exception {
MatcherAssert.assertThat(
ValidatorBuilder.HTML.validate(
StringUtils.join(
"<!DOCTYPE html>",
"<html><head><meta charset='UTF-8'>",
"<title>hey</title></head>",
"<body></body></html>"
)
).errors(),
Matchers.empty()
);
}
示例3: retriesAfterFailure
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* Repeater should retry a method that fails.
*/
@Test
public void retriesAfterFailure() {
final AtomicInteger calls = new AtomicInteger(0);
MatcherAssert.assertThat(
new Callable<Boolean>() {
@Override
@RetryOnFailure(attempts = Tv.THREE, verbose = false)
public Boolean call() {
if (calls.get() < Tv.THREE - 1) {
calls.incrementAndGet();
throw new IllegalStateException();
}
return true;
}
} .call(),
Matchers.equalTo(true)
);
MatcherAssert.assertThat(calls.get(), Matchers.equalTo(Tv.THREE - 1));
}
示例4: stopsRetryingAfterNumberOfAttempts
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* Repeater should stop method retries if it exceeds a threshold.
*/
@Test(expected = IllegalStateException.class)
public void stopsRetryingAfterNumberOfAttempts() {
final AtomicInteger calls = new AtomicInteger(0);
new Callable<Boolean>() {
@Override
@RetryOnFailure(attempts = Tv.THREE, verbose = false)
public Boolean call() {
if (calls.get() < Tv.THREE) {
calls.incrementAndGet();
throw new IllegalStateException();
}
return true;
}
} .call();
}
示例5: onlyRetryExceptionsWhichAreSpecified
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* Repeater should retry if an exception specified to be
* retried is thrown from the method.
*/
@Test
public void onlyRetryExceptionsWhichAreSpecified() {
final AtomicInteger calls = new AtomicInteger(0);
MatcherAssert.assertThat(
new Callable<Boolean>() {
@Override
@RetryOnFailure
(
attempts = Tv.THREE,
types = {ArrayIndexOutOfBoundsException.class },
verbose = false
)
public Boolean call() {
if (calls.get() < Tv.THREE - 1) {
calls.incrementAndGet();
throw new ArrayIndexOutOfBoundsException();
}
return true;
}
} .call(),
Matchers.equalTo(true)
);
MatcherAssert.assertThat(calls.get(), Matchers.equalTo(Tv.THREE - 1));
}
示例6: throwExceptionsWhichAreNotSpecifiedAsRetry
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* Repeater should throw the exception if it is
* not specified to be retried.
*/
@Test(expected = ArrayIndexOutOfBoundsException.class)
public void throwExceptionsWhichAreNotSpecifiedAsRetry() {
final AtomicInteger calls = new AtomicInteger(0);
try {
new Callable<Boolean>() {
@Override
@RetryOnFailure
(
attempts = Tv.THREE,
types = {IllegalArgumentException.class },
verbose = false
)
public Boolean call() {
if (calls.get() < Tv.THREE - 1) {
calls.incrementAndGet();
throw new ArrayIndexOutOfBoundsException();
}
return true;
}
} .call();
} finally {
MatcherAssert.assertThat(calls.get(), Matchers.equalTo(1));
}
}
示例7: retryExceptionsWhichAreSubTypesOfTheExceptionsSpecified
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* Repeater should retry even if the exception is a
* subtype of the class specified to be retried.
*/
@Test
public void retryExceptionsWhichAreSubTypesOfTheExceptionsSpecified() {
final AtomicInteger calls = new AtomicInteger(0);
MatcherAssert.assertThat(
new Callable<Boolean>() {
@Override
@RetryOnFailure
(
attempts = Tv.THREE,
verbose = false,
types = {IndexOutOfBoundsException.class }
)
public Boolean call() {
if (calls.get() < Tv.THREE - 1) {
calls.incrementAndGet();
throw new ArrayIndexOutOfBoundsException();
}
return true;
}
} .call(),
Matchers.equalTo(true)
);
MatcherAssert.assertThat(calls.get(), Matchers.equalTo(Tv.THREE - 1));
}
示例8: validatesCssDocument
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* DefaultCssValidator can validate CSS document.
* @throws Exception If something goes wrong inside
*/
@Test
@RetryOnFailure(verbose = false)
public void validatesCssDocument() throws Exception {
MatcherAssert.assertThat(
ValidatorBuilder.CSS.validate("* { }").errors(),
Matchers.empty()
);
}
示例9: reserve
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* Reserve port.
* @return Reserved TCP port
* @throws IOException If fails
*/
@RetryOnFailure
private static int reserve() throws IOException {
final int reserved;
try (final ServerSocket socket = new ServerSocket(0)) {
reserved = socket.getLocalPort();
}
return reserved;
}
示例10: matchesValidHtml
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* W3CMatchers can check HTML document validity.
*/
@Test
@RetryOnFailure(verbose = false)
public void matchesValidHtml() {
MatcherAssert.assertThat(
StringUtils.join(
"<!DOCTYPE html>",
"<html><head><meta charset='UTF-8'/>",
"<title>hey</title></head>",
"<body></body></html>"
),
W3CMatchers.validHtml()
);
}
示例11: rejectsInvalidHtml
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* W3CMatchers can reject invalid HTML document.
*/
@Test
@RetryOnFailure(verbose = false)
public void rejectsInvalidHtml() {
MatcherAssert.assertThat(
"<blah><blaaaaaaaaa/>",
Matchers.not(W3CMatchers.validHtml())
);
}
示例12: matchesValidCss
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* W3CMatchers can check CSS document validity.
*/
@Test
@RetryOnFailure(verbose = false)
public void matchesValidCss() {
MatcherAssert.assertThat(
"body { background-color:#d0e4fe; }",
W3CMatchers.validCss()
);
}
示例13: rejectsInvalidCss
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* W3CMatchers can reject invalid CSS document.
*/
@Test
@RetryOnFailure(verbose = false)
public void rejectsInvalidCss() {
MatcherAssert.assertThat(
"hello { $#^@*&^$&@; }",
Matchers.not(W3CMatchers.validCss())
);
}
示例14: port
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
/**
* Returns available port number.
* @return Available port number
* @throws IOException in case of IO error.
*/
@RetryOnFailure
public final int port() throws IOException {
final ServerSocket socket = new ServerSocket();
try {
socket.setReuseAddress(true);
socket.bind(
new InetSocketAddress("localhost", 0)
);
return socket.getLocalPort();
} finally {
socket.close();
}
}
示例15: next
import com.jcabi.aspects.RetryOnFailure; //导入依赖的package包/类
@Override
@RetryOnFailure
(
verbose = false, delay = Tv.FIVE, unit = TimeUnit.SECONDS,
ignore = NoSuchElementException.class
)
public T next() {
return this.origin.next();
}