use of org.apache.kafka.clients.admin.AdminClient in project kafka by apache.
the class InternalTopicManagerTest method shouldCleanUpWhenUnexpectedExceptionIsThrownDuringSetup.
@Test
public void shouldCleanUpWhenUnexpectedExceptionIsThrownDuringSetup() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final StreamsConfig streamsConfig = new StreamsConfig(config);
final MockTime time = new MockTime((Integer) config.get(StreamsConfig.consumerPrefix(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG)) / 3);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
final InternalTopicConfig internalTopicConfig1 = setupRepartitionTopicConfig(topic1, 1);
final InternalTopicConfig internalTopicConfig2 = setupRepartitionTopicConfig(topic2, 1);
setupCleanUpScenario(admin, streamsConfig, internalTopicConfig1, internalTopicConfig2);
final KafkaFutureImpl<Void> deleteTopicSuccessfulFuture = new KafkaFutureImpl<>();
deleteTopicSuccessfulFuture.complete(null);
EasyMock.expect(admin.deleteTopics(mkSet(topic1))).andAnswer(() -> new MockDeleteTopicsResult(mkMap(mkEntry(topic1, deleteTopicSuccessfulFuture))));
EasyMock.replay(admin);
assertThrows(StreamsException.class, () -> topicManager.setup(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(topic2, internalTopicConfig2))));
EasyMock.verify(admin);
}
use of org.apache.kafka.clients.admin.AdminClient in project kafka by apache.
the class InternalTopicManagerTest method shouldThrowWhenCreateTopicsResultsDoNotContainTopic.
@Test
public void shouldThrowWhenCreateTopicsResultsDoNotContainTopic() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final StreamsConfig streamsConfig = new StreamsConfig(config);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
final NewTopic newTopic = newTopic(topic1, internalTopicConfig, streamsConfig);
EasyMock.expect(admin.createTopics(mkSet(newTopic))).andStubAnswer(() -> new MockCreateTopicsResult(Collections.singletonMap(topic2, new KafkaFutureImpl<>())));
EasyMock.replay(admin);
assertThrows(IllegalStateException.class, () -> topicManager.setup(Collections.singletonMap(topic1, internalTopicConfig)));
}
use of org.apache.kafka.clients.admin.AdminClient in project kafka by apache.
the class InternalTopicManagerTest method shouldOnlyRetryNotSuccessfulFuturesDuringSetup.
@Test
public void shouldOnlyRetryNotSuccessfulFuturesDuringSetup() {
final AdminClient admin = EasyMock.createMock(AdminClient.class);
final StreamsConfig streamsConfig = new StreamsConfig(config);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
final KafkaFutureImpl<TopicMetadataAndConfig> createTopicFailFuture = new KafkaFutureImpl<>();
createTopicFailFuture.completeExceptionally(new TopicExistsException("exists"));
final KafkaFutureImpl<TopicMetadataAndConfig> createTopicSuccessfulFuture = new KafkaFutureImpl<>();
createTopicSuccessfulFuture.complete(new TopicMetadataAndConfig(Uuid.randomUuid(), 1, 1, new Config(Collections.emptyList())));
final InternalTopicConfig internalTopicConfig1 = setupRepartitionTopicConfig(topic1, 1);
final InternalTopicConfig internalTopicConfig2 = setupRepartitionTopicConfig(topic2, 1);
final NewTopic newTopic1 = newTopic(topic1, internalTopicConfig1, streamsConfig);
final NewTopic newTopic2 = newTopic(topic2, internalTopicConfig2, streamsConfig);
EasyMock.expect(admin.createTopics(mkSet(newTopic1, newTopic2))).andAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic1, createTopicSuccessfulFuture), mkEntry(topic2, createTopicFailFuture))));
EasyMock.expect(admin.createTopics(mkSet(newTopic2))).andAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic2, createTopicSuccessfulFuture))));
EasyMock.replay(admin);
topicManager.setup(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(topic2, internalTopicConfig2)));
EasyMock.verify(admin);
}
use of org.apache.kafka.clients.admin.AdminClient in project kafka by apache.
the class InternalTopicManagerTest method shouldCleanUpWhenCreateTopicsResultsDoNotContainTopic.
@Test
public void shouldCleanUpWhenCreateTopicsResultsDoNotContainTopic() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final StreamsConfig streamsConfig = new StreamsConfig(config);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
final InternalTopicConfig internalTopicConfig1 = setupRepartitionTopicConfig(topic1, 1);
final InternalTopicConfig internalTopicConfig2 = setupRepartitionTopicConfig(topic2, 1);
final KafkaFutureImpl<TopicMetadataAndConfig> createTopicFailFuture1 = new KafkaFutureImpl<>();
createTopicFailFuture1.completeExceptionally(new TopicExistsException("exists"));
final KafkaFutureImpl<TopicMetadataAndConfig> createTopicSuccessfulFuture = new KafkaFutureImpl<>();
createTopicSuccessfulFuture.complete(new TopicMetadataAndConfig(Uuid.randomUuid(), 1, 1, new Config(Collections.emptyList())));
final NewTopic newTopic1 = newTopic(topic1, internalTopicConfig1, streamsConfig);
final NewTopic newTopic2 = newTopic(topic2, internalTopicConfig2, streamsConfig);
EasyMock.expect(admin.createTopics(mkSet(newTopic1, newTopic2))).andAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic1, createTopicSuccessfulFuture), mkEntry(topic2, createTopicFailFuture1))));
EasyMock.expect(admin.createTopics(mkSet(newTopic2))).andAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic3, createTopicSuccessfulFuture))));
final KafkaFutureImpl<Void> deleteTopicSuccessfulFuture = new KafkaFutureImpl<>();
deleteTopicSuccessfulFuture.complete(null);
EasyMock.expect(admin.deleteTopics(mkSet(topic1))).andAnswer(() -> new MockDeleteTopicsResult(mkMap(mkEntry(topic1, deleteTopicSuccessfulFuture))));
EasyMock.replay(admin);
assertThrows(IllegalStateException.class, () -> topicManager.setup(mkMap(mkEntry(topic1, internalTopicConfig1), mkEntry(topic2, internalTopicConfig2))));
EasyMock.verify(admin);
}
use of org.apache.kafka.clients.admin.AdminClient in project kafka by apache.
the class InternalTopicManagerTest method shouldThrowTimeoutExceptionWhenCreateTopicExceedsTimeout.
@Test
public void shouldThrowTimeoutExceptionWhenCreateTopicExceedsTimeout() {
final AdminClient admin = EasyMock.createNiceMock(AdminClient.class);
final MockTime time = new MockTime((Integer) config.get(StreamsConfig.consumerPrefix(ConsumerConfig.MAX_POLL_INTERVAL_MS_CONFIG)) / 3);
final StreamsConfig streamsConfig = new StreamsConfig(config);
final InternalTopicManager topicManager = new InternalTopicManager(time, admin, streamsConfig);
final KafkaFutureImpl<TopicMetadataAndConfig> createTopicFailFuture = new KafkaFutureImpl<>();
createTopicFailFuture.completeExceptionally(new TimeoutException());
final InternalTopicConfig internalTopicConfig = setupRepartitionTopicConfig(topic1, 1);
final NewTopic newTopic = newTopic(topic1, internalTopicConfig, streamsConfig);
EasyMock.expect(admin.createTopics(mkSet(newTopic))).andStubAnswer(() -> new MockCreateTopicsResult(mkMap(mkEntry(topic1, createTopicFailFuture))));
EasyMock.replay(admin);
assertThrows(TimeoutException.class, () -> topicManager.setup(Collections.singletonMap(topic1, internalTopicConfig)));
}
Aggregations