use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class HighAvailabilityStreamsPartitionAssignorTest method shouldScheduleProbingRebalanceOnThisClientIfWarmupTasksRequired.
@Test
public void shouldScheduleProbingRebalanceOnThisClientIfWarmupTasksRequired() {
final long rebalanceInterval = 5 * 60 * 1000L;
builder.addSource(null, "source1", null, null, null, "topic1");
builder.addProcessor("processor1", new MockApiProcessorSupplier<>(), "source1");
builder.addStateStore(new MockKeyValueStoreBuilder("store1", false), "processor1");
final Set<TaskId> allTasks = mkSet(TASK_0_0, TASK_0_1, TASK_0_2);
createMockTaskManager(allTasks);
createMockAdminClient(getTopicPartitionOffsetsMap(singletonList(APPLICATION_ID + "-store1-changelog"), singletonList(3)));
configurePartitionAssignorWith(singletonMap(StreamsConfig.PROBING_REBALANCE_INTERVAL_MS_CONFIG, rebalanceInterval));
final String firstConsumer = "consumer1";
final String newConsumer = "consumer2";
subscriptions.put(firstConsumer, new Subscription(singletonList("source1"), getInfo(UUID_1, allTasks).encode()));
subscriptions.put(newConsumer, new Subscription(singletonList("source1"), getInfo(UUID_2, EMPTY_TASKS).encode()));
final Map<String, Assignment> assignments = partitionAssignor.assign(metadata, new GroupSubscription(subscriptions)).groupAssignment();
final List<TaskId> firstConsumerActiveTasks = AssignmentInfo.decode(assignments.get(firstConsumer).userData()).activeTasks();
final List<TaskId> newConsumerActiveTasks = AssignmentInfo.decode(assignments.get(newConsumer).userData()).activeTasks();
final ArrayList<TaskId> sortedExpectedTasks = new ArrayList<>(allTasks);
Collections.sort(sortedExpectedTasks);
assertThat(firstConsumerActiveTasks, equalTo(sortedExpectedTasks));
assertThat(newConsumerActiveTasks, empty());
assertThat(referenceContainer.assignmentErrorCode.get(), equalTo(AssignorError.NONE.code()));
final long nextScheduledRebalanceOnThisClient = AssignmentInfo.decode(assignments.get(firstConsumer).userData()).nextRebalanceMs();
final long nextScheduledRebalanceOnOtherClient = AssignmentInfo.decode(assignments.get(newConsumer).userData()).nextRebalanceMs();
assertThat(nextScheduledRebalanceOnThisClient, equalTo(time.milliseconds() + rebalanceInterval));
assertThat(nextScheduledRebalanceOnOtherClient, equalTo(Long.MAX_VALUE));
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method testPatternSourceTopicsWithGlobalTopics.
@Test
public void testPatternSourceTopicsWithGlobalTopics() {
builder.setApplicationId("X");
builder.addSource(null, "source-1", null, null, null, Pattern.compile("topic-1"));
builder.addSource(null, "source-2", null, null, null, Pattern.compile("topic-2"));
builder.addGlobalStore(new MockKeyValueStoreBuilder("global-store", false).withLoggingDisabled(), "globalSource", null, null, null, "globalTopic", "global-processor", new MockApiProcessorSupplier<>());
builder.initializeSubscription();
final Pattern expectedPattern = Pattern.compile("topic-1|topic-2");
final String patternString = builder.sourceTopicsPatternString();
assertEquals(expectedPattern.pattern(), Pattern.compile(patternString).pattern());
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method shouldNotAllowToAddGlobalStoresWithSameName.
@Test
public void shouldNotAllowToAddGlobalStoresWithSameName() {
final StoreBuilder<KeyValueStore<Object, Object>> firstGlobalBuilder = new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled();
final StoreBuilder<KeyValueStore<Object, Object>> secondGlobalBuilder = new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled();
builder.addGlobalStore(firstGlobalBuilder, "global-store", null, null, null, "global-topic", "global-processor", new MockApiProcessorSupplier<>());
final TopologyException exception = assertThrows(TopologyException.class, () -> builder.addGlobalStore(secondGlobalBuilder, "global-store-2", null, null, null, "global-topic", "global-processor-2", new MockApiProcessorSupplier<>()));
assertThat(exception.getMessage(), equalTo("Invalid topology: A different GlobalStateStore has already been added with the name testStore"));
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class RegexSourceIntegrationTest method shouldAddStateStoreToRegexDefinedSource.
@Test
public void shouldAddStateStoreToRegexDefinedSource() throws Exception {
final StoreBuilder<KeyValueStore<Object, Object>> storeBuilder = new MockKeyValueStoreBuilder("testStateStore", false);
final long thirtySecondTimeout = 30 * 1000;
final TopologyWrapper topology = new TopologyWrapper();
topology.addSource("ingest", Pattern.compile("topic-\\d+"));
topology.addProcessor("my-processor", new MockApiProcessorSupplier<>(), "ingest");
topology.addStateStore(storeBuilder, "my-processor");
streams = new KafkaStreams(topology, streamsConfiguration);
streams.start();
final TestCondition stateStoreNameBoundToSourceTopic = () -> {
final Map<String, List<String>> stateStoreToSourceTopic = topology.getInternalBuilder().stateStoreNameToFullSourceTopicNames();
final List<String> topicNamesList = stateStoreToSourceTopic.get("testStateStore");
return topicNamesList != null && !topicNamesList.isEmpty() && topicNamesList.get(0).equals("topic-1");
};
TestUtils.waitForCondition(stateStoreNameBoundToSourceTopic, thirtySecondTimeout, "Did not find topic: [topic-1] connected to state store: [testStateStore]");
}
use of org.apache.kafka.test.MockKeyValueStoreBuilder in project kafka by apache.
the class InternalTopologyBuilderTest method shouldNotAllowToAddStoresWithSameNameWhenFirstStoreIsGlobal.
@Test
public void shouldNotAllowToAddStoresWithSameNameWhenFirstStoreIsGlobal() {
final StoreBuilder<KeyValueStore<Object, Object>> globalBuilder = new MockKeyValueStoreBuilder("testStore", false).withLoggingDisabled();
builder.addGlobalStore(globalBuilder, "global-store", null, null, null, "global-topic", "global-processor", new MockApiProcessorSupplier<>());
final TopologyException exception = assertThrows(TopologyException.class, () -> builder.addStateStore(storeBuilder));
assertThat(exception.getMessage(), equalTo("Invalid topology: A different GlobalStateStore has already been added with the name testStore"));
}
Aggregations