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


Java RetryOnFailure类代码示例

本文整理汇总了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;
}
 
开发者ID:ohmage,项目名称:lifestreams,代码行数:17,代码来源:CachedOpenStreetMapClient.java

示例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()
    );
}
 
开发者ID:jcabi,项目名称:jcabi-w3c,代码行数:21,代码来源:DefaultHtmlValidatorITCase.java

示例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));
}
 
开发者ID:jcabi,项目名称:jcabi-aspects,代码行数:23,代码来源:RepeaterTest.java

示例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();
}
 
开发者ID:jcabi,项目名称:jcabi-aspects,代码行数:19,代码来源:RepeaterTest.java

示例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));
}
 
开发者ID:jcabi,项目名称:jcabi-aspects,代码行数:29,代码来源:RepeaterTest.java

示例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));
    }
}
 
开发者ID:jcabi,项目名称:jcabi-aspects,代码行数:29,代码来源:RepeaterTest.java

示例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));
}
 
开发者ID:jcabi,项目名称:jcabi-aspects,代码行数:29,代码来源:RepeaterTest.java

示例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()
    );
}
 
开发者ID:jcabi,项目名称:jcabi-w3c,代码行数:13,代码来源:DefaultCssValidatorITCase.java

示例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;
}
 
开发者ID:jcabi,项目名称:jcabi-http,代码行数:14,代码来源:MkGrizzlyContainer.java

示例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()
    );
}
 
开发者ID:jcabi,项目名称:jcabi-matchers,代码行数:17,代码来源:W3CMatchersTest.java

示例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())
    );
}
 
开发者ID:jcabi,项目名称:jcabi-matchers,代码行数:12,代码来源:W3CMatchersTest.java

示例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()
    );
}
 
开发者ID:jcabi,项目名称:jcabi-matchers,代码行数:12,代码来源:W3CMatchersTest.java

示例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())
    );
}
 
开发者ID:jcabi,项目名称:jcabi-matchers,代码行数:12,代码来源:W3CMatchersTest.java

示例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();
    }
}
 
开发者ID:jcabi,项目名称:jcabi-github,代码行数:19,代码来源:RandomPort.java

示例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();
}
 
开发者ID:jcabi,项目名称:jcabi-dynamo,代码行数:10,代码来源:ReIterator.java


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