Search in sources :

Example 76 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class KafkaConfigBackingStoreTest method testRecordToRestartRequest.

@Test
public void testRecordToRestartRequest() {
    ConsumerRecord<String, byte[]> record = new ConsumerRecord<>(TOPIC, 0, 0, 0L, TimestampType.CREATE_TIME, 0, 0, RESTART_CONNECTOR_KEYS.get(0), CONFIGS_SERIALIZED.get(0), new RecordHeaders(), Optional.empty());
    Struct struct = RESTART_REQUEST_STRUCTS.get(0);
    SchemaAndValue schemaAndValue = new SchemaAndValue(struct.schema(), structToMap(struct));
    RestartRequest restartRequest = configStorage.recordToRestartRequest(record, schemaAndValue);
    assertEquals(CONNECTOR_1_NAME, restartRequest.connectorName());
    assertEquals(struct.getBoolean(INCLUDE_TASKS_FIELD_NAME), restartRequest.includeTasks());
    assertEquals(struct.getBoolean(ONLY_FAILED_FIELD_NAME), restartRequest.onlyFailed());
}
Also used : RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) RestartRequest(org.apache.kafka.connect.runtime.RestartRequest) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Struct(org.apache.kafka.connect.data.Struct) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 77 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class WorkerSourceTaskTest method testHeaders.

@Test
public void testHeaders() throws Exception {
    Headers headers = new RecordHeaders();
    headers.add("header_key", "header_value".getBytes());
    org.apache.kafka.connect.header.Headers connectHeaders = new ConnectHeaders();
    connectHeaders.add("header_key", new SchemaAndValue(Schema.STRING_SCHEMA, "header_value"));
    createWorkerTask();
    List<SourceRecord> records = new ArrayList<>();
    records.add(new SourceRecord(PARTITION, OFFSET, TOPIC, null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD, null, connectHeaders));
    expectTopicCreation(TOPIC);
    Capture<ProducerRecord<byte[], byte[]>> sent = expectSendRecord(TOPIC, true, true, true, true, headers);
    PowerMock.replayAll();
    Whitebox.setInternalState(workerTask, "toSend", records);
    Whitebox.invokeMethod(workerTask, "sendRecords");
    assertEquals(SERIALIZED_KEY, sent.getValue().key());
    assertEquals(SERIALIZED_RECORD, sent.getValue().value());
    assertEquals(headers, sent.getValue().headers());
    PowerMock.verifyAll();
}
Also used : Headers(org.apache.kafka.common.header.Headers) ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ArrayList(java.util.ArrayList) SourceRecord(org.apache.kafka.connect.source.SourceRecord) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) ConnectHeaders(org.apache.kafka.connect.header.ConnectHeaders) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ProducerRecord(org.apache.kafka.clients.producer.ProducerRecord) ThreadedTest(org.apache.kafka.connect.util.ThreadedTest) RetryWithToleranceOperatorTest(org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperatorTest) ParameterizedTest(org.apache.kafka.connect.util.ParameterizedTest) Test(org.junit.Test)

Example 78 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project kafka by apache.

the class WorkerSinkTaskTest method expectConversionAndTransformation.

private void expectConversionAndTransformation(final int numMessages, final String topicPrefix, final Headers headers) {
    EasyMock.expect(keyConverter.toConnectData(TOPIC, headers, RAW_KEY)).andReturn(new SchemaAndValue(KEY_SCHEMA, KEY)).times(numMessages);
    EasyMock.expect(valueConverter.toConnectData(TOPIC, headers, RAW_VALUE)).andReturn(new SchemaAndValue(VALUE_SCHEMA, VALUE)).times(numMessages);
    for (Header header : headers) {
        EasyMock.expect(headerConverter.toConnectHeader(TOPIC, header.key(), header.value())).andReturn(new SchemaAndValue(VALUE_SCHEMA, new String(header.value()))).times(1);
    }
    expectTransformation(numMessages, topicPrefix);
}
Also used : Header(org.apache.kafka.common.header.Header) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue)

Example 79 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project connect-utils by jcustenborder.

the class BaseKeyValueTransformation method apply.

@Override
public R apply(R record) {
    SchemaAndValue key = new SchemaAndValue(record.keySchema(), record.key());
    SchemaAndValue value = new SchemaAndValue(record.valueSchema(), record.value());
    final SchemaAndValue input = this.isKey ? key : value;
    final SchemaAndValue result = process(record, input);
    if (this.isKey) {
        key = result;
    } else {
        value = result;
    }
    return record.newRecord(record.topic(), record.kafkaPartition(), key.schema(), key.value(), value.schema(), value.value(), record.timestamp(), record.headers());
}
Also used : SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue)

Example 80 with SchemaAndValue

use of org.apache.kafka.connect.data.SchemaAndValue in project connect-utils by jcustenborder.

the class StructHelperTest method generate.

SchemaAndValue generate(int count) {
    SchemaBuilder builder = SchemaBuilder.struct();
    for (int i = 1; i <= count; i++) {
        String fieldName = String.format("f%s", i);
        builder.field(fieldName, Schema.INT32_SCHEMA);
    }
    final Schema schema = builder.build();
    final Struct struct = new Struct(schema);
    for (int i = 1; i <= count; i++) {
        String fieldName = String.format("f%s", i);
        struct.put(fieldName, i);
    }
    return new SchemaAndValue(schema, struct);
}
Also used : Schema(org.apache.kafka.connect.data.Schema) SchemaBuilder(org.apache.kafka.connect.data.SchemaBuilder) Struct(org.apache.kafka.connect.data.Struct) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue)

Aggregations

SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)140 Test (org.junit.Test)57 Schema (org.apache.kafka.connect.data.Schema)49 Test (org.junit.jupiter.api.Test)46 HashMap (java.util.HashMap)32 Struct (org.apache.kafka.connect.data.Struct)21 Date (org.apache.kafka.connect.data.Date)18 BigInteger (java.math.BigInteger)12 Map (java.util.Map)12 ConnectorStatus (org.apache.kafka.connect.runtime.ConnectorStatus)11 BigDecimal (java.math.BigDecimal)10 TopicPartition (org.apache.kafka.common.TopicPartition)9 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)8 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)8 Callback (org.apache.kafka.clients.producer.Callback)7 SinkRecord (org.apache.kafka.connect.sink.SinkRecord)7 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)7 Collection (java.util.Collection)6 GregorianCalendar (java.util.GregorianCalendar)6 LinkedHashMap (java.util.LinkedHashMap)6