Search in sources :

Example 21 with IntegerSerde

use of org.apache.samza.serializers.IntegerSerde in project samza by apache.

the class TestJoinOperator method getTestJoinStreamGraph.

private StreamApplicationDescriptorImpl getTestJoinStreamGraph(TestJoinFunction joinFn) throws IOException {
    Map<String, String> mapConfig = new HashMap<>();
    mapConfig.put("job.name", "jobName");
    mapConfig.put("job.id", "jobId");
    StreamTestUtils.addStreamConfigs(mapConfig, "inStream", "insystem", "instream");
    StreamTestUtils.addStreamConfigs(mapConfig, "inStream2", "insystem", "instream2");
    Config config = new MapConfig(mapConfig);
    return new StreamApplicationDescriptorImpl(appDesc -> {
        IntegerSerde integerSerde = new IntegerSerde();
        KVSerde<Integer, Integer> kvSerde = KVSerde.of(integerSerde, integerSerde);
        GenericSystemDescriptor sd = new GenericSystemDescriptor("insystem", "mockFactoryClassName");
        GenericInputDescriptor<KV<Integer, Integer>> inputDescriptor1 = sd.getInputDescriptor("inStream", kvSerde);
        GenericInputDescriptor<KV<Integer, Integer>> inputDescriptor2 = sd.getInputDescriptor("inStream2", kvSerde);
        MessageStream<KV<Integer, Integer>> inStream = appDesc.getInputStream(inputDescriptor1);
        MessageStream<KV<Integer, Integer>> inStream2 = appDesc.getInputStream(inputDescriptor2);
        inStream.join(inStream2, joinFn, integerSerde, kvSerde, kvSerde, JOIN_TTL, "j1").sink((message, messageCollector, taskCoordinator) -> {
            SystemStream outputSystemStream = new SystemStream("outputSystem", "outputStream");
            messageCollector.send(new OutgoingMessageEnvelope(outputSystemStream, message));
        });
    }, config);
}
Also used : HashMap(java.util.HashMap) MapConfig(org.apache.samza.config.MapConfig) Config(org.apache.samza.config.Config) SystemStream(org.apache.samza.system.SystemStream) IntegerSerde(org.apache.samza.serializers.IntegerSerde) StreamApplicationDescriptorImpl(org.apache.samza.application.descriptors.StreamApplicationDescriptorImpl) MapConfig(org.apache.samza.config.MapConfig) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) GenericSystemDescriptor(org.apache.samza.system.descriptors.GenericSystemDescriptor)

Example 22 with IntegerSerde

use of org.apache.samza.serializers.IntegerSerde in project samza by apache.

the class TestStreamApplicationDescriptorImpl method testGetInputStreamWithExpandingSystem.

