Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class TopicManagementResponse {
.put("NOT_FOUND", "registration-token-not-registered")
.put("INTERNAL", "internal-error")
.put("TOO_MANY_TOPICS", "too-many-topics")
.put("RESOURCE_EXHAUSTED", "resource-exhausted")
.build();

private final int successCount;
Expand Down Expand Up @@ -101,8 +102,11 @@ public static class Error {

private Error(int index, String reason) {
this.index = index;
this.reason = ERROR_CODES.containsKey(reason)
? ERROR_CODES.get(reason) : UNKNOWN_ERROR;
if (reason == null || reason.trim().isEmpty()) {
this.reason = UNKNOWN_ERROR;
} else {
this.reason = ERROR_CODES.getOrDefault(reason, reason);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,30 @@ public void testTopicManagementResponseWithEmptyList() {

@Test
public void testTopicManagementResponseErrorToString() {
GenericJson json = new GenericJson().set("error", "test error");
GenericJson json = new GenericJson().set("error", "INVALID_ARGUMENT");
ImmutableList<GenericJson> jsonList = ImmutableList.of(json);

TopicManagementResponse topicManagementResponse = new TopicManagementResponse(jsonList);

String expected = "[Error{index=0, reason=invalid-argument}]";
assertEquals(expected, topicManagementResponse.getErrors().toString());
}

@Test
public void testTopicManagementResponseErrorNotInErrorCodes() {
String myError = "myError";
GenericJson json = new GenericJson().set("error", myError);
ImmutableList<GenericJson> jsonList = ImmutableList.of(json);

TopicManagementResponse topicManagementResponse = new TopicManagementResponse(jsonList);

String expected = "[Error{index=0, reason=" + myError + "}]";
assertEquals(expected, topicManagementResponse.getErrors().toString());
}

@Test
public void testTopicManagementResponseErrorUnknown() {
GenericJson json = new GenericJson().set("error", "");
ImmutableList<GenericJson> jsonList = ImmutableList.of(json);

TopicManagementResponse topicManagementResponse = new TopicManagementResponse(jsonList);
Expand All @@ -413,6 +436,17 @@ public void testTopicManagementResponseErrorToString() {
assertEquals(expected, topicManagementResponse.getErrors().toString());
}

@Test
public void testTopicManagementResponseErrorResourceExhausted() {
GenericJson json = new GenericJson().set("error", "RESOURCE_EXHAUSTED");
ImmutableList<GenericJson> jsonList = ImmutableList.of(json);

TopicManagementResponse topicManagementResponse = new TopicManagementResponse(jsonList);

String expected = "[Error{index=0, reason=resource-exhausted}]";
assertEquals(expected, topicManagementResponse.getErrors().toString());
}

private static InstanceIdClientImpl initInstanceIdClient(
final MockLowLevelHttpResponse mockResponse,
final HttpResponseInterceptor interceptor) {
Expand All @@ -432,7 +466,7 @@ private void checkTopicManagementRequest(
assertEquals(1, result.getFailureCount());
assertEquals(1, result.getErrors().size());
assertEquals(1, result.getErrors().get(0).getIndex());
assertEquals("unknown-error", result.getErrors().get(0).getReason());
assertEquals("error_reason", result.getErrors().get(0).getReason());

ByteArrayOutputStream out = new ByteArrayOutputStream();
request.getContent().writeTo(out);
Expand Down