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


Java HttpStatusCodes.STATUS_CODE_SERVER_ERROR属性代码示例

本文整理汇总了Java中com.google.api.client.http.HttpStatusCodes.STATUS_CODE_SERVER_ERROR属性的典型用法代码示例。如果您正苦于以下问题:Java HttpStatusCodes.STATUS_CODE_SERVER_ERROR属性的具体用法?Java HttpStatusCodes.STATUS_CODE_SERVER_ERROR怎么用?Java HttpStatusCodes.STATUS_CODE_SERVER_ERROR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在com.google.api.client.http.HttpStatusCodes的用法示例。


在下文中一共展示了HttpStatusCodes.STATUS_CODE_SERVER_ERROR属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testSimpleRetry

public void testSimpleRetry() throws Exception {
    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 3);

    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();
    MockSleeper mockSleeper = new MockSleeper();

    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
        TimeValue.timeValueSeconds(5));

    Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    HttpResponse response = request.execute();

    assertThat(mockSleeper.getCount(), equalTo(3));
    assertThat(response.getStatusCode(), equalTo(200));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:22,代码来源:RetryHttpInitializerWrapperTests.java

示例2: testIOExceptionRetry

public void testIOExceptionRetry() throws Exception {
    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, 1, true);

    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();
    MockSleeper mockSleeper = new MockSleeper();
    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, mockSleeper,
        TimeValue.timeValueMillis(500));

    Compute client = new Compute.Builder(fakeTransport, new JacksonFactory(), null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    HttpResponse response = request.execute();

    assertThat(mockSleeper.getCount(), equalTo(1));
    assertThat(response.getStatusCode(), equalTo(200));
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:RetryHttpInitializerWrapperTests.java

示例3: testRetryWaitTooLong

public void testRetryWaitTooLong() throws Exception {
    TimeValue maxWaitTime = TimeValue.timeValueMillis(10);
    int maxRetryTimes = 50;

    FailThenSuccessBackoffTransport fakeTransport =
            new FailThenSuccessBackoffTransport(HttpStatusCodes.STATUS_CODE_SERVER_ERROR, maxRetryTimes);
    JsonFactory jsonFactory = new JacksonFactory();
    MockGoogleCredential credential = RetryHttpInitializerWrapper.newMockCredentialBuilder()
            .build();

    MockSleeper oneTimeSleeper = new MockSleeper() {
        @Override
        public void sleep(long millis) throws InterruptedException {
            Thread.sleep(maxWaitTime.getMillis());
            super.sleep(0); // important number, use this to get count
        }
    };

    RetryHttpInitializerWrapper retryHttpInitializerWrapper = new RetryHttpInitializerWrapper(credential, oneTimeSleeper, maxWaitTime);

    Compute client = new Compute.Builder(fakeTransport, jsonFactory, null)
            .setHttpRequestInitializer(retryHttpInitializerWrapper)
            .setApplicationName("test")
            .build();

    HttpRequest request1 = client.getRequestFactory().buildRequest("Get", new GenericUrl("http://elasticsearch.com"), null);
    try {
        request1.execute();
        fail("Request should fail if wait too long");
    } catch (HttpResponseException e) {
        assertThat(e.getStatusCode(), equalTo(HttpStatusCodes.STATUS_CODE_SERVER_ERROR));
        // should only retry once.
        assertThat(oneTimeSleeper.getCount(), lessThan(maxRetryTimes));
    }
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:35,代码来源:RetryHttpInitializerWrapperTests.java


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