@Test
public void testGetInputStreamWithExpandingSystem() {
    String streamId = "test-stream-1";
    String expandedStreamId = "expanded-stream";
    AtomicInteger expandCallCount = new AtomicInteger();
    StreamExpander expander = (sg, isd) -> {
        expandCallCount.incrementAndGet();
        InputDescriptor expandedISD = new GenericSystemDescriptor("expanded-system", "mockFactoryClass").getInputDescriptor(expandedStreamId, new IntegerSerde());
        return sg.getInputStream(expandedISD);
    };
    MockExpandingSystemDescriptor sd = new MockExpandingSystemDescriptor("mock-system", expander);
    MockInputDescriptor isd = sd.getInputDescriptor(streamId, new IntegerSerde());
    StreamApplicationDescriptorImpl streamAppDesc = new StreamApplicationDescriptorImpl(appDesc -> {
        appDesc.getInputStream(isd);
    }, getConfig());
    InputOperatorSpec inputOpSpec = streamAppDesc.getInputOperators().get(expandedStreamId);
    assertEquals(OpCode.INPUT, inputOpSpec.getOpCode());
    assertEquals(1, expandCallCount.get());
    assertFalse(streamAppDesc.getInputOperators().containsKey(streamId));
    assertFalse(streamAppDesc.getInputDescriptors().containsKey(streamId));
    assertTrue(streamAppDesc.getInputDescriptors().containsKey(expandedStreamId));
    assertEquals(expandedStreamId, inputOpSpec.getStreamId());
}
Also used : SystemDescriptor(org.apache.samza.system.descriptors.SystemDescriptor) GenericSystemDescriptor(org.apache.samza.system.descriptors.GenericSystemDescriptor) IntermediateMessageStreamImpl(org.apache.samza.operators.stream.IntermediateMessageStreamImpl) HashMap(java.util.HashMap) Serde(org.apache.samza.serializers.Serde) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) AtomicReference(java.util.concurrent.atomic.AtomicReference) TableImpl(org.apache.samza.operators.TableImpl) ArrayList(java.util.ArrayList) OutputStreamImpl(org.apache.samza.operators.spec.OutputStreamImpl) OperatorSpec(org.apache.samza.operators.spec.OperatorSpec) BaseTableDescriptor(org.apache.samza.table.descriptors.BaseTableDescriptor) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ApplicationConfig(org.apache.samza.config.ApplicationConfig) InputTransformer(org.apache.samza.system.descriptors.InputTransformer) ProcessorLifecycleListenerFactory(org.apache.samza.runtime.ProcessorLifecycleListenerFactory) Assert.fail(org.junit.Assert.fail) MapConfig(org.apache.samza.config.MapConfig) IntegerSerde(org.apache.samza.serializers.IntegerSerde) NoOpSerde(org.apache.samza.serializers.NoOpSerde) Mockito.doReturn(org.mockito.Mockito.doReturn) TestMessageEnvelope(org.apache.samza.operators.data.TestMessageEnvelope) OpCode(org.apache.samza.operators.spec.OperatorSpec.OpCode) InputDescriptor(org.apache.samza.system.descriptors.InputDescriptor) ApplicationContainerContextFactory(org.apache.samza.context.ApplicationContainerContextFactory) GenericOutputDescriptor(org.apache.samza.system.descriptors.GenericOutputDescriptor) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) TransformingInputDescriptorProvider(org.apache.samza.system.descriptors.TransformingInputDescriptorProvider) SamzaException(org.apache.samza.SamzaException) ApplicationTaskContextFactory(org.apache.samza.context.ApplicationTaskContextFactory) ExpandingInputDescriptorProvider(org.apache.samza.system.descriptors.ExpandingInputDescriptorProvider) StreamExpander(org.apache.samza.system.descriptors.StreamExpander) Mockito.verify(org.mockito.Mockito.verify) List(java.util.List) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Config(org.apache.samza.config.Config) KVSerde(org.apache.samza.serializers.KVSerde) StreamApplication(org.apache.samza.application.StreamApplication) Assert.assertEquals(org.junit.Assert.assertEquals) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) Mockito.mock(org.mockito.Mockito.mock) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) InputDescriptor(org.apache.samza.system.descriptors.InputDescriptor) InputOperatorSpec(org.apache.samza.operators.spec.InputOperatorSpec) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StreamExpander(org.apache.samza.system.descriptors.StreamExpander) GenericSystemDescriptor(org.apache.samza.system.descriptors.GenericSystemDescriptor) IntegerSerde(org.apache.samza.serializers.IntegerSerde) Test(org.junit.Test)

Example 23 with IntegerSerde

use of org.apache.samza.serializers.IntegerSerde in project samza by apache.

the class TestLocalTableEndToEnd method testSendTo.

