use of io.confluent.kafkarest.entities.v3.ProduceResponse in project kafka-rest by confluentinc.
the class TopicsResourceBinaryProduceTest method testProduceToTopicException.
private void testProduceToTopicException(List<CompletableFuture<RecordMetadata>> produceResults, List<PartitionOffset> produceExceptionResults) {
Response rawResponse = produceToTopic(PRODUCE_EXCEPTION_DATA, produceResults);
if (produceExceptionResults == null) {
assertErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, rawResponse, RestServerErrorException.DEFAULT_ERROR_CODE, AbstractProduceAction.UNEXPECTED_PRODUCER_EXCEPTION, Versions.KAFKA_V2_JSON);
} else {
assertOKResponse(rawResponse, Versions.KAFKA_V2_JSON);
ProduceResponse response = TestUtils.tryReadEntityOrLog(rawResponse, ProduceResponse.class);
assertEquals(produceExceptionResults, response.getOffsets());
assertNull(response.getKeySchemaId());
assertNull(response.getValueSchemaId());
}
}
use of io.confluent.kafkarest.entities.v3.ProduceResponse in project kafka-rest by confluentinc.
the class TopicsResourceBinaryProduceTest method testProduceToTopicSuccess.
private void testProduceToTopicSuccess(List<ProduceRecord> records) {
Response rawResponse = produceToTopic(records, PRODUCE_RESULTS);
assertOKResponse(rawResponse, Versions.KAFKA_V2_JSON);
ProduceResponse response = TestUtils.tryReadEntityOrLog(rawResponse, ProduceResponse.class);
assertEquals(OFFSETS, response.getOffsets());
assertNull(response.getKeySchemaId());
assertNull(response.getValueSchemaId());
}
use of io.confluent.kafkarest.entities.v3.ProduceResponse in project kafka-rest by confluentinc.
the class ProduceActionIntegrationTest method produceAvroWithSchemaIdAndSubject.
@Test
public void produceAvroWithSchemaIdAndSubject() throws Exception {
String clusterId = testEnv.kafkaCluster().getClusterId();
SchemaKey keySchema = testEnv.schemaRegistry().createSchema("my-key-subject", new AvroSchema("{\"type\": \"string\"}"));
SchemaKey valueSchema = testEnv.schemaRegistry().createSchema("my-value-subject", new AvroSchema("{\"type\": \"string\"}"));
String key = "foo";
String value = "bar";
ProduceRequest request = ProduceRequest.builder().setKey(ProduceRequestData.builder().setSubject("my-key-subject").setSchemaId(keySchema.getSchemaId()).setData(TextNode.valueOf(key)).build()).setValue(ProduceRequestData.builder().setSubject("my-value-subject").setSchemaId(valueSchema.getSchemaId()).setData(TextNode.valueOf(value)).build()).setOriginalSize(0L).build();
Response response = testEnv.kafkaRest().target().path("/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/records").request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(request, MediaType.APPLICATION_JSON));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ProduceResponse actual = readProduceResponse(response);
ConsumerRecord<Object, Object> produced = testEnv.kafkaCluster().getRecord(TOPIC_NAME, actual.getPartitionId(), actual.getOffset(), testEnv.schemaRegistry().createAvroDeserializer(), testEnv.schemaRegistry().createAvroDeserializer());
assertEquals(key, produced.key());
assertEquals(value, produced.value());
}
use of io.confluent.kafkarest.entities.v3.ProduceResponse in project kafka-rest by confluentinc.
the class ProduceActionIntegrationTest method produceProtobufWithRawSchema.
@Test
public void produceProtobufWithRawSchema() throws Exception {
String clusterId = testEnv.kafkaCluster().getClusterId();
ProtobufSchema keySchema = new ProtobufSchema("syntax = \"proto3\"; message MyKey { string foo = 1; }");
ProtobufSchema valueSchema = new ProtobufSchema("syntax = \"proto3\"; message MyValue { string bar = 1; }");
ObjectNode key = new ObjectNode(JsonNodeFactory.instance);
key.put("foo", "foz");
ObjectNode value = new ObjectNode(JsonNodeFactory.instance);
value.put("bar", "baz");
ProduceRequest request = ProduceRequest.builder().setKey(ProduceRequestData.builder().setFormat(EmbeddedFormat.PROTOBUF).setRawSchema(keySchema.canonicalString()).setData(key).build()).setValue(ProduceRequestData.builder().setFormat(EmbeddedFormat.PROTOBUF).setRawSchema(valueSchema.canonicalString()).setData(value).build()).setOriginalSize(0L).build();
Response response = testEnv.kafkaRest().target().path("/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/records").request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(request, MediaType.APPLICATION_JSON));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ProduceResponse actual = readProduceResponse(response);
ConsumerRecord<Message, Message> produced = testEnv.kafkaCluster().getRecord(TOPIC_NAME, actual.getPartitionId(), actual.getOffset(), testEnv.schemaRegistry().createProtobufDeserializer(), testEnv.schemaRegistry().createProtobufDeserializer());
DynamicMessage.Builder expectedKey = DynamicMessage.newBuilder(keySchema.toDescriptor());
expectedKey.setField(keySchema.toDescriptor().findFieldByName("foo"), "foz");
DynamicMessage.Builder expectedValue = DynamicMessage.newBuilder(valueSchema.toDescriptor());
expectedValue.setField(valueSchema.toDescriptor().findFieldByName("bar"), "baz");
assertEquals(expectedKey.build().toByteString(), produced.key().toByteString());
assertEquals(expectedValue.build().toByteString(), produced.value().toByteString());
}
use of io.confluent.kafkarest.entities.v3.ProduceResponse in project kafka-rest by confluentinc.
the class ProduceActionIntegrationTest method produceBinaryValueOnly.
@Test
public void produceBinaryValueOnly() throws Exception {
String clusterId = testEnv.kafkaCluster().getClusterId();
ByteString value = ByteString.copyFromUtf8("bar");
ProduceRequest request = ProduceRequest.builder().setValue(ProduceRequestData.builder().setFormat(EmbeddedFormat.BINARY).setData(BinaryNode.valueOf(value.toByteArray())).build()).setOriginalSize(0L).build();
Response response = testEnv.kafkaRest().target().path("/v3/clusters/" + clusterId + "/topics/" + TOPIC_NAME + "/records").request().accept(MediaType.APPLICATION_JSON).post(Entity.entity(request, MediaType.APPLICATION_JSON));
assertEquals(Status.OK.getStatusCode(), response.getStatus());
ProduceResponse actual = readProduceResponse(response);
ConsumerRecord<byte[], byte[]> produced = testEnv.kafkaCluster().getRecord(TOPIC_NAME, actual.getPartitionId(), actual.getOffset(), new ByteArrayDeserializer(), new ByteArrayDeserializer());
assertNull(produced.key());
assertEquals(value, ByteString.copyFrom(produced.value()));
}
Aggregations