use of io.confluent.ksql.api.utils.InsertsResponse in project ksql by confluentinc.
the class ApiIntegrationTest method shouldExecuteInserts.
@Test
public void shouldExecuteInserts() {
// Given:
JsonObject properties = new JsonObject();
JsonObject requestBody = new JsonObject().put("target", TEST_STREAM).put("properties", properties);
Buffer bodyBuffer = requestBody.toBuffer();
bodyBuffer.appendString("\n");
int numRows = 10;
for (int i = 0; i < numRows; i++) {
JsonObject row = new JsonObject().put("K", new JsonObject().put("F1", new JsonArray().add("my_key_" + i))).put("STR", "Value_" + i).put("LONG", 1000 + i).put("DEC", // JsonObject does not accept BigDecimal
i + 0.11).put("ARRAY", new JsonArray().add("a_" + i).add("b_" + i)).put("MAP", new JsonObject().put("k1", "v1_" + i).put("k2", "v2_" + i)).put("STRUCT", new JsonObject().put("F1", i)).put("COMPLEX", COMPLEX_FIELD_VALUE);
bodyBuffer.appendBuffer(row.toBuffer()).appendString("\n");
}
// When:
HttpResponse<Buffer> response = sendRequest("/inserts-stream", bodyBuffer);
// Then:
assertThat(response.statusCode(), is(200));
InsertsResponse insertsResponse = new InsertsResponse(response.bodyAsString());
assertThat(insertsResponse.acks, hasSize(numRows));
assertThat(insertsResponse.error, is(nullValue()));
Set<Long> sequences = new HashSet<>();
for (JsonObject ack : insertsResponse.acks) {
sequences.add(ack.getLong("seq"));
}
assertThat(sequences, hasSize(numRows));
for (long l = 0; l < numRows; l++) {
assertThat(sequences.contains(l), is(true));
}
}
use of io.confluent.ksql.api.utils.InsertsResponse in project ksql by confluentinc.
the class ApiIntegrationTest method shouldInsert.
private void shouldInsert(final String target, final JsonObject row) {
HttpResponse<Buffer> response = makeInsertsRequest(target, row);
assertThat(response.statusCode(), is(200));
InsertsResponse insertsResponse = new InsertsResponse(response.bodyAsString());
assertThat(insertsResponse.acks, hasSize(1));
assertThat(insertsResponse.error, is(nullValue()));
}
use of io.confluent.ksql.api.utils.InsertsResponse in project ksql by confluentinc.
the class AuthTest method shouldFailInsertRequest.
private void shouldFailInsertRequest(final String username, final String password, int expectedStatus, final String expectedMessage, final int expectedErrorCode) throws Exception {
// Given
JsonObject params = new JsonObject().put("target", "test-stream");
Buffer requestBody = Buffer.buffer();
requestBody.appendBuffer(params.toBuffer()).appendString("\n");
for (JsonObject row : DEFAULT_INSERT_ROWS) {
requestBody.appendBuffer(row.toBuffer()).appendString("\n");
}
// When
HttpResponse<Buffer> response = sendPostRequestWithCreds("/inserts-stream", requestBody, username, password);
// Then
assertThat(response.statusCode(), is(expectedStatus));
InsertsResponse insertsResponse = new InsertsResponse(response.bodyAsString());
validateError(expectedErrorCode, expectedMessage, insertsResponse.error);
}
use of io.confluent.ksql.api.utils.InsertsResponse in project ksql by confluentinc.
the class ApiTest method shouldHandleErrorInProcessingInserts.
@Test
public void shouldHandleErrorInProcessingInserts() throws Exception {
// Given
JsonObject params = new JsonObject().put("target", "test-stream");
List<JsonObject> rows = DEFAULT_INSERT_ROWS;
Buffer requestBody = Buffer.buffer();
requestBody.appendBuffer(params.toBuffer()).appendString("\n");
for (JsonObject row : rows) {
requestBody.appendBuffer(row.toBuffer()).appendString("\n");
}
// Inject an error on last row inserted
testEndpoints.setAcksBeforePublisherError(rows.size() - 1);
// When
HttpResponse<Buffer> response = sendPostRequest("/inserts-stream", requestBody);
// Then
// The HTTP response will be OK as the error is later in the stream after response
// headers have been written
assertThat(response.statusCode(), is(200));
assertThat(response.statusMessage(), is("OK"));
String responseBody = response.bodyAsString();
InsertsResponse insertsResponse = new InsertsResponse(responseBody);
assertThat(insertsResponse.acks, hasSize(rows.size() - 1));
validateInsertStreamError(ERROR_CODE_SERVER_ERROR, "Error in processing inserts. Check server logs for details.", insertsResponse.error, (long) rows.size() - 1);
assertThat(testEndpoints.getInsertsSubscriber().isCompleted(), is(true));
}
use of io.confluent.ksql.api.utils.InsertsResponse in project ksql by confluentinc.
the class ApiTest method shouldUseDelimitedFormatWhenNoAcceptHeaderInserts.
@Test
public void shouldUseDelimitedFormatWhenNoAcceptHeaderInserts() throws Exception {
// When
JsonObject params = new JsonObject().put("target", "test-stream");
List<JsonObject> rows = DEFAULT_INSERT_ROWS;
Buffer requestBody = Buffer.buffer();
requestBody.appendBuffer(params.toBuffer()).appendString("\n");
for (JsonObject row : rows) {
requestBody.appendBuffer(row.toBuffer()).appendString("\n");
}
VertxCompletableFuture<HttpResponse<Buffer>> requestFuture = new VertxCompletableFuture<>();
client.post("/inserts-stream").sendBuffer(requestBody, requestFuture);
// Then
HttpResponse<Buffer> response = requestFuture.get();
String responseBody = response.bodyAsString();
InsertsResponse insertsResponse = new InsertsResponse(responseBody);
assertThat(insertsResponse.acks, hasSize(rows.size()));
for (int i = 0; i < insertsResponse.acks.size(); i++) {
final JsonObject ackLine = new JsonObject().put("status", "ok").put("seq", i);
assertThat(insertsResponse.acks.get(i), is(ackLine));
}
}
Aggregations