use of org.apache.samza.application.SamzaApplication in project samza by apache.
the class LocalApplicationRunnerMain method main.
public static void main(String[] args) {
ApplicationRunnerMain.ApplicationRunnerCommandLine cmdLine = new ApplicationRunnerMain.ApplicationRunnerCommandLine();
OptionSet options = cmdLine.parser().parse(args);
Config orgConfig = cmdLine.loadConfig(options);
Config config = ConfigUtil.rewriteConfig(orgConfig);
SamzaApplication app = ApplicationUtil.fromConfig(config);
ApplicationRunner runner = ApplicationRunners.getApplicationRunner(app, config);
try {
LOGGER.info("Launching stream application: {} to run.", app);
runner.run(buildExternalContext(config).orElse(null));
runner.waitForFinish();
} catch (Exception e) {
LOGGER.error("Exception occurred when running application: {}.", app, e);
}
}
use of org.apache.samza.application.SamzaApplication in project samza by apache.
the class TransactionalStateMultiStoreIntegrationTest method initialRun.
private void initialRun(List<String> inputMessages, List<String> expectedChangelogMessages) {
// create input topic and produce the first batch of input messages
createTopic(INPUT_TOPIC, 1);
inputMessages.forEach(m -> produceMessage(INPUT_TOPIC, 0, m, m));
// verify that the input messages were produced successfully
if (inputMessages.size() > 0) {
List<ConsumerRecord<String, String>> inputRecords = consumeMessages(INPUT_TOPIC, inputMessages.size());
List<String> readInputMessages = inputRecords.stream().map(ConsumerRecord::value).collect(Collectors.toList());
Assert.assertEquals(inputMessages, readInputMessages);
}
SamzaApplication app = new MyStatefulApplication(INPUT_SYSTEM, INPUT_TOPIC, ImmutableMap.of(STORE_1_NAME, STORE_1_CHANGELOG, STORE_2_NAME, STORE_2_CHANGELOG));
// run the application
RunApplicationContext context = runApplication(app, APP_NAME, CONFIGS);
// consume and verify the changelog messages
if (expectedChangelogMessages.size() > 0) {
List<ConsumerRecord<String, String>> changelogRecords = consumeMessages(STORE_1_CHANGELOG, expectedChangelogMessages.size());
List<String> changelogMessages = changelogRecords.stream().map(ConsumerRecord::value).collect(Collectors.toList());
Assert.assertEquals(expectedChangelogMessages, changelogMessages);
}
// wait for the application to finish
context.getRunner().waitForFinish();
LOG.info("Finished initial run");
}
use of org.apache.samza.application.SamzaApplication in project samza by apache.
the class TransactionalStateMultiStoreIntegrationTest method secondRun.
private void secondRun(String changelogTopic, List<String> expectedChangelogMessages, List<String> expectedInitialStoreContents) {
// clear the local store directory
if (!hostAffinity) {
new FileUtil().rm(new File(LOGGED_STORE_BASE_DIR));
}
// produce the second batch of input messages
List<String> inputMessages = Arrays.asList("4", "5", "5", ":shutdown");
inputMessages.forEach(m -> produceMessage(INPUT_TOPIC, 0, m, m));
SamzaApplication app = new MyStatefulApplication(INPUT_SYSTEM, INPUT_TOPIC, ImmutableMap.of(STORE_1_NAME, changelogTopic, STORE_2_NAME, STORE_2_CHANGELOG));
// run the application
RunApplicationContext context = runApplication(app, APP_NAME, CONFIGS);
// wait for the application to finish
context.getRunner().waitForFinish();
// consume and verify any additional changelog messages
List<ConsumerRecord<String, String>> changelogRecords = consumeMessages(changelogTopic, expectedChangelogMessages.size());
List<String> changelogMessages = changelogRecords.stream().map(ConsumerRecord::value).collect(Collectors.toList());
Assert.assertEquals(expectedChangelogMessages, changelogMessages);
// verify the store contents during startup (this is after changelog verification to ensure init has completed)
Assert.assertEquals(expectedInitialStoreContents, MyStatefulApplication.getInitialStoreContents().get(STORE_1_NAME));
}
Aggregations