use of org.apache.kafka.connect.runtime.ConnectorStatus 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));
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project kafka by apache.
the class KafkaStatusBackingStoreTest method readConnectorState.
@Test
public void readConnectorState() {
byte[] value = new byte[0];
Map<String, Object> statusMap = new HashMap<>();
statusMap.put("worker_id", WORKER_ID);
statusMap.put("state", "RUNNING");
statusMap.put("generation", 0L);
when(converter.toConnectData(STATUS_TOPIC, value)).thenReturn(new SchemaAndValue(null, statusMap));
store.read(consumerRecord(0, "status-connector-conn", value));
ConnectorStatus status = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.RUNNING, WORKER_ID, 0);
assertEquals(status, store.get(CONNECTOR));
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project kafka by apache.
the class KafkaStatusBackingStoreTest method putConnectorStateNonRetriableFailure.
@Test
public void putConnectorStateNonRetriableFailure() {
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 UnknownServerException());
return null;
}).when(kafkaBasedLog).send(eq("status-connector-conn"), eq(value), any(Callback.class));
// the error is logged and ignored
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));
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project kafka by apache.
the class MemoryStatusBackingStoreTest method putAndGetConnectorStatus.
@Test
public void putAndGetConnectorStatus() {
MemoryStatusBackingStore store = new MemoryStatusBackingStore();
ConnectorStatus status = new ConnectorStatus("connector", ConnectorStatus.State.RUNNING, "localhost:8083", 0);
store.put(status);
assertEquals(status, store.get("connector"));
}
use of org.apache.kafka.connect.runtime.ConnectorStatus in project apache-kafka-on-k8s by banzaicloud.
the class KafkaStatusBackingStore method parseConnectorStatus.
private ConnectorStatus parseConnectorStatus(String connector, byte[] data) {
try {
SchemaAndValue schemaAndValue = converter.toConnectData(topic, data);
if (!(schemaAndValue.value() instanceof Map)) {
log.error("Invalid connector status type {}", schemaAndValue.value().getClass());
return null;
}
@SuppressWarnings("unchecked") Map<String, Object> statusMap = (Map<String, Object>) schemaAndValue.value();
TaskStatus.State state = TaskStatus.State.valueOf((String) statusMap.get(STATE_KEY_NAME));
String trace = (String) statusMap.get(TRACE_KEY_NAME);
String workerUrl = (String) statusMap.get(WORKER_ID_KEY_NAME);
int generation = ((Long) statusMap.get(GENERATION_KEY_NAME)).intValue();
return new ConnectorStatus(connector, state, trace, workerUrl, generation);
} catch (Exception e) {
log.error("Failed to deserialize connector status", e);
return null;
}
}
Aggregations