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"));
}
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)));
}
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));
}
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));
}
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"));
}
Aggregations