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 @@ -124,8 +124,10 @@ public CompletableFuture<HeartbeatResponse> heartbeat(ProxyContext ctx, Heartbea
break;
}
default: {
log.warn("heartbeat rejected unsupported client type. clientId:{}, clientType:{}",
ctx.getClientID(), clientSettings.getClientType());
future.complete(HeartbeatResponse.newBuilder()
.setStatus(ResponseBuilder.getInstance().buildStatus(Code.UNRECOGNIZED_CLIENT_TYPE, clientSettings.getClientType().name()))
.setStatus(buildUnsupportedClientTypeStatus(clientSettings.getClientType()))
.build());
return future;
}
Expand Down Expand Up @@ -181,8 +183,10 @@ public CompletableFuture<NotifyClientTerminationResponse> notifyClientTerminatio
}
break;
default:
log.warn("client termination rejected unsupported client type. clientId:{}, clientType:{}",
clientId, clientSettings.getClientType());
future.complete(NotifyClientTerminationResponse.newBuilder()
.setStatus(ResponseBuilder.getInstance().buildStatus(Code.UNRECOGNIZED_CLIENT_TYPE, clientSettings.getClientType().name()))
.setStatus(buildUnsupportedClientTypeStatus(clientSettings.getClientType()))
.build());
return future;
}
Expand All @@ -195,6 +199,12 @@ public CompletableFuture<NotifyClientTerminationResponse> notifyClientTerminatio
return future;
}

private Status buildUnsupportedClientTypeStatus(ClientType clientType) {
String message = String.format("unsupported client type: %s. Proxy supports PRODUCER, PUSH_CONSUMER, "
+ "SIMPLE_CONSUMER, LITE_PUSH_CONSUMER and LITE_SIMPLE_CONSUMER", clientType.name());
return ResponseBuilder.getInstance().buildStatus(Code.UNRECOGNIZED_CLIENT_TYPE, message);
}

public CompletableFuture<SyncLiteSubscriptionResponse> syncLiteSubscription(ProxyContext ctx,
SyncLiteSubscriptionRequest request) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,40 @@ public void testConsumerHeartbeat() throws Throwable {
assertEquals("tag", data.getSubString());
}

@Test
public void testHeartbeatWithUnsupportedClientType() throws Throwable {
ProxyContext context = createContext();
Settings settings = Settings.newBuilder()
.setClientType(ClientType.CLIENT_TYPE_UNSPECIFIED)
.build();
when(this.grpcClientSettingsManager.getClientSettings(any())).thenReturn(settings);

HeartbeatResponse response = this.clientActivity.heartbeat(context, HeartbeatRequest.newBuilder()
.setClientType(ClientType.CLIENT_TYPE_UNSPECIFIED)
.build()).get();

assertEquals(Code.UNRECOGNIZED_CLIENT_TYPE, response.getStatus().getCode());
assertThat(response.getStatus().getMessage()).contains("unsupported client type: CLIENT_TYPE_UNSPECIFIED");
assertThat(response.getStatus().getMessage()).contains("Proxy supports");
}

@Test
public void testNotifyClientTerminationWithUnsupportedClientType() throws Throwable {
ProxyContext context = createContext();
Settings settings = Settings.newBuilder()
.setClientType(ClientType.CLIENT_TYPE_UNSPECIFIED)
.build();
when(this.grpcClientSettingsManager.removeAndGetClientSettings(any())).thenReturn(settings);

NotifyClientTerminationResponse response = this.clientActivity.notifyClientTermination(
context,
NotifyClientTerminationRequest.newBuilder().build()).get();

assertEquals(Code.UNRECOGNIZED_CLIENT_TYPE, response.getStatus().getCode());
assertThat(response.getStatus().getMessage()).contains("unsupported client type: CLIENT_TYPE_UNSPECIFIED");
assertThat(response.getStatus().getMessage()).contains("Proxy supports");
}

protected void assertClientChannelInfo(ClientChannelInfo clientChannelInfo, String group) {
assertEquals(LanguageCode.JAVA, clientChannelInfo.getLanguage());
assertEquals(CLIENT_ID, clientChannelInfo.getClientId());
Expand Down