Search in sources :

Example 16 with IntegerSerde

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

the class TestExpandingInputDescriptor method testAPIUsage.

public void testAPIUsage() {
    // does not assert anything, but acts as a compile-time check on expected descriptor type parameters
    // and validates that the method calls can be chained.
    ExampleExpandingSystemDescriptor expandingSystem = new ExampleExpandingSystemDescriptor("expandingSystem");
    ExampleExpandingInputDescriptor<Long> input1 = expandingSystem.getInputDescriptor("input1", new IntegerSerde());
    ExampleExpandingOutputDescriptor<Integer> output1 = expandingSystem.getOutputDescriptor("output1", new IntegerSerde());
    input1.shouldBootstrap().withOffsetDefault(SystemStreamMetadata.OffsetType.NEWEST).withPriority(1).shouldResetOffset().withStreamConfigs(Collections.emptyMap());
    output1.withStreamConfigs(Collections.emptyMap());
}
Also used : ExampleExpandingSystemDescriptor(org.apache.samza.system.descriptors.examples.expanding.ExampleExpandingSystemDescriptor) IntegerSerde(org.apache.samza.serializers.IntegerSerde)

Example 17 with IntegerSerde

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

the class TestGenericInputDescriptor method testISDObjectsWithOverrides.

@Test
public void testISDObjectsWithOverrides() {
    GenericSystemDescriptor mySystem = new GenericSystemDescriptor("input-system", "factory.class.name").withSystemConfigs(Collections.emptyMap()).withDefaultStreamConfigs(Collections.emptyMap());
    IntegerSerde streamSerde = new IntegerSerde();
    GenericInputDescriptor<Integer> isd = mySystem.getInputDescriptor("input-stream", streamSerde);
    assertEquals(streamSerde, isd.getSerde());
    assertFalse(isd.getTransformer().isPresent());
}
Also used : IntegerSerde(org.apache.samza.serializers.IntegerSerde) Test(org.junit.Test)

Example 18 with IntegerSerde

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

the class TestSimpleInputDescriptor method testAPIUsage.

@Test
public void testAPIUsage() {
    // does not assert anything, but acts as a compile-time check on expected descriptor type parameters
    // and validates that the method calls can be chained.
    ExampleSimpleSystemDescriptor kafkaSystem = new ExampleSimpleSystemDescriptor("kafka-system").withSystemConfigs(Collections.emptyMap());
    ExampleSimpleInputDescriptor<Integer> input1 = kafkaSystem.getInputDescriptor("input1", new IntegerSerde());
    ExampleSimpleOutputDescriptor<Integer> output1 = kafkaSystem.getOutputDescriptor("output1", new IntegerSerde());
    input1.shouldBootstrap().withOffsetDefault(SystemStreamMetadata.OffsetType.NEWEST).withPriority(1).shouldResetOffset().withStreamConfigs(Collections.emptyMap());
    output1.withStreamConfigs(Collections.emptyMap());
}
Also used : ExampleSimpleSystemDescriptor(org.apache.samza.system.descriptors.examples.serde.ExampleSimpleSystemDescriptor) IntegerSerde(org.apache.samza.serializers.IntegerSerde) Test(org.junit.Test)

Example 19 with IntegerSerde

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

the class TestWindowOperator method testTumblingAggregatingWindowsDiscardingMode.