@Test
public void testSendTo() {
    MyMapFunction mapFn = new MyMapFunction();
    StreamApplication app = appDesc -> {
        Table<KV<Integer, Profile>> table = appDesc.getTable(new InMemoryTableDescriptor<>("t1", KVSerde.of(new IntegerSerde(), new ProfileJsonSerde())));
        DelegatingSystemDescriptor ksd = new DelegatingSystemDescriptor(SYSTEM_NAME);
        GenericInputDescriptor<Profile> isd = ksd.getInputDescriptor(PROFILE_STREAM, new NoOpSerde<>());
        appDesc.getInputStream(isd).map(mapFn).sendTo(table);
    };
    InMemorySystemDescriptor isd = new InMemorySystemDescriptor(SYSTEM_NAME);
    InMemoryInputDescriptor<Profile> profileStreamDesc = isd.getInputDescriptor(PROFILE_STREAM, new NoOpSerde<>());
    int numProfilesPerPartition = 10;
    int numInputPartitions = 4;
    Map<Integer, List<Profile>> inputProfiles = TestTableData.generatePartitionedProfiles(numProfilesPerPartition * numInputPartitions, numInputPartitions);
    TestRunner.of(app).addInputStream(profileStreamDesc, inputProfiles).run(Duration.ofSeconds(10));
    for (int i = 0; i < numInputPartitions; i++) {
        MyMapFunction mapFnCopy = MyMapFunction.getMapFunctionByTask(String.format("Partition %d", i));
        assertEquals(numProfilesPerPartition, mapFnCopy.received.size());
        mapFnCopy.received.forEach(p -> assertNotNull(mapFnCopy.table.get(p.getMemberId())));
    }
}
Also used : PageViewJsonSerdeFactory(org.apache.samza.test.table.TestTableData.PageViewJsonSerdeFactory) InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) JobConfig(org.apache.samza.config.JobConfig) HashMap(java.util.HashMap) SingleContainerGrouperFactory(org.apache.samza.container.grouper.task.SingleContainerGrouperFactory) Profile(org.apache.samza.test.table.TestTableData.Profile) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) ArrayList(java.util.ArrayList) MapFunction(org.apache.samza.operators.functions.MapFunction) InMemoryInputDescriptor(org.apache.samza.test.framework.system.descriptors.InMemoryInputDescriptor) DelegatingSystemDescriptor(org.apache.samza.system.descriptors.DelegatingSystemDescriptor) Duration(java.time.Duration) Map(java.util.Map) ArraySystemFactory(org.apache.samza.test.util.ArraySystemFactory) LinkedList(java.util.LinkedList) KV(org.apache.samza.operators.KV) IntegerSerde(org.apache.samza.serializers.IntegerSerde) NoOpSerde(org.apache.samza.serializers.NoOpSerde) ProfileJsonSerde(org.apache.samza.test.table.TestTableData.ProfileJsonSerde) InMemoryTableDescriptor(org.apache.samza.storage.kv.inmemory.descriptors.InMemoryTableDescriptor) MessageStream(org.apache.samza.operators.MessageStream) Table(org.apache.samza.table.Table) TaskConfig(org.apache.samza.config.TaskConfig) Assert.assertNotNull(org.junit.Assert.assertNotNull) EnrichedPageView(org.apache.samza.test.table.TestTableData.EnrichedPageView) Test(org.junit.Test) PageViewJsonSerde(org.apache.samza.test.table.TestTableData.PageViewJsonSerde) PassthroughJobCoordinatorFactory(org.apache.samza.standalone.PassthroughJobCoordinatorFactory) Context(org.apache.samza.context.Context) TestRunner(org.apache.samza.test.framework.TestRunner) List(java.util.List) ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) StreamApplicationDescriptor(org.apache.samza.application.descriptors.StreamApplicationDescriptor) JobCoordinatorConfig(org.apache.samza.config.JobCoordinatorConfig) KVSerde(org.apache.samza.serializers.KVSerde) PageView(org.apache.samza.test.table.TestTableData.PageView) StreamApplication(org.apache.samza.application.StreamApplication) Assert.assertEquals(org.junit.Assert.assertEquals) Table(org.apache.samza.table.Table) ReadWriteUpdateTable(org.apache.samza.table.ReadWriteUpdateTable) ProfileJsonSerde(org.apache.samza.test.table.TestTableData.ProfileJsonSerde) StreamApplication(org.apache.samza.application.StreamApplication) Profile(org.apache.samza.test.table.TestTableData.Profile) InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) IntegerSerde(org.apache.samza.serializers.IntegerSerde) DelegatingSystemDescriptor(org.apache.samza.system.descriptors.DelegatingSystemDescriptor) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) NoOpSerde(org.apache.samza.serializers.NoOpSerde) InMemoryTableDescriptor(org.apache.samza.storage.kv.inmemory.descriptors.InMemoryTableDescriptor) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) Test(org.junit.Test)

Example 24 with IntegerSerde

use of org.apache.samza.serializers.IntegerSerde in project samza by apache.

