Search in sources :

Example 1 with KafkaBasedLog

use of org.apache.kafka.connect.util.KafkaBasedLog in project kafka by apache.

the class KafkaStatusBackingStoreTest method putConnectorStateRetriableFailure.

@Test
public void putConnectorStateRetriableFailure() {
    byte[] value = new byte[0];
    when(converter.fromConnectData(eq(STATUS_TOPIC), any(Schema.class), any(Struct.class))).thenReturn(value);
    doAnswer(invocation -> {
        ((Callback) invocation.getArgument(2)).onCompletion(null, new TimeoutException());
        return null;
    }).doAnswer(invocation -> {
        ((Callback) invocation.getArgument(2)).onCompletion(null, null);
        return null;
    }).when(kafkaBasedLog).send(eq("status-connector-conn"), eq(value), any(Callback.class));
    ConnectorStatus status = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.RUNNING, WORKER_ID, 0);
    store.put(status);
    // state is not visible until read back from the log
    assertNull(store.get(CONNECTOR));
}
Also used : WorkerConfig(org.apache.kafka.connect.runtime.WorkerConfig) KafkaBasedLog(org.apache.kafka.connect.util.KafkaBasedLog) MockTime(org.apache.kafka.common.utils.MockTime) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) Assert.assertThrows(org.junit.Assert.assertThrows) HashMap(java.util.HashMap) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) Schema(org.apache.kafka.connect.data.Schema) HashSet(java.util.HashSet) RecordHeaders(org.apache.kafka.common.header.internals.RecordHeaders) ArgumentCaptor(org.mockito.ArgumentCaptor) Map(java.util.Map) Mockito.doAnswer(org.mockito.Mockito.doAnswer) TimestampType(org.apache.kafka.common.record.TimestampType) Before(org.junit.Before) TimeoutException(org.apache.kafka.common.errors.TimeoutException) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) ConfigException(org.apache.kafka.common.config.ConfigException) DistributedConfig(org.apache.kafka.connect.runtime.distributed.DistributedConfig) Mockito.verify(org.mockito.Mockito.verify) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) Mockito.never(org.mockito.Mockito.never) Assert.assertNull(org.junit.Assert.assertNull) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Struct(org.apache.kafka.connect.data.Struct) Optional(java.util.Optional) Mockito.any(org.mockito.Mockito.any) Callback(org.apache.kafka.clients.producer.Callback) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) TaskStatus(org.apache.kafka.connect.runtime.TaskStatus) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Callback(org.apache.kafka.clients.producer.Callback) Schema(org.apache.kafka.connect.data.Schema) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) Struct(org.apache.kafka.connect.data.Struct) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Test(org.junit.Test)

Example 2 with KafkaBasedLog

use of org.apache.kafka.connect.util.KafkaBasedLog in project kafka by apache.

the class KafkaStatusBackingStoreFormatTest method putTopicStateRetriableFailure.

@Test
public void putTopicStateRetriableFailure() {
    TopicStatus topicStatus = new TopicStatus(FOO_TOPIC, new ConnectorTaskId(FOO_CONNECTOR, 0), time.milliseconds());
    String key = TOPIC_STATUS_PREFIX + FOO_TOPIC + TOPIC_STATUS_SEPARATOR + FOO_CONNECTOR;
    ArgumentCaptor<byte[]> valueCaptor = ArgumentCaptor.forClass(byte[].class);
    doAnswer(invocation -> {
        ((Callback) invocation.getArgument(2)).onCompletion(null, new TimeoutException());
        return null;
    }).doAnswer(invocation -> {
        ((Callback) invocation.getArgument(2)).onCompletion(null, null);
        return null;
    }).when(kafkaBasedLog).send(eq(key), valueCaptor.capture(), any(Callback.class));
    store.put(topicStatus);
    verify(kafkaBasedLog, times(2)).send(any(), any(), any());
    // check capture state
    assertEquals(topicStatus, store.parseTopicStatus(valueCaptor.getValue()));
    // state is not visible until read back from the log
    assertNull(store.getTopic(FOO_CONNECTOR, FOO_TOPIC));
}
Also used : KafkaBasedLog(org.apache.kafka.connect.util.KafkaBasedLog) MockTime(org.apache.kafka.common.utils.MockTime) Arrays(java.util.Arrays) TOPIC_STATUS_SEPARATOR(org.apache.kafka.connect.storage.KafkaStatusBackingStore.TOPIC_STATUS_SEPARATOR) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) HashSet(java.util.HashSet) ArgumentCaptor(org.mockito.ArgumentCaptor) TopicStatus(org.apache.kafka.connect.runtime.TopicStatus) Mockito.doAnswer(org.mockito.Mockito.doAnswer) Before(org.junit.Before) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Time(org.apache.kafka.common.utils.Time) SCHEMAS_ENABLE_CONFIG(org.apache.kafka.connect.json.JsonConverterConfig.SCHEMAS_ENABLE_CONFIG) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) CONNECTOR_STATUS_PREFIX(org.apache.kafka.connect.storage.KafkaStatusBackingStore.CONNECTOR_STATUS_PREFIX) TASK_STATUS_PREFIX(org.apache.kafka.connect.storage.KafkaStatusBackingStore.TASK_STATUS_PREFIX) Mockito.verify(org.mockito.Mockito.verify) Assert.assertNull(org.junit.Assert.assertNull) TOPIC_STATUS_PREFIX(org.apache.kafka.connect.storage.KafkaStatusBackingStore.TOPIC_STATUS_PREFIX) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Assert.assertFalse(org.junit.Assert.assertFalse) JsonConverter(org.apache.kafka.connect.json.JsonConverter) Mockito.any(org.mockito.Mockito.any) Callback(org.apache.kafka.clients.producer.Callback) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.eq(org.mockito.Mockito.eq) Mockito.mock(org.mockito.Mockito.mock) Callback(org.apache.kafka.clients.producer.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TopicStatus(org.apache.kafka.connect.runtime.TopicStatus) TimeoutException(org.apache.kafka.common.errors.TimeoutException) Test(org.junit.Test)

Aggregations

Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 ConsumerRecord (org.apache.kafka.clients.consumer.ConsumerRecord)2 Callback (org.apache.kafka.clients.producer.Callback)2 TimeoutException (org.apache.kafka.common.errors.TimeoutException)2 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)2 MockTime (org.apache.kafka.common.utils.MockTime)2 ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)2 KafkaBasedLog (org.apache.kafka.connect.util.KafkaBasedLog)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNull (org.junit.Assert.assertNull)2 Assert.assertTrue (org.junit.Assert.assertTrue)2 Before (org.junit.Before)2 Test (org.junit.Test)2 ArgumentCaptor (org.mockito.ArgumentCaptor)2 Mockito.any (org.mockito.Mockito.any)2 Mockito.doAnswer (org.mockito.Mockito.doAnswer)2 Mockito.eq (org.mockito.Mockito.eq)2 Mockito.mock (org.mockito.Mockito.mock)2 Mockito.verify (org.mockito.Mockito.verify)2