@Test
public void testTumblingAggregatingWindowsDiscardingMode() throws Exception {
    when(this.context.getTaskContext().getStore("jobName-jobId-window-w1")).thenReturn(new TestInMemoryStore<>(new TimeSeriesKeySerde(new IntegerSerde()), new IntegerSerde()));
    OperatorSpecGraph sgb = this.getAggregateTumblingWindowStreamGraph(AccumulationMode.DISCARDING, Duration.ofSeconds(1), Triggers.repeat(Triggers.count(2))).getOperatorSpecGraph();
    List<WindowPane<Integer, Integer>> windowPanes = new ArrayList<>();
    TestClock testClock = new TestClock();
    StreamOperatorTask task = new StreamOperatorTask(sgb, testClock);
    task.init(this.context);
    MessageCollector messageCollector = envelope -> windowPanes.add((WindowPane<Integer, Integer>) envelope.getMessage());
    integers.forEach(n -> task.processAsync(new IntegerEnvelope(n), messageCollector, taskCoordinator, taskCallback));
    testClock.advanceTime(Duration.ofSeconds(1));
    task.window(messageCollector, taskCoordinator);
    Assert.assertEquals(windowPanes.size(), 5);
    Assert.assertEquals(windowPanes.get(0).getMessage(), new Integer(2));
    Assert.assertEquals(windowPanes.get(1).getMessage(), new Integer(2));
    Assert.assertEquals(windowPanes.get(2).getMessage(), new Integer(2));
    Assert.assertEquals(windowPanes.get(3).getMessage(), new Integer(2));
    Assert.assertEquals(windowPanes.get(4).getMessage(), new Integer(1));
}
Also used : StreamApplicationDescriptorImpl(org.apache.samza.application.descriptors.StreamApplicationDescriptorImpl) TaskModel(org.apache.samza.job.model.TaskModel) GenericInputDescriptor(org.apache.samza.system.descriptors.GenericInputDescriptor) OperatorSpecGraph(org.apache.samza.operators.OperatorSpecGraph) AccumulationMode(org.apache.samza.operators.windows.AccumulationMode) Duration(java.time.Duration) Map(java.util.Map) MapConfig(org.apache.samza.config.MapConfig) KV(org.apache.samza.operators.KV) TaskCallback(org.apache.samza.task.TaskCallback) ImmutableSet(com.google.common.collect.ImmutableSet) TaskName(org.apache.samza.container.TaskName) IncomingMessageEnvelope(org.apache.samza.system.IncomingMessageEnvelope) Collection(java.util.Collection) Triggers(org.apache.samza.operators.triggers.Triggers) Context(org.apache.samza.context.Context) List(java.util.List) TestClock(org.apache.samza.testUtils.TestClock) TestInMemoryStore(org.apache.samza.operators.impl.store.TestInMemoryStore) Config(org.apache.samza.config.Config) KVSerde(org.apache.samza.serializers.KVSerde) StreamApplication(org.apache.samza.application.StreamApplication) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) Mockito.mock(org.mockito.Mockito.mock) StreamOperatorTask(org.apache.samza.task.StreamOperatorTask) GenericSystemDescriptor(org.apache.samza.system.descriptors.GenericSystemDescriptor) HashMap(java.util.HashMap) Serde(org.apache.samza.serializers.Serde) SystemStreamPartition(org.apache.samza.system.SystemStreamPartition) ArrayList(java.util.ArrayList) MapFunction(org.apache.samza.operators.functions.MapFunction) WindowPane(org.apache.samza.operators.windows.WindowPane) Trigger(org.apache.samza.operators.triggers.Trigger) ImmutableList(com.google.common.collect.ImmutableList) MessageCollector(org.apache.samza.task.MessageCollector) FiringType(org.apache.samza.operators.triggers.FiringType) SystemStream(org.apache.samza.system.SystemStream) MockContext(org.apache.samza.context.MockContext) IntegerSerde(org.apache.samza.serializers.IntegerSerde) MessageStream(org.apache.samza.operators.MessageStream) Before(org.junit.Before) Windows(org.apache.samza.operators.windows.Windows) Partition(org.apache.samza.Partition) IOException(java.io.IOException) Test(org.junit.Test) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) TaskCoordinator(org.apache.samza.task.TaskCoordinator) Mockito.verify(org.mockito.Mockito.verify) OutgoingMessageEnvelope(org.apache.samza.system.OutgoingMessageEnvelope) TaskContextImpl(org.apache.samza.context.TaskContextImpl) Assert(org.junit.Assert) TimeSeriesKeySerde(org.apache.samza.operators.impl.store.TimeSeriesKeySerde) OperatorSpecGraph(org.apache.samza.operators.OperatorSpecGraph) StreamOperatorTask(org.apache.samza.task.StreamOperatorTask) ArrayList(java.util.ArrayList) WindowPane(org.apache.samza.operators.windows.WindowPane) IntegerSerde(org.apache.samza.serializers.IntegerSerde) TestClock(org.apache.samza.testUtils.TestClock) MessageCollector(org.apache.samza.task.MessageCollector) TimeSeriesKeySerde(org.apache.samza.operators.impl.store.TimeSeriesKeySerde) Test(org.junit.Test)

Example 20 with IntegerSerde

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

the class TestTimestampedValueSerde method testEmptyValueSerialization.

@Test
public void testEmptyValueSerialization() {
    byte[] expectedBytes = new byte[8];
    ByteBuffer.wrap(expectedBytes).putLong(1234L);
    TimestampedValueSerde<Integer> timestampedValueSerde = new TimestampedValueSerde<>(new IntegerSerde());
    TimestampedValue<Integer> timestampedValue = new TimestampedValue<>(null, 1234L);
    assertTrue(Arrays.equals(expectedBytes, timestampedValueSerde.toBytes(timestampedValue)));
}
Also used : TimestampedValue(org.apache.samza.util.TimestampedValue) IntegerSerde(org.apache.samza.serializers.IntegerSerde) 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