Skip to content

Commit

Permalink
fix: reinstate the old KsqlRestClient.create overload (#8761)
Browse files Browse the repository at this point in the history
  • Loading branch information
swist committed Feb 15, 2022
1 parent f9e6780 commit ee4a1bc
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,33 @@ public final class KsqlRestClient implements Closeable {
private List<URI> serverAddresses;
private boolean isCCloudServer;



/**
* @param serverAddress the address of the KSQL server to connect to.
* @param localProps initial set of local properties.
* @param clientProps properties used to build the client.
* @param creds optional credentials
*/
@Deprecated
public static KsqlRestClient create(
final String serverAddress,
final Map<String, ?> localProps,
final Map<String, String> clientProps,
final Optional<BasicCredentials> creds
) {
return create(
serverAddress,
localProps,
clientProps,
creds,
Optional.empty(),
(cprops, credz, lprops) -> new KsqlClient(cprops, credz, lprops,
new HttpClientOptions(),
Optional.of(new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2)))
);
}

/**
* @param serverAddress the address of the KSQL server to connect to.
* @param localProps initial set of local properties.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static io.confluent.ksql.rest.client.KsqlRestClient.CCLOUD_CONNECT_USERNAME_HEADER;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThrows;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -222,6 +223,18 @@ public void shouldNotIncludeAdditionalHeadersForOnPremNonConnectorRequest() thro
verify(target).postKsqlRequest("some ksql;", Collections.emptyMap(), Optional.of(0L));
}

@Test
public void shouldAllowCallingCreateWithoutNeedingACCloudApiKey() {
// This is a backwards compatibility check

final KsqlRestClient client = KsqlRestClient.create(SOME_SERVER_ADDRESS, LOCAL_PROPS, CLIENT_PROPS, Optional.empty());
assertThat(client, is(instanceOf(KsqlRestClient.class)));

// Also with new signature
final KsqlRestClient ccloudClient = KsqlRestClient.create(SOME_SERVER_ADDRESS, LOCAL_PROPS, CLIENT_PROPS, Optional.empty(), Optional.empty());
assertThat(ccloudClient, is(instanceOf(KsqlRestClient.class)));
}

private KsqlRestClient clientWithServerAddresses(final String serverAddresses) {
return clientWithServerAddresses(serverAddresses, Optional.empty());
}
Expand Down

0 comments on commit ee4a1bc

Please sign in to comment.