org.apache.samza.application.TaskApplication Java Examples

The following examples show how to use org.apache.samza.application.TaskApplication. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationDescriptorUtil.java    From samza with Apache License 2.0 5 votes vote down vote up
/**
 * Create a new instance of {@link ApplicationDescriptorImpl} based on {@link SamzaApplication} and {@link Config}
 *
 * @param app an implementation of {@link SamzaApplication}. The {@code app} has to have a proper fully-qualified class name.
 * @param config the {@link Config} for the application
 * @return the {@link ApplicationDescriptorImpl} instance containing the processing logic and the config
 */
public static ApplicationDescriptorImpl<? extends ApplicationDescriptor> getAppDescriptor(SamzaApplication app, Config config) {
  if (app instanceof StreamApplication) {
    return new StreamApplicationDescriptorImpl((StreamApplication) app, config);
  }
  if (app instanceof TaskApplication) {
    return new TaskApplicationDescriptorImpl((TaskApplication) app, config);
  }
  throw new IllegalArgumentException(String.format("User application class %s is not supported. Only StreamApplication "
      + "and TaskApplication are supported.", app.getClass().getName()));
}
 
Example #2
Source File: TestTaskApplicationDescriptorImpl.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testConstructor() {
  TaskApplication mockApp = mock(TaskApplication.class);
  TaskApplicationDescriptorImpl appDesc = new TaskApplicationDescriptorImpl(mockApp, config);
  verify(mockApp).describe(appDesc);
  assertEquals(config, appDesc.getConfig());
}
 
Example #3
Source File: TestTaskApplicationDescriptorImpl.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplicationContainerContextFactory() {
  ApplicationContainerContextFactory factory = mock(ApplicationContainerContextFactory.class);
  TaskApplication testApp = appDesc -> appDesc.withApplicationContainerContextFactory(factory);
  TaskApplicationDescriptorImpl appSpec = new TaskApplicationDescriptorImpl(testApp, mock(Config.class));
  assertEquals(appSpec.getApplicationContainerContextFactory(), Optional.of(factory));
}
 
Example #4
Source File: TestTaskApplicationDescriptorImpl.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoApplicationContainerContextFactory() {
  TaskApplication testApp = appDesc -> {
  };
  TaskApplicationDescriptorImpl appSpec = new TaskApplicationDescriptorImpl(testApp, mock(Config.class));
  assertEquals(appSpec.getApplicationContainerContextFactory(), Optional.empty());
}
 
Example #5
Source File: TestTaskApplicationDescriptorImpl.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplicationTaskContextFactory() {
  ApplicationTaskContextFactory factory = mock(ApplicationTaskContextFactory.class);
  TaskApplication testApp = appDesc -> appDesc.withApplicationTaskContextFactory(factory);
  TaskApplicationDescriptorImpl appSpec = new TaskApplicationDescriptorImpl(testApp, mock(Config.class));
  assertEquals(appSpec.getApplicationTaskContextFactory(), Optional.of(factory));
}
 
Example #6
Source File: TestTaskApplicationDescriptorImpl.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoApplicationTaskContextFactory() {
  TaskApplication testApp = appDesc -> {
  };
  TaskApplicationDescriptorImpl appSpec = new TaskApplicationDescriptorImpl(testApp, mock(Config.class));
  assertEquals(appSpec.getApplicationTaskContextFactory(), Optional.empty());
}
 
Example #7
Source File: ExecutionPlannerTestBase.java    From samza with Apache License 2.0 5 votes vote down vote up
TaskApplication getTaskApplication() {
  return appDesc -> {
    appDesc.withInputStream(input1Descriptor)
        .withInputStream(input2Descriptor)
        .withInputStream(intermediateInputDescriptor)
        .withOutputStream(intermediateOutputDescriptor)
        .withOutputStream(outputDescriptor)
        .withTaskFactory(() -> new IdentityStreamTask());
  };
}
 
Example #8
Source File: TestZkLocalApplicationRunner.java    From samza with Apache License 2.0 5 votes vote down vote up
@Test
public void testApplicationShutdownShouldBeIndependentOfPerMessageProcessingTime() throws Exception {
  publishKafkaEvents(inputKafkaTopic, 0, NUM_KAFKA_EVENTS, PROCESSOR_IDS[0]);

  // Create a TaskApplication with only one task per container.
  // The task does not invokes taskCallback.complete for any of the dispatched message.
  CountDownLatch shutdownLatch = new CountDownLatch(1);
  CountDownLatch processedMessagesLatch1 = new CountDownLatch(1);

  TaskApplication taskApplication = new TestTaskApplication(TEST_SYSTEM, inputKafkaTopic, outputKafkaTopic, processedMessagesLatch1, shutdownLatch);
  MapConfig taskApplicationConfig = new MapConfig(ImmutableList.of(applicationConfig1,
      ImmutableMap.of(TaskConfig.MAX_CONCURRENCY, "1", JobConfig.SSP_GROUPER_FACTORY, "org.apache.samza.container.grouper.stream.AllSspToSingleTaskGrouperFactory")));
  ApplicationRunner appRunner = ApplicationRunners.getApplicationRunner(taskApplication, taskApplicationConfig);

  // Run the application.
  executeRun(appRunner, applicationConfig1);

  // Wait for the task to receive at least one dispatched message.
  processedMessagesLatch1.await();

  // Kill the application when none of the dispatched messages is acknowledged as completed by the task.
  appRunner.kill();
  appRunner.waitForFinish();

  // Expect the shutdown latch to be triggered.
  shutdownLatch.await();

  // Assert that the shutdown was successful.
  Assert.assertEquals(ApplicationStatus.SuccessfulFinish, appRunner.status());
}
 
Example #9
Source File: TaskApplicationDescriptorImpl.java    From samza with Apache License 2.0 4 votes vote down vote up
public TaskApplicationDescriptorImpl(TaskApplication userApp, Config config) {
  super(userApp, config);
  userApp.describe(this);
}
 
Example #10
Source File: ExecutionPlannerTestBase.java    From samza with Apache License 2.0 4 votes vote down vote up
TaskApplication getLegacyTaskApplication() {
  return new LegacyTaskApplication(IdentityStreamTask.class.getName());
}