Search in sources :

Example 1 with Triple

use of org.apache.beam.sdk.extensions.euphoria.core.client.util.Triple in project beam by apache.

the class TopPerKeyTest method testBuild.

@Test
public void testBuild() {
    final PCollection<String> dataset = TestUtils.createMockDataset(TypeDescriptors.strings());
    final FixedWindows windowing = FixedWindows.of(org.joda.time.Duration.standardHours(1));
    final DefaultTrigger trigger = DefaultTrigger.of();
    final PCollection<Triple<String, Long, Long>> result = TopPerKey.named("TopPerKey1").of(dataset).keyBy(s -> s).valueBy(s -> 1L).scoreBy(s -> 1L).windowBy(windowing).triggeredBy(trigger).discardingFiredPanes().withAllowedLateness(Duration.millis(1000)).output();
    final TopPerKey tpk = (TopPerKey) TestUtils.getProducer(result);
    assertTrue(tpk.getName().isPresent());
    assertEquals("TopPerKey1", tpk.getName().get());
    assertNotNull(tpk.getKeyExtractor());
    assertNotNull(tpk.getValueExtractor());
    assertNotNull(tpk.getScoreExtractor());
    assertTrue(tpk.getWindow().isPresent());
    @SuppressWarnings("unchecked") final WindowDesc<?> windowDesc = WindowDesc.of((Window) tpk.getWindow().get());
    assertEquals(windowing, windowDesc.getWindowFn());
    assertEquals(trigger, windowDesc.getTrigger());
    assertEquals(AccumulationMode.DISCARDING_FIRED_PANES, windowDesc.getAccumulationMode());
    assertEquals(Duration.millis(1000), windowDesc.getAllowedLateness());
}
Also used : Triple(org.apache.beam.sdk.extensions.euphoria.core.client.util.Triple) AccumulationMode(org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode) Triple(org.apache.beam.sdk.extensions.euphoria.core.client.util.Triple) Assert.assertNotNull(org.junit.Assert.assertNotNull) WindowDesc(org.apache.beam.sdk.transforms.windowing.WindowDesc) Duration(org.joda.time.Duration) RunWith(org.junit.runner.RunWith) Assert.assertTrue(org.junit.Assert.assertTrue) FixedWindows(org.apache.beam.sdk.transforms.windowing.FixedWindows) Test(org.junit.Test) JUnit4(org.junit.runners.JUnit4) PCollection(org.apache.beam.sdk.values.PCollection) DefaultTrigger(org.apache.beam.sdk.transforms.windowing.DefaultTrigger) Assert.assertFalse(org.junit.Assert.assertFalse) TypeDescriptors(org.apache.beam.sdk.values.TypeDescriptors) Window(org.apache.beam.sdk.transforms.windowing.Window) Assert.assertEquals(org.junit.Assert.assertEquals) FixedWindows(org.apache.beam.sdk.transforms.windowing.FixedWindows) DefaultTrigger(org.apache.beam.sdk.transforms.windowing.DefaultTrigger) Test(org.junit.Test)

Aggregations

Triple (org.apache.beam.sdk.extensions.euphoria.core.client.util.Triple)1 DefaultTrigger (org.apache.beam.sdk.transforms.windowing.DefaultTrigger)1 FixedWindows (org.apache.beam.sdk.transforms.windowing.FixedWindows)1 Window (org.apache.beam.sdk.transforms.windowing.Window)1 WindowDesc (org.apache.beam.sdk.transforms.windowing.WindowDesc)1 PCollection (org.apache.beam.sdk.values.PCollection)1 TypeDescriptors (org.apache.beam.sdk.values.TypeDescriptors)1 AccumulationMode (org.apache.beam.sdk.values.WindowingStrategy.AccumulationMode)1 Duration (org.joda.time.Duration)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1 Assert.assertNotNull (org.junit.Assert.assertNotNull)1 Assert.assertTrue (org.junit.Assert.assertTrue)1 Test (org.junit.Test)1 RunWith (org.junit.runner.RunWith)1 JUnit4 (org.junit.runners.JUnit4)1