Search in sources :

Example 26 with ConnectorStatus

use of org.apache.kafka.connect.runtime.ConnectorStatus in project kafka by apache.

the class KafkaStatusBackingStoreTest method putConnectorState.

@Test
public void putConnectorState() {
    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, 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 : 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) Test(org.junit.Test)

Example 27 with ConnectorStatus

use of org.apache.kafka.connect.runtime.ConnectorStatus in project kafka by apache.

the class KafkaStatusBackingStoreTest method putSafeOverridesValueSetBySameWorker.

@Test
public void putSafeOverridesValueSetBySameWorker() {
    final byte[] value = new byte[0];
    // the persisted came from the same host, but has a newer generation
    Map<String, Object> firstStatusRead = new HashMap<>();
    firstStatusRead.put("worker_id", WORKER_ID);
    firstStatusRead.put("state", "RUNNING");
    firstStatusRead.put("generation", 1L);
    Map<String, Object> secondStatusRead = new HashMap<>();
    secondStatusRead.put("worker_id", WORKER_ID);
    secondStatusRead.put("state", "UNASSIGNED");
    secondStatusRead.put("generation", 0L);
    when(converter.toConnectData(STATUS_TOPIC, value)).thenReturn(new SchemaAndValue(null, firstStatusRead)).thenReturn(new SchemaAndValue(null, secondStatusRead));
    when(converter.fromConnectData(eq(STATUS_TOPIC), any(Schema.class), any(Struct.class))).thenReturn(value);
    doAnswer(invocation -> {
        ((Callback) invocation.getArgument(2)).onCompletion(null, null);
        store.read(consumerRecord(1, "status-connector-conn", value));
        return null;
    }).when(kafkaBasedLog).send(eq("status-connector-conn"), eq(value), any(Callback.class));
    store.read(consumerRecord(0, "status-connector-conn", value));
    store.putSafe(new ConnectorStatus(CONNECTOR, ConnectorStatus.State.UNASSIGNED, WORKER_ID, 0));
    ConnectorStatus status = new ConnectorStatus(CONNECTOR, ConnectorStatus.State.UNASSIGNED, WORKER_ID, 0);
    assertEquals(status, store.get(CONNECTOR));
}
Also used : Callback(org.apache.kafka.clients.producer.Callback) HashMap(java.util.HashMap) Schema(org.apache.kafka.connect.data.Schema) ConnectorStatus(org.apache.kafka.connect.runtime.ConnectorStatus) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) SchemaAndValue(org.apache.kafka.connect.data.SchemaAndValue) Struct(org.apache.kafka.connect.data.Struct) Test(org.junit.Test)

Aggregations

ConnectorStatus (org.apache.kafka.connect.runtime.ConnectorStatus)27 Test (org.junit.Test)23 Callback (org.apache.kafka.clients.producer.Callback)14 Schema (org.apache.kafka.connect.data.Schema)13 Struct (org.apache.kafka.connect.data.Struct)13 HashMap (java.util.HashMap)12 SchemaAndValue (org.apache.kafka.connect.data.SchemaAndValue)12 MockTime (org.apache.kafka.common.utils.MockTime)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)6 TaskStatus (org.apache.kafka.connect.runtime.TaskStatus)5 EasyMock.anyObject (org.easymock.EasyMock.anyObject)4 Map (java.util.Map)3 ConfigException (org.apache.kafka.common.config.ConfigException)3 UnknownServerException (org.apache.kafka.common.errors.UnknownServerException)3 ExecutionException (java.util.concurrent.ExecutionException)2 RetriableException (org.apache.kafka.common.errors.RetriableException)2 TimeoutException (org.apache.kafka.common.errors.TimeoutException)2 Connector (org.apache.kafka.connect.connector.Connector)2 NotFoundException (org.apache.kafka.connect.errors.NotFoundException)2 WorkerConnector (org.apache.kafka.connect.runtime.WorkerConnector)2