@Test(expected = KsqlRestClientException.class) public void shouldThrowOnInvalidServerAddress() { new KsqlRestClient("not-valid-address"); }
@SuppressWarnings("unchecked") private <T> void givenServerWillReturn(final int statusCode, final Optional<T> entity) { final Response response = mock(Response.class); when(response.getStatus()).thenReturn(statusCode); entity.ifPresent(e -> when(response.readEntity((Class<T>) e.getClass())).thenReturn(e)); final Invocation.Builder builder = mock(Invocation.Builder.class); when(builder.get()).thenReturn(response); when(builder.post(any())).thenReturn(response); final WebTarget target = mock(WebTarget.class); when(target.path(any())).thenReturn(target); when(target.request(MediaType.APPLICATION_JSON_TYPE)).thenReturn(builder); final Client client = mock(Client.class); when(client.target(any(URI.class))).thenReturn(target); ksqlRestClient = new KsqlRestClient(client, "http://0.0.0.0", Collections.emptyMap()); }
private static void createStreams() { try (final KsqlRestClient ksqlRestClient = new KsqlRestClient(REST_APP.getHttpListener().toString()) ) { final RestResponse createStreamResponse = ksqlRestClient .makeKsqlRequest(String.format( "CREATE STREAM %s (viewtime bigint, pageid varchar, userid varchar)" + " WITH (kafka_topic='pageviews', value_format='json');", PAGE_VIEW_STREAM)); assertTrue(createStreamResponse.isSuccessful()); } } }
public static void main(final String[] args) throws IOException { final Options options = args.length == 0 ? Options.parse("http://localhost:8088") : Options.parse(args); if (options == null) { System.exit(-1); } try { final Properties properties = loadProperties(options.getConfigFile()); try (KsqlRestClient restClient = new KsqlRestClient(options.getServer(), properties)) { options.getUserNameAndPassword().ifPresent( creds -> restClient.setupAuthenticationCredentials(creds.left, creds.right) ); final KsqlVersionCheckerAgent versionChecker = new KsqlVersionCheckerAgent(() -> false); versionChecker.start(KsqlModuleType.CLI, properties); try (Cli cli = Cli.build( options.getStreamedQueryRowLimit(), options.getStreamedQueryTimeoutMs(), options.getOutputFormat(), restClient) ) { cli.runInteractively(); } } } catch (final Exception e) { final String msg = ErrorMessageUtil.buildErrorMessage(e); LOGGER.error(msg); System.err.println(msg); System.exit(-1); } }
@Before public void init() throws Exception { mockApplication = new MockApplication(); mockApplication.start(); ksqlRestClient = new KsqlRestClient(mockApplication.getServerAddress()); }
private int canMakeCliRequest(final String username, final String password) { try (KsqlRestClient restClient = new KsqlRestClient(REST_APP.getHttpListener().toString())) { if (!username.isEmpty()) { restClient.setupAuthenticationCredentials(username, password); } final RestResponse<ServerInfo> response = restClient.getServerInfo(); if (response.isSuccessful()) { return Code.OK.getCode(); } return response.getErrorMessage().getErrorCode(); } }
@BeforeClass public static void classSetUp() throws Exception { restClient = new KsqlRestClient(REST_APP.getHttpListener().toString()); commandTopicName = KsqlRestConfig.getCommandTopic(KsqlConfig.KSQL_SERVICE_ID_DEFAULT); orderDataProvider = new OrderDataProvider(); CLUSTER.createTopic(orderDataProvider.topicName()); topicProducer = new TopicProducer(CLUSTER); topicConsumer = new TopicConsumer(CLUSTER); produceInputStream(orderDataProvider); try (Cli cli = Cli.build(1L, 1000L, OutputFormat.JSON, restClient)) { createKStream(orderDataProvider, cli); } }