Search in sources :

Example 1 with DeleteRecordsResult

use of org.apache.kafka.clients.admin.DeleteRecordsResult in project apache-kafka-on-k8s by banzaicloud.

the class TaskManagerTest method shouldSendPurgeData.

@Test
public void shouldSendPurgeData() {
    final KafkaFutureImpl<DeletedRecords> futureDeletedRecords = new KafkaFutureImpl<>();
    final Map<TopicPartition, RecordsToDelete> recordsToDelete = Collections.singletonMap(t1p1, RecordsToDelete.beforeOffset(5L));
    final DeleteRecordsResult deleteRecordsResult = new DeleteRecordsResult(Collections.singletonMap(t1p1, (KafkaFuture<DeletedRecords>) futureDeletedRecords));
    futureDeletedRecords.complete(null);
    EasyMock.expect(active.recordsToDelete()).andReturn(Collections.singletonMap(t1p1, 5L)).times(2);
    EasyMock.expect(adminClient.deleteRecords(recordsToDelete)).andReturn(deleteRecordsResult).times(2);
    replay();
    taskManager.maybePurgeCommitedRecords();
    taskManager.maybePurgeCommitedRecords();
    verify(active, adminClient);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) TopicPartition(org.apache.kafka.common.TopicPartition) DeletedRecords(org.apache.kafka.clients.admin.DeletedRecords) RecordsToDelete(org.apache.kafka.clients.admin.RecordsToDelete) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DeleteRecordsResult(org.apache.kafka.clients.admin.DeleteRecordsResult) Test(org.junit.Test)

Example 2 with DeleteRecordsResult

use of org.apache.kafka.clients.admin.DeleteRecordsResult in project apache-kafka-on-k8s by banzaicloud.

the class TaskManagerTest method shouldIgnorePurgeDataErrors.

@Test
public void shouldIgnorePurgeDataErrors() {
    final KafkaFutureImpl<DeletedRecords> futureDeletedRecords = new KafkaFutureImpl<>();
    final Map<TopicPartition, RecordsToDelete> recordsToDelete = Collections.singletonMap(t1p1, RecordsToDelete.beforeOffset(5L));
    final DeleteRecordsResult deleteRecordsResult = new DeleteRecordsResult(Collections.singletonMap(t1p1, (KafkaFuture<DeletedRecords>) futureDeletedRecords));
    futureDeletedRecords.completeExceptionally(new Exception("KABOOM!"));
    EasyMock.expect(active.recordsToDelete()).andReturn(Collections.singletonMap(t1p1, 5L)).times(2);
    EasyMock.expect(adminClient.deleteRecords(recordsToDelete)).andReturn(deleteRecordsResult).times(2);
    replay();
    taskManager.maybePurgeCommitedRecords();
    taskManager.maybePurgeCommitedRecords();
    verify(active, adminClient);
}
Also used : KafkaFuture(org.apache.kafka.common.KafkaFuture) TopicPartition(org.apache.kafka.common.TopicPartition) DeletedRecords(org.apache.kafka.clients.admin.DeletedRecords) RecordsToDelete(org.apache.kafka.clients.admin.RecordsToDelete) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DeleteRecordsResult(org.apache.kafka.clients.admin.DeleteRecordsResult) StreamsException(org.apache.kafka.streams.errors.StreamsException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with DeleteRecordsResult

use of org.apache.kafka.clients.admin.DeleteRecordsResult in project apache-kafka-on-k8s by banzaicloud.

the class TaskManagerTest method shouldNotSendPurgeDataIfPreviousNotDone.

@Test
public void shouldNotSendPurgeDataIfPreviousNotDone() {
    final KafkaFuture<DeletedRecords> futureDeletedRecords = new KafkaFutureImpl<>();
    final Map<TopicPartition, RecordsToDelete> recordsToDelete = Collections.singletonMap(t1p1, RecordsToDelete.beforeOffset(5L));
    final DeleteRecordsResult deleteRecordsResult = new DeleteRecordsResult(Collections.singletonMap(t1p1, futureDeletedRecords));
    EasyMock.expect(active.recordsToDelete()).andReturn(Collections.singletonMap(t1p1, 5L)).once();
    EasyMock.expect(adminClient.deleteRecords(recordsToDelete)).andReturn(deleteRecordsResult).once();
    replay();
    taskManager.maybePurgeCommitedRecords();
    // second call should be no-op as the previous one is not done yet
    taskManager.maybePurgeCommitedRecords();
    verify(active, adminClient);
}
Also used : TopicPartition(org.apache.kafka.common.TopicPartition) DeletedRecords(org.apache.kafka.clients.admin.DeletedRecords) RecordsToDelete(org.apache.kafka.clients.admin.RecordsToDelete) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DeleteRecordsResult(org.apache.kafka.clients.admin.DeleteRecordsResult) Test(org.junit.Test)

Example 4 with DeleteRecordsResult

use of org.apache.kafka.clients.admin.DeleteRecordsResult in project kafka by apache.

the class TaskManagerTest method shouldSendPurgeData.

@Test
public void shouldSendPurgeData() {
    resetToStrict(adminClient);
    expect(adminClient.deleteRecords(singletonMap(t1p1, RecordsToDelete.beforeOffset(5L)))).andReturn(new DeleteRecordsResult(singletonMap(t1p1, completedFuture())));
    expect(adminClient.deleteRecords(singletonMap(t1p1, RecordsToDelete.beforeOffset(17L)))).andReturn(new DeleteRecordsResult(singletonMap(t1p1, completedFuture())));
    replay(adminClient);
    final Map<TopicPartition, Long> purgableOffsets = new HashMap<>();
    final StateMachineTask task00 = new StateMachineTask(taskId00, taskId00Partitions, true) {

        @Override
        public Map<TopicPartition, Long> purgeableOffsets() {
            return purgableOffsets;
        }
    };
    expectRestoreToBeCompleted(consumer, changeLogReader);
    expect(activeTaskCreator.createTasks(anyObject(), eq(taskId00Assignment))).andStubReturn(singletonList(task00));
    replay(activeTaskCreator, consumer, changeLogReader);
    taskManager.handleAssignment(taskId00Assignment, emptyMap());
    assertThat(taskManager.tryToCompleteRestoration(time.milliseconds(), null), is(true));
    assertThat(task00.state(), is(Task.State.RUNNING));
    purgableOffsets.put(t1p1, 5L);
    taskManager.maybePurgeCommittedRecords();
    purgableOffsets.put(t1p1, 17L);
    taskManager.maybePurgeCommittedRecords();
    verify(adminClient);
}
Also used : HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) DeleteRecordsResult(org.apache.kafka.clients.admin.DeleteRecordsResult) Test(org.junit.Test)

