Search in sources :

Example 16 with InMemorySystemDescriptor

use of org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor in project samza by apache.

the class TestContext method testSyncTaskWithSinglePartitionMultithreaded.

@Test
public void testSyncTaskWithSinglePartitionMultithreaded() throws Exception {
    List<Integer> inputList = Arrays.asList(1, 2, 3, 4, 5);
    List<Integer> outputList = Arrays.asList(10, 20, 30, 40, 50);
    InMemorySystemDescriptor isd = new InMemorySystemDescriptor("test");
    InMemoryInputDescriptor<Integer> imid = isd.getInputDescriptor("input", new NoOpSerde<Integer>());
    InMemoryOutputDescriptor<Integer> imod = isd.getOutputDescriptor("output", new NoOpSerde<Integer>());
    TestRunner.of(MyStreamTestTask.class).addInputStream(imid, inputList).addOutputStream(imod, 1).addConfig("job.container.thread.pool.size", "4").addExternalContext(new TestContext(10)).run(Duration.ofSeconds(1));
    StreamAssert.containsInOrder(outputList, imod, Duration.ofMillis(1000));
}
Also used : InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) Test(org.junit.Test)

Example 17 with InMemorySystemDescriptor

use of org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor in project samza by apache.

the class TestContext method testSyncTaskWithSinglePartition.

@Test
public void testSyncTaskWithSinglePartition() throws Exception {
    List<Integer> inputList = Arrays.asList(1, 2, 3, 4, 5);
    List<Integer> outputList = Arrays.asList(10, 20, 30, 40, 50);
    InMemorySystemDescriptor isd = new InMemorySystemDescriptor("test");
    InMemoryInputDescriptor<Integer> imid = isd.getInputDescriptor("input", new NoOpSerde<Integer>());
    InMemoryOutputDescriptor<Integer> imod = isd.getOutputDescriptor("output", new NoOpSerde<Integer>());
    TestRunner.of(MyStreamTestTask.class).addInputStream(imid, inputList).addOutputStream(imod, 1).addExternalContext(new TestContext(10)).run(Duration.ofSeconds(1));
    Assert.assertThat(TestRunner.consumeStream(imod, Duration.ofMillis(1000)).get(0), IsIterableContainingInOrder.contains(outputList.toArray()));
}
Also used : InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) Test(org.junit.Test)

Example 18 with InMemorySystemDescriptor

use of org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor in project samza by apache.

the class TestContext method testSamzaJobFailureForSyncTask.

/**
 * Samza job logic expects integers, but doubles are passed here which results in failure
 */
@Test(expected = SamzaException.class)
public void testSamzaJobFailureForSyncTask() {
    List<Double> inputList = Arrays.asList(1.2, 2.3, 3.33, 4.5);
    InMemorySystemDescriptor isd = new InMemorySystemDescriptor("test");
    InMemoryInputDescriptor<Double> imid = isd.getInputDescriptor("doubles", new NoOpSerde<Double>());
    InMemoryOutputDescriptor imod = isd.getOutputDescriptor("output", new NoOpSerde<>());
    TestRunner.of(MyStreamTestTask.class).addInputStream(imid, inputList).addOutputStream(imod, 1).addExternalContext(new TestContext(10)).run(Duration.ofSeconds(1));
}
Also used : InMemoryOutputDescriptor(org.apache.samza.test.framework.system.descriptors.InMemoryOutputDescriptor) InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) Test(org.junit.Test)

Example 19 with InMemorySystemDescriptor

use of org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor in project samza by apache.

the class AsyncStreamTaskIntegrationTest method testAsyncTaskWithSinglePartition.

@Test
public void testAsyncTaskWithSinglePartition() throws Exception {
    List<Integer> inputList = Arrays.asList(1, 2, 3, 4, 5);
    List<Integer> outputList = Arrays.asList(10, 20, 30, 40, 50);
    InMemorySystemDescriptor isd = new InMemorySystemDescriptor("async-test");
    InMemoryInputDescriptor<Integer> imid = isd.getInputDescriptor("ints", new NoOpSerde<Integer>());
    InMemoryOutputDescriptor imod = isd.getOutputDescriptor("ints-out", new NoOpSerde<>());
    TestRunner.of(MyAsyncStreamTask.class).addInputStream(imid, inputList).addOutputStream(imod, 1).run(Duration.ofSeconds(2));
    Assert.assertThat(TestRunner.consumeStream(imod, Duration.ofMillis(1000)).get(0), IsIterableContainingInOrder.contains(outputList.toArray()));
}
Also used : InMemoryOutputDescriptor(org.apache.samza.test.framework.system.descriptors.InMemoryOutputDescriptor) InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) Test(org.junit.Test)

Example 20 with InMemorySystemDescriptor

use of org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor in project samza by apache.

the class TestLocalTableWithConfigRewriterEndToEnd method testWithConfigRewriter.

/**
 * MyTaskApplication does not include table descriptor, so if the rewriter does not add the table configs properly,
 * then the application will fail to execute.
 */
@Test
public void testWithConfigRewriter() {
    InMemorySystemDescriptor isd = new InMemorySystemDescriptor("test");
    InMemoryInputDescriptor<TestTableData.PageView> inputDescriptor = isd.getInputDescriptor("PageView", new NoOpSerde<>());
    TestRunner.of(new MyTaskApplication()).addInputStream(inputDescriptor, TestTableData.generatePartitionedPageViews(40, 4)).addConfig("job.config.rewriters", "my-rewriter").addConfig("job.config.rewriter.my-rewriter.class", MyConfigRewriter.class.getName()).run(Duration.ofSeconds(10));
}
Also used : InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) Test(org.junit.Test)

Aggregations

InMemorySystemDescriptor (org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor)34 Test (org.junit.Test)29 KV (org.apache.samza.operators.KV)17 ArrayList (java.util.ArrayList)16 List (java.util.List)16 NoOpSerde (org.apache.samza.serializers.NoOpSerde)13 HashMap (java.util.HashMap)12 StreamApplication (org.apache.samza.application.StreamApplication)12 Duration (java.time.Duration)11 InMemoryInputDescriptor (org.apache.samza.test.framework.system.descriptors.InMemoryInputDescriptor)11 PageView (org.apache.samza.test.table.TestTableData.PageView)11 DelegatingSystemDescriptor (org.apache.samza.system.descriptors.DelegatingSystemDescriptor)10 GenericInputDescriptor (org.apache.samza.system.descriptors.GenericInputDescriptor)10 Table (org.apache.samza.table.Table)10 TestRunner (org.apache.samza.test.framework.TestRunner)10 EnrichedPageView (org.apache.samza.test.table.TestTableData.EnrichedPageView)10 Profile (org.apache.samza.test.table.TestTableData.Profile)10 Arrays (java.util.Arrays)9 StreamApplicationDescriptor (org.apache.samza.application.descriptors.StreamApplicationDescriptor)9 Assert (org.junit.Assert)9