the class EndOfStreamIntegrationTest method testPipeline.

@Test
public void testPipeline() {
    class PipelineApplication implements StreamApplication {

        @Override
        public void describe(StreamApplicationDescriptor appDescriptor) {
            DelegatingSystemDescriptor sd = new DelegatingSystemDescriptor("test");
            GenericInputDescriptor<KV<String, PageView>> isd = sd.getInputDescriptor("PageView", KVSerde.of(new NoOpSerde<>(), new NoOpSerde<>()));
            appDescriptor.getInputStream(isd).map(KV::getValue).partitionBy(PageView::getMemberId, pv -> pv, KVSerde.of(new IntegerSerde(), new TestTableData.PageViewJsonSerde()), "p1").sink((m, collector, coordinator) -> {
                RECEIVED.add(m.getValue());
            });
        }
    }
    int numPageViews = 40;
    InMemorySystemDescriptor isd = new InMemorySystemDescriptor("test");
    InMemoryInputDescriptor<TestTableData.PageView> inputDescriptor = isd.getInputDescriptor("PageView", new NoOpSerde<>());
    TestRunner.of(new PipelineApplication()).addInputStream(inputDescriptor, TestTableData.generatePartitionedPageViews(numPageViews, 4)).run(Duration.ofSeconds(10));
    assertEquals(RECEIVED.size(), numPageViews);
}
Also used : InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) Test(org.junit.Test) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) ArrayList(java.util.ArrayList) TestRunner(org.apache.samza.test.framework.TestRunner) List(java.util.List) InMemoryInputDescriptor(org.apache.samza.test.framework.system.descriptors.InMemoryInputDescriptor) StreamApplicationDescriptor(org.apache.samza.application.descriptors.StreamApplicationDescriptor) TestTableData(org.apache.samza.test.table.TestTableData) DelegatingSystemDescriptor(org.apache.samza.system.descriptors.DelegatingSystemDescriptor) Duration(java.time.Duration) KVSerde(org.apache.samza.serializers.KVSerde) PageView(org.apache.samza.test.table.TestTableData.PageView) StreamApplication(org.apache.samza.application.StreamApplication) KV(org.apache.samza.operators.KV) IntegerSerde(org.apache.samza.serializers.IntegerSerde) NoOpSerde(org.apache.samza.serializers.NoOpSerde) Assert.assertEquals(org.junit.Assert.assertEquals) PageView(org.apache.samza.test.table.TestTableData.PageView) StreamApplication(org.apache.samza.application.StreamApplication) KV(org.apache.samza.operators.KV) InMemorySystemDescriptor(org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor) IntegerSerde(org.apache.samza.serializers.IntegerSerde) StreamApplicationDescriptor(org.apache.samza.application.descriptors.StreamApplicationDescriptor) DelegatingSystemDescriptor(org.apache.samza.system.descriptors.DelegatingSystemDescriptor) NoOpSerde(org.apache.samza.serializers.NoOpSerde) TestTableData(org.apache.samza.test.table.TestTableData) Test(org.junit.Test)

Aggregations

IntegerSerde (org.apache.samza.serializers.IntegerSerde)24 Test (org.junit.Test)17 StreamApplication (org.apache.samza.application.StreamApplication)9 KVSerde (org.apache.samza.serializers.KVSerde)9 Config (org.apache.samza.config.Config)8 Duration (java.time.Duration)7 HashMap (java.util.HashMap)7 StreamApplicationDescriptor (org.apache.samza.application.descriptors.StreamApplicationDescriptor)7 MapConfig (org.apache.samza.config.MapConfig)7 KV (org.apache.samza.operators.KV)6 List (java.util.List)5 MessageStream (org.apache.samza.operators.MessageStream)5 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 Context (org.apache.samza.context.Context)4 StringSerde (org.apache.samza.serializers.StringSerde)4 GenericInputDescriptor (org.apache.samza.system.descriptors.GenericInputDescriptor)4 InMemorySystemDescriptor (org.apache.samza.test.framework.system.descriptors.InMemorySystemDescriptor)4 ImmutableList (com.google.common.collect.ImmutableList)3 OutputStream (org.apache.samza.operators.OutputStream)3