Search in sources :

Example 6 with TaskApplication

use of org.apache.samza.application.TaskApplication in project samza by apache.

the class TestTaskApplicationDescriptorImpl method testWithTaskFactory.

@Test
public void testWithTaskFactory() {
    TaskFactory mockTf = mock(TaskFactory.class);
    TaskApplication testApp = appDesc -> appDesc.withTaskFactory(mockTf);
    TaskApplicationDescriptorImpl appDesc = new TaskApplicationDescriptorImpl(testApp, config);
    assertEquals(appDesc.getTaskFactory(), mockTf);
}
Also used : InputDescriptor(org.apache.samza.system.descriptors.InputDescriptor) ApplicationContainerContextFactory(org.apache.samza.context.ApplicationContainerContextFactory) SystemDescriptor(org.apache.samza.system.descriptors.SystemDescriptor) TaskApplication(org.apache.samza.application.TaskApplication) TableDescriptor(org.apache.samza.table.descriptors.TableDescriptor) Set(java.util.Set) Test(org.junit.Test) TaskFactory(org.apache.samza.task.TaskFactory) Mockito.when(org.mockito.Mockito.when) ApplicationTaskContextFactory(org.apache.samza.context.ApplicationTaskContextFactory) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) HashSet(java.util.HashSet) List(java.util.List) BaseTableDescriptor(org.apache.samza.table.descriptors.BaseTableDescriptor) Optional(java.util.Optional) ProcessorLifecycleListenerFactory(org.apache.samza.runtime.ProcessorLifecycleListenerFactory) Config(org.apache.samza.config.Config) OutputDescriptor(org.apache.samza.system.descriptors.OutputDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) TaskFactory(org.apache.samza.task.TaskFactory) TaskApplication(org.apache.samza.application.TaskApplication) Test(org.junit.Test)

Example 7 with TaskApplication

use of org.apache.samza.application.TaskApplication in project samza by apache.

the class TestTaskApplicationDescriptorImpl method testNoApplicationTaskContextFactory.

@Test
public void testNoApplicationTaskContextFactory() {
    TaskApplication testApp = appDesc -> {
    };
    TaskApplicationDescriptorImpl appSpec = new TaskApplicationDescriptorImpl(testApp, mock(Config.class));
    assertEquals(appSpec.getApplicationTaskContextFactory(), Optional.empty());
}
Also used : InputDescriptor(org.apache.samza.system.descriptors.InputDescriptor) ApplicationContainerContextFactory(org.apache.samza.context.ApplicationContainerContextFactory) SystemDescriptor(org.apache.samza.system.descriptors.SystemDescriptor) TaskApplication(org.apache.samza.application.TaskApplication) TableDescriptor(org.apache.samza.table.descriptors.TableDescriptor) Set(java.util.Set) Test(org.junit.Test) TaskFactory(org.apache.samza.task.TaskFactory) Mockito.when(org.mockito.Mockito.when) ApplicationTaskContextFactory(org.apache.samza.context.ApplicationTaskContextFactory) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) HashSet(java.util.HashSet) List(java.util.List) BaseTableDescriptor(org.apache.samza.table.descriptors.BaseTableDescriptor) Optional(java.util.Optional) ProcessorLifecycleListenerFactory(org.apache.samza.runtime.ProcessorLifecycleListenerFactory) Config(org.apache.samza.config.Config) OutputDescriptor(org.apache.samza.system.descriptors.OutputDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Config(org.apache.samza.config.Config) TaskApplication(org.apache.samza.application.TaskApplication) Test(org.junit.Test)

Example 8 with TaskApplication

use of org.apache.samza.application.TaskApplication in project samza by apache.

the class TestZkLocalApplicationRunner method testApplicationShutdownShouldBeIndependentOfPerMessageProcessingTime.

@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());
}
Also used : ApplicationRunner(org.apache.samza.runtime.ApplicationRunner) LocalApplicationRunner(org.apache.samza.runtime.LocalApplicationRunner) TaskApplication(org.apache.samza.application.TaskApplication) MapConfig(org.apache.samza.config.MapConfig) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 9 with TaskApplication

use of org.apache.samza.application.TaskApplication in project samza by apache.

the class TestTaskApplicationDescriptorImpl method testAddOutputStreams.

