Search in sources :

Example 91 with ConnectorTaskId

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

the class KafkaStatusBackingStoreFormatTest method deleteTopicStatus.

@Test
public void deleteTopicStatus() {
    TopicStatus topicStatus = new TopicStatus("foo", new ConnectorTaskId("bar", 0), Time.SYSTEM.milliseconds());
    store.topics.computeIfAbsent("bar", k -> new ConcurrentHashMap<>()).put("foo", topicStatus);
    assertTrue(store.topics.containsKey("bar"));
    assertTrue(store.topics.get("bar").containsKey("foo"));
    assertEquals(topicStatus, store.topics.get("bar").get("foo"));
    // should return null
    byte[] value = store.serializeTopicStatus(null);
    ConsumerRecord<String, byte[]> statusRecord = new ConsumerRecord<>(STATUS_TOPIC, 0, 0, "status-topic-foo:connector-bar", value);
    store.read(statusRecord);
    assertTrue(store.topics.containsKey("bar"));
    assertFalse(store.topics.get("bar").containsKey("foo"));
    assertEquals(Collections.emptyMap(), store.topics.get("bar"));
}
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) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TopicStatus(org.apache.kafka.connect.runtime.TopicStatus) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 92 with ConnectorTaskId

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

the class KafkaStatusBackingStoreFormatTest method putTopicState.

@Test
public void putTopicState() {
    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, null);
        return null;
    }).when(kafkaBasedLog).send(eq(key), valueCaptor.capture(), any(Callback.class));
    store.put(topicStatus);
    // 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));
    ConsumerRecord<String, byte[]> statusRecord = new ConsumerRecord<>(STATUS_TOPIC, 0, 0, key, valueCaptor.getValue());
    store.read(statusRecord);
    assertEquals(topicStatus, store.getTopic(FOO_CONNECTOR, FOO_TOPIC));
    assertEquals(Collections.singleton(topicStatus), new HashSet<>(store.getAllTopics(FOO_CONNECTOR)));
}
Also used : Callback(org.apache.kafka.clients.producer.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TopicStatus(org.apache.kafka.connect.runtime.TopicStatus) ConsumerRecord(org.apache.kafka.clients.consumer.ConsumerRecord) Test(org.junit.Test)

Example 93 with ConnectorTaskId

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

the class KafkaStatusBackingStoreFormatTest method putTopicStateNonRetriableFailure.

@Test
public void putTopicStateNonRetriableFailure() {
    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 UnknownServerException());
        return null;
    }).when(kafkaBasedLog).send(eq(key), valueCaptor.capture(), any(Callback.class));
    // the error is logged and ignored
    store.put(topicStatus);
    // 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 : Callback(org.apache.kafka.clients.producer.Callback) ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TopicStatus(org.apache.kafka.connect.runtime.TopicStatus) UnknownServerException(org.apache.kafka.common.errors.UnknownServerException) Test(org.junit.Test)

Example 94 with ConnectorTaskId

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

the class MemoryStatusBackingStoreTest method deleteTaskStatus.

@Test
public void deleteTaskStatus() {
    MemoryStatusBackingStore store = new MemoryStatusBackingStore();
    ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
    store.put(new TaskStatus(taskId, ConnectorStatus.State.RUNNING, "localhost:8083", 0));
    store.put(new TaskStatus(taskId, ConnectorStatus.State.DESTROYED, "localhost:8083", 0));
    assertNull(store.get(taskId));
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TaskStatus(org.apache.kafka.connect.runtime.TaskStatus) Test(org.junit.Test)

Example 95 with ConnectorTaskId

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

the class MemoryStatusBackingStoreTest method putAndGetTaskStatus.

@Test
public void putAndGetTaskStatus() {
    MemoryStatusBackingStore store = new MemoryStatusBackingStore();
    ConnectorTaskId taskId = new ConnectorTaskId("connector", 0);
    TaskStatus status = new TaskStatus(taskId, ConnectorStatus.State.RUNNING, "localhost:8083", 0);
    store.put(status);
    assertEquals(status, store.get(taskId));
    assertEquals(Collections.singleton(status), store.getAll("connector"));
}
Also used : ConnectorTaskId(org.apache.kafka.connect.util.ConnectorTaskId) TaskStatus(org.apache.kafka.connect.runtime.TaskStatus) Test(org.junit.Test)

Aggregations

ConnectorTaskId (org.apache.kafka.connect.util.ConnectorTaskId)111 Test (org.junit.Test)59 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)45 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)25 Map (java.util.Map)18 FutureCallback (org.apache.kafka.connect.util.FutureCallback)16 ConnectException (org.apache.kafka.connect.errors.ConnectException)15 Callback (org.apache.kafka.connect.util.Callback)15 Connector (org.apache.kafka.connect.connector.Connector)13 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)12 ConnectorInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorInfo)12 SinkConnector (org.apache.kafka.connect.sink.SinkConnector)12 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)11 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)11 SourceConnector (org.apache.kafka.connect.source.SourceConnector)11 Herder (org.apache.kafka.connect.runtime.Herder)10 List (java.util.List)9 StatusBackingStore (org.apache.kafka.connect.storage.StatusBackingStore)9 ConnectorStateInfo (org.apache.kafka.connect.runtime.rest.entities.ConnectorStateInfo)8