use of org.apache.pulsar.functions.instance.producers.Producers in project incubator-pulsar by apache.
the class JavaInstanceRunnableProcessTest method testSetupJavaInstance.
/**
* Test the basic run logic of instance.
*/
@Test
public void testSetupJavaInstance() throws Exception {
JavaInstanceRunnable runnable = new JavaInstanceRunnable(config, fnCache, "test-jar-file", mockClient, TEST_STORAGE_SERVICE_URL);
runnable.setupJavaInstance();
// verify
// 1. verify jar is loaded
verify(fnCache, times(1)).registerFunctionInstance(eq(config.getFunctionId()), eq(config.getInstanceId()), eq(Arrays.asList("test-jar-file")), eq(Collections.emptyList()));
verify(fnCache, times(1)).getClassLoader(eq(config.getFunctionId()));
// 2. verify serde is setup
for (String inputTopic : fnConfig.getInputsList()) {
assertTrue(runnable.getInputSerDe().containsKey(inputTopic));
assertTrue(runnable.getInputSerDe().get(inputTopic) instanceof DefaultSerDe);
DefaultSerDe serDe = (DefaultSerDe) runnable.getInputSerDe().get(inputTopic);
assertEquals(String.class, Whitebox.getInternalState(serDe, "type"));
}
// 3. verify producers and consumers are setup
Producers producers = runnable.getOutputProducer();
assertTrue(producers instanceof SimpleOneOuputTopicProducers);
assertSame(mockProducers.get(Pair.of(fnConfig.getOutput(), null)).getProducer(), ((SimpleOneOuputTopicProducers) producers).getProducer());
assertEquals(mockConsumers.size(), runnable.getInputConsumers().size());
for (Map.Entry<String, Consumer> consumerEntry : runnable.getInputConsumers().entrySet()) {
String topic = consumerEntry.getKey();
Consumer mockConsumer = mockConsumers.get(Pair.of(topic, FunctionConfigUtils.getFullyQualifiedName(fnConfig))).getConsumer();
assertSame(mockConsumer, consumerEntry.getValue());
}
// 4. verify state table
assertSame(mockStorageClient, runnable.getStorageClient());
assertSame(mockTable, runnable.getStateTable());
runnable.close();
// verify close
for (ConsumerInstance consumer : mockConsumers.values()) {
verify(consumer.getConsumer(), times(1)).close();
}
assertTrue(runnable.getInputConsumers().isEmpty());
for (ProducerInstance producer : mockProducers.values()) {
verify(producer.getProducer(), times(1)).close();
}
verify(mockTable, times(1)).close();
verify(mockStorageClient, times(1)).close();
// function is unregistered
verify(fnCache, times(1)).unregisterFunctionInstance(eq(config.getFunctionId()), eq(config.getInstanceId()));
}
Aggregations