@Test
public void testAddOutputStreams() {
    TaskApplication testApp = appDesc -> {
        mockOutputs.forEach(appDesc::withOutputStream);
    };
    TaskApplicationDescriptorImpl appDesc = new TaskApplicationDescriptorImpl(testApp, config);
    assertEquals(mockOutputs.toArray(), appDesc.getOutputDescriptors().values().toArray());
}
Also used : InputDescriptor(org.apache.samza.system.descriptors.InputDescriptor) ApplicationContainerContextFactory(org.apache.samza.context.ApplicationContainerContextFactory) SystemDescriptor(org.apache.samza.system.descriptors.SystemDescriptor) TaskApplication(org.apache.samza.application.TaskApplication) TableDescriptor(org.apache.samza.table.descriptors.TableDescriptor) Set(java.util.Set) Test(org.junit.Test) TaskFactory(org.apache.samza.task.TaskFactory) Mockito.when(org.mockito.Mockito.when) ApplicationTaskContextFactory(org.apache.samza.context.ApplicationTaskContextFactory) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) HashSet(java.util.HashSet) List(java.util.List) BaseTableDescriptor(org.apache.samza.table.descriptors.BaseTableDescriptor) Optional(java.util.Optional) ProcessorLifecycleListenerFactory(org.apache.samza.runtime.ProcessorLifecycleListenerFactory) Config(org.apache.samza.config.Config) OutputDescriptor(org.apache.samza.system.descriptors.OutputDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) TaskApplication(org.apache.samza.application.TaskApplication) Test(org.junit.Test)

Example 10 with TaskApplication

use of org.apache.samza.application.TaskApplication in project samza by apache.

the class TestTaskApplicationDescriptorImpl method testNoApplicationContainerContextFactory.

@Test
public void testNoApplicationContainerContextFactory() {
    TaskApplication testApp = appDesc -> {
    };
    TaskApplicationDescriptorImpl appSpec = new TaskApplicationDescriptorImpl(testApp, mock(Config.class));
    assertEquals(appSpec.getApplicationContainerContextFactory(), Optional.empty());
}
Also used : InputDescriptor(org.apache.samza.system.descriptors.InputDescriptor) ApplicationContainerContextFactory(org.apache.samza.context.ApplicationContainerContextFactory) SystemDescriptor(org.apache.samza.system.descriptors.SystemDescriptor) TaskApplication(org.apache.samza.application.TaskApplication) TableDescriptor(org.apache.samza.table.descriptors.TableDescriptor) Set(java.util.Set) Test(org.junit.Test) TaskFactory(org.apache.samza.task.TaskFactory) Mockito.when(org.mockito.Mockito.when) ApplicationTaskContextFactory(org.apache.samza.context.ApplicationTaskContextFactory) ArrayList(java.util.ArrayList) Mockito.verify(org.mockito.Mockito.verify) HashSet(java.util.HashSet) List(java.util.List) BaseTableDescriptor(org.apache.samza.table.descriptors.BaseTableDescriptor) Optional(java.util.Optional) ProcessorLifecycleListenerFactory(org.apache.samza.runtime.ProcessorLifecycleListenerFactory) Config(org.apache.samza.config.Config) OutputDescriptor(org.apache.samza.system.descriptors.OutputDescriptor) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Mockito.mock(org.mockito.Mockito.mock) Config(org.apache.samza.config.Config) TaskApplication(org.apache.samza.application.TaskApplication) Test(org.junit.Test)

Aggregations

TaskApplication (org.apache.samza.application.TaskApplication)11 Test (org.junit.Test)11 ArrayList (java.util.ArrayList)9 HashSet (java.util.HashSet)9 List (java.util.List)9 Optional (java.util.Optional)9 Set (java.util.Set)9 Config (org.apache.samza.config.Config)9 ApplicationContainerContextFactory (org.apache.samza.context.ApplicationContainerContextFactory)9 ApplicationTaskContextFactory (org.apache.samza.context.ApplicationTaskContextFactory)9 ProcessorLifecycleListenerFactory (org.apache.samza.runtime.ProcessorLifecycleListenerFactory)9 InputDescriptor (org.apache.samza.system.descriptors.InputDescriptor)9 OutputDescriptor (org.apache.samza.system.descriptors.OutputDescriptor)9 SystemDescriptor (org.apache.samza.system.descriptors.SystemDescriptor)9 BaseTableDescriptor (org.apache.samza.table.descriptors.BaseTableDescriptor)9 TableDescriptor (org.apache.samza.table.descriptors.TableDescriptor)9 TaskFactory (org.apache.samza.task.TaskFactory)9 Assert.assertEquals (org.junit.Assert.assertEquals)9 Before (org.junit.Before)9 Mockito.mock (org.mockito.Mockito.mock)9