-
Notifications
You must be signed in to change notification settings - Fork 864
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix gRPC Retry Mechanism for Unsuccessful HTTP Responses
- Loading branch information
1 parent
74579aa
commit 18637d9
Showing
2 changed files
with
69 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
.../src/test/java/io/opentelemetry/exporter/sender/okhttp/internal/OkHttpGrpcSenderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.exporter.sender.okhttp.internal; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import io.opentelemetry.exporter.internal.RetryUtil; | ||
import okhttp3.Protocol; | ||
import okhttp3.Request; | ||
import okhttp3.Response; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class OkHttpGrpcSenderTest { | ||
|
||
@Test | ||
public void isRetryable_SuccessfulResponse() { | ||
Response response = | ||
new Response.Builder() | ||
.request(new Request.Builder().url("http://localhost/").build()) | ||
.protocol(Protocol.HTTP_2) | ||
.code(200) | ||
.message("OK") | ||
.header("grpc-status", "0") // OK | ||
.build(); | ||
|
||
boolean isRetryable = OkHttpGrpcSender.isRetryable(response); | ||
assertFalse(isRetryable); | ||
} | ||
|
||
@Test | ||
public void isRetryable_RetryableGrpcStatus() { | ||
for (String grpcStatus : RetryUtil.retryableGrpcStatusCodes()) { | ||
Response response = | ||
new Response.Builder() | ||
.request(new Request.Builder().url("http://localhost/").build()) | ||
.protocol(Protocol.HTTP_2) | ||
.code(503) | ||
.message("Service Unavailable") | ||
.header("grpc-status", grpcStatus) | ||
.build(); | ||
|
||
boolean isRetryable = OkHttpGrpcSender.isRetryable(response); | ||
assertTrue(isRetryable); | ||
} | ||
} | ||
|
||
@Test | ||
public void isRetryable_NonRetryableGrpcStatus() { | ||
Response response = | ||
new Response.Builder() | ||
.request(new Request.Builder().url("http://localhost/").build()) | ||
.protocol(Protocol.HTTP_2) | ||
.code(400) | ||
.message("Bad Request") | ||
.header("grpc-status", "3") // INVALID_ARGUMENT | ||
.build(); | ||
|
||
boolean isRetryable = OkHttpGrpcSender.isRetryable(response); | ||
assertFalse(isRetryable); | ||
} | ||
} |