use of org.apache.kafka.test.MockProcessorSupplier in project kafka by apache.
the class StreamPartitionAssignorTest method testAssignWithInternalTopics.
@Test
public void testAssignWithInternalTopics() throws Exception {
String applicationId = "test";
builder.setApplicationId(applicationId);
builder.addInternalTopic("topicX");
builder.addSource("source1", "topic1");
builder.addProcessor("processor1", new MockProcessorSupplier(), "source1");
builder.addSink("sink1", "topicX", "processor1");
builder.addSource("source2", "topicX");
builder.addProcessor("processor2", new MockProcessorSupplier(), "source2");
List<String> topics = Utils.mkList("topic1", "test-topicX");
Set<TaskId> allTasks = Utils.mkSet(task0, task1, task2);
UUID uuid1 = UUID.randomUUID();
String client1 = "client1";
StreamThread thread10 = new StreamThread(builder, config, mockClientSupplier, applicationId, client1, uuid1, new Metrics(), Time.SYSTEM, new StreamsMetadataState(builder, StreamsMetadataState.UNKNOWN_HOST), 0);
partitionAssignor.configure(config.getConsumerConfigs(thread10, applicationId, client1));
MockInternalTopicManager internalTopicManager = new MockInternalTopicManager(thread10.config, mockClientSupplier.restoreConsumer);
partitionAssignor.setInternalTopicManager(internalTopicManager);
Map<String, PartitionAssignor.Subscription> subscriptions = new HashMap<>();
Set<TaskId> emptyTasks = Collections.emptySet();
subscriptions.put("consumer10", new PartitionAssignor.Subscription(topics, new SubscriptionInfo(uuid1, emptyTasks, emptyTasks, userEndPoint).encode()));
partitionAssignor.assign(metadata, subscriptions);
// check prepared internal topics
assertEquals(1, internalTopicManager.readyTopics.size());
assertEquals(allTasks.size(), (long) internalTopicManager.readyTopics.get("test-topicX"));
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class TopologyTest method addProcessorWithStore.
private TopologyDescription.Processor addProcessorWithStore(final String processorName, final String[] storeNames, final boolean newStores, final TopologyDescription.Node... parents) {
final String[] parentNames = new String[parents.length];
for (int i = 0; i < parents.length; ++i) {
parentNames[i] = parents[i].name();
}
topology.addProcessor(processorName, new MockProcessorSupplier(), parentNames);
if (newStores) {
for (final String store : storeNames) {
final StoreBuilder storeBuilder = EasyMock.createNiceMock(StoreBuilder.class);
EasyMock.expect(storeBuilder.name()).andReturn(store).anyTimes();
EasyMock.replay(storeBuilder);
topology.addStateStore(storeBuilder, processorName);
}
} else {
topology.connectProcessorAndStateStores(processorName, storeNames);
}
final TopologyDescription.Processor expectedProcessorNode = new InternalTopologyBuilder.Processor(processorName, new HashSet<>(Arrays.asList(storeNames)));
for (final TopologyDescription.Node parent : parents) {
((InternalTopologyBuilder.AbstractNode) parent).addSuccessor(expectedProcessorNode);
((InternalTopologyBuilder.AbstractNode) expectedProcessorNode).addPredecessor(parent);
}
return expectedProcessorNode;
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class TopologyTest method addGlobalStoreToTopologyAndExpectedDescription.
private void addGlobalStoreToTopologyAndExpectedDescription(final String globalStoreName, final String sourceName, final String globalTopicName, final String processorName, final int id) {
final KeyValueStoreBuilder globalStoreBuilder = EasyMock.createNiceMock(KeyValueStoreBuilder.class);
EasyMock.expect(globalStoreBuilder.name()).andReturn(globalStoreName).anyTimes();
EasyMock.replay(globalStoreBuilder);
topology.addGlobalStore(globalStoreBuilder, sourceName, null, null, null, globalTopicName, processorName, new MockProcessorSupplier());
final TopologyDescription.GlobalStore expectedGlobalStore = new InternalTopologyBuilder.GlobalStore(sourceName, processorName, globalStoreName, globalTopicName, id);
expectedDescription.addGlobalStore(expectedGlobalStore);
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class TopologyTest method shouldNotAllowToAddProcessorWithSameName.
@Test
public void shouldNotAllowToAddProcessorWithSameName() {
topology.addSource("source", "topic-1");
topology.addProcessor("processor", new MockProcessorSupplier(), "source");
try {
topology.addProcessor("processor", new MockProcessorSupplier(), "source");
fail("Should throw TopologyException for duplicate processor name");
} catch (TopologyException expected) {
}
}
use of org.apache.kafka.test.MockProcessorSupplier in project apache-kafka-on-k8s by banzaicloud.
the class TopologyTest method shouldNotAllowToAddGlobalStoreWithSourceNameEqualsProcessorName.
@Test(expected = TopologyException.class)
public void shouldNotAllowToAddGlobalStoreWithSourceNameEqualsProcessorName() {
EasyMock.expect(globalStoreBuilder.name()).andReturn("anyName").anyTimes();
EasyMock.replay(globalStoreBuilder);
topology.addGlobalStore(globalStoreBuilder, "sameName", null, null, "anyTopicName", "sameName", new MockProcessorSupplier());
}
Aggregations