use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesFutureThrowsException.
@Test
public void shouldIncludeUnresponsiveIfShowQueriesFutureThrowsException() {
// Given
when(sessionProperties.getInternalRequest()).thenReturn(false);
final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES;");
final PersistentQueryMetadata metadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
final KsqlEngine engine = mock(KsqlEngine.class);
when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(metadata));
when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(metadata));
when(ksqlClient.makeKsqlRequest(any(), any(), any())).thenThrow(new KsqlRestClientException("error"));
when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
queryStatusCount.updateStatusCount(RUNNING_QUERY_STATE, 1);
queryStatusCount.updateStatusCount(KsqlQueryStatus.UNRESPONSIVE, 1);
// When
final Queries queries = (Queries) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
// Then
assertThat(queries.getQueries(), containsInAnyOrder(persistentQueryMetadataToRunningQuery(metadata, queryStatusCount)));
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class ListQueriesExecutorTest method shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException.
@Test
public void shouldIncludeUnresponsiveIfShowQueriesExtendedFutureThrowsException() {
// Given
when(sessionProperties.getInternalRequest()).thenReturn(false);
final ConfiguredStatement<ListQueries> showQueries = (ConfiguredStatement<ListQueries>) engine.configure("SHOW QUERIES EXTENDED;");
final PersistentQueryMetadata metadata = givenPersistentQuery("id", RUNNING_QUERY_STATE);
final KsqlEngine engine = mock(KsqlEngine.class);
when(engine.getAllLiveQueries()).thenReturn(ImmutableList.of(metadata));
when(engine.getPersistentQueries()).thenReturn(ImmutableList.of(metadata));
when(ksqlClient.makeKsqlRequest(any(), any(), any())).thenThrow(new KsqlRestClientException("error"));
when(serviceContext.getKsqlClient()).thenReturn(ksqlClient);
// When
final Map<KsqlHostInfoEntity, KsqlQueryStatus> map = new HashMap<>();
map.put(LOCAL_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.RUNNING);
map.put(REMOTE_KSQL_HOST_INFO_ENTITY, KsqlQueryStatus.UNRESPONSIVE);
// When
final QueryDescriptionList queries = (QueryDescriptionList) CUSTOM_EXECUTORS.listQueries().execute(showQueries, sessionProperties, engine, serviceContext).getEntity().orElseThrow(IllegalStateException::new);
// Then
assertThat(queries.getQueryDescriptions(), containsInAnyOrder(QueryDescriptionFactory.forQueryMetadata(metadata, map)));
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class KsqlClient method createHttpClient.
private static HttpClient createHttpClient(final Vertx vertx, final Map<String, String> clientProps, final HttpClientOptions httpClientOptions, final boolean tls) {
if (tls) {
httpClientOptions.setSsl(true);
configureHostVerification(clientProps, httpClientOptions);
final Optional<JksOptions> trustStoreOptions = VertxSslOptionsFactory.getJksTrustStoreOptions(clientProps);
if (trustStoreOptions.isPresent()) {
httpClientOptions.setTrustStoreOptions(trustStoreOptions.get());
final String alias = clientProps.get(SSL_KEYSTORE_ALIAS_CONFIG);
final Optional<JksOptions> keyStoreOptions = VertxSslOptionsFactory.buildJksKeyStoreOptions(clientProps, Optional.ofNullable(alias));
keyStoreOptions.ifPresent(options -> httpClientOptions.setKeyStoreOptions(options));
}
}
try {
return vertx.createHttpClient(httpClientOptions);
} catch (VertxException e) {
throw new KsqlRestClientException(e.getMessage(), e);
}
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class CliTest method shouldPrintErrorIfCantConnectToRestServerOnRunCommand.
@Test
public void shouldPrintErrorIfCantConnectToRestServerOnRunCommand() throws Exception {
givenRunInteractivelyWillExit();
final KsqlRestClient mockRestClient = givenMockRestClient();
when(mockRestClient.getServerInfo()).thenThrow(new KsqlRestClientException("Boom", new IOException("")));
new Cli(1L, 1L, mockRestClient, console).runCommand("this is a command");
assertThat(terminal.getOutputString(), containsString("Please ensure that the URL provided is for an active KSQL server."));
}
use of io.confluent.ksql.rest.client.exception.KsqlRestClientException in project ksql by confluentinc.
the class RemoteServerSpecificCommandTest method shouldPrintErrorWhenCantConnectToNewAddress.
@Test
public void shouldPrintErrorWhenCantConnectToNewAddress() {
// Given:
when(restClient.getServerInfo()).thenThrow(new KsqlRestClientException("Failed to connect", new IOException("Boom")));
// When:
command.execute(ImmutableList.of(VALID_SERVER_ADDRESS), terminal);
// Then:
assertThat(out.toString(), containsString("Boom"));
assertThat(out.toString(), containsString("Failed to connect"));
}
Aggregations