Example 5 with DeleteRecordsResult

use of org.apache.kafka.clients.admin.DeleteRecordsResult in project kafka by apache.

the class TaskManagerTest method shouldNotSendPurgeDataIfPreviousNotDone.

@Test
public void shouldNotSendPurgeDataIfPreviousNotDone() {
    resetToStrict(adminClient);
    final KafkaFutureImpl<DeletedRecords> futureDeletedRecords = new KafkaFutureImpl<>();
    expect(adminClient.deleteRecords(singletonMap(t1p1, RecordsToDelete.beforeOffset(5L)))).andReturn(new DeleteRecordsResult(singletonMap(t1p1, futureDeletedRecords)));
    replay(adminClient);
    final Map<TopicPartition, Long> purgableOffsets = new HashMap<>();
    final StateMachineTask task00 = new StateMachineTask(taskId00, taskId00Partitions, true) {

        @Override
        public Map<TopicPartition, Long> purgeableOffsets() {
            return purgableOffsets;
        }
    };
    expectRestoreToBeCompleted(consumer, changeLogReader);
    expect(activeTaskCreator.createTasks(anyObject(), eq(taskId00Assignment))).andStubReturn(singletonList(task00));
    replay(activeTaskCreator, consumer, changeLogReader);
    taskManager.handleAssignment(taskId00Assignment, emptyMap());
    assertThat(taskManager.tryToCompleteRestoration(time.milliseconds(), null), is(true));
    assertThat(task00.state(), is(Task.State.RUNNING));
    purgableOffsets.put(t1p1, 5L);
    taskManager.maybePurgeCommittedRecords();
    // this call should be a no-op.
    // this is verified, as there is no expectation on adminClient for this second call,
    // so it would fail verification if we invoke the admin client again.
    purgableOffsets.put(t1p1, 17L);
    taskManager.maybePurgeCommittedRecords();
    verify(adminClient);
}
Also used : HashMap(java.util.HashMap) TopicPartition(org.apache.kafka.common.TopicPartition) DeletedRecords(org.apache.kafka.clients.admin.DeletedRecords) KafkaFutureImpl(org.apache.kafka.common.internals.KafkaFutureImpl) DeleteRecordsResult(org.apache.kafka.clients.admin.DeleteRecordsResult) Test(org.junit.Test)

Aggregations

DeleteRecordsResult (org.apache.kafka.clients.admin.DeleteRecordsResult)6 Test (org.junit.Test)6 DeletedRecords (org.apache.kafka.clients.admin.DeletedRecords)5 TopicPartition (org.apache.kafka.common.TopicPartition)5 KafkaFutureImpl (org.apache.kafka.common.internals.KafkaFutureImpl)5 RecordsToDelete (org.apache.kafka.clients.admin.RecordsToDelete)3 HashMap (java.util.HashMap)2 KafkaFuture (org.apache.kafka.common.KafkaFuture)2 StreamsException (org.apache.kafka.streams.errors.StreamsException)2 IOException (java.io.IOException)1 CommitFailedException (org.apache.kafka.clients.consumer.CommitFailedException)1 KafkaException (org.apache.kafka.common.KafkaException)1 TimeoutException (org.apache.kafka.common.errors.TimeoutException)1 LockException (org.apache.kafka.streams.errors.LockException)1 TaskCorruptedException (org.apache.kafka.streams.errors.TaskCorruptedException)1 TaskMigratedException (org.apache.kafka.streams.errors.TaskMigratedException)1