Search in sources :

Example 6 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class BaseWindowedBoltTest method testSettingSlidingTimeWindow.

@Test
public void testSettingSlidingTimeWindow() {
    final Object[][] args = new Object[][] { { -1L, 10L }, { 10L, -1L }, { 0L, 10L }, { 10L, 0L }, { 0L, 0L }, { -1L, -1L }, { 5L, 10L }, { 1L, 1L }, { 10L, 5L }, { 100L, 10L }, { 100L, 100L }, { 200L, 100L }, { 500L, 100L }, { null, null }, { null, 1L }, { 1L, null }, { null, -1L }, { -1L, null } };
    for (Object[] arg : args) {
        TopologyBuilder builder = new TopologyBuilder();
        Object arg0 = arg[0];
        Object arg1 = arg[1];
        try {
            Duration windowLengthDuration = null;
            if (arg0 != null) {
                windowLengthDuration = Duration.ofMillis((Long) arg0);
            }
            Duration slidingIntervalDuration = null;
            if (arg1 != null) {
                slidingIntervalDuration = Duration.ofMillis((Long) arg1);
            }
            builder.setBolt("testBolt", new TestBolt().withWindow(windowLengthDuration, slidingIntervalDuration));
            if (arg0 == null || arg1 == null) {
                fail(String.format("Window length or sliding window length cannot be null -- " + "windowLengthDuration: %s slidingIntervalDuration: %s", arg0, arg1));
            }
            if ((Long) arg0 <= 0 || (Long) arg1 <= 0) {
                fail(String.format("Window length or sliding window length cannot be zero or less -- " + "windowLengthDuration: %s slidingIntervalDuration: %s", arg0, arg1));
            }
        } catch (IllegalArgumentException e) {
            if (arg0 != null && arg1 != null && (Long) arg0 > 0 && (Long) arg1 > 0) {
                fail(String.format("Exception: %s thrown on valid input -- windowLengthDuration: %s " + "slidingIntervalDuration: %s", e.getMessage(), arg0, arg1));
            }
        }
    }
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) Duration(java.time.Duration) Test(org.junit.Test)

Example 7 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class BaseWindowedBoltTest method testSettingSlidingCountWindow.

@Test
public void testSettingSlidingCountWindow() {
    final Object[][] args = new Object[][] { { -1, 10 }, { 10, -1 }, { 0, 10 }, { 10, 0 }, { 0, 0 }, { -1, -1 }, { 5, 10 }, { 1, 1 }, { 10, 5 }, { 100, 10 }, { 100, 100 }, { 200, 100 }, { 500, 100 }, { null, null }, { null, 1 }, { 1, null }, { null, -1 }, { -1, null } };
    for (Object[] arg : args) {
        TopologyBuilder builder = new TopologyBuilder();
        Object arg0 = arg[0];
        Object arg1 = arg[1];
        try {
            BaseWindowedBolt.Count windowLengthCount = null;
            if (arg0 != null) {
                windowLengthCount = BaseWindowedBolt.Count.of((Integer) arg0);
            }
            BaseWindowedBolt.Count slidingIntervalCount = null;
            if (arg1 != null) {
                slidingIntervalCount = BaseWindowedBolt.Count.of((Integer) arg1);
            }
            builder.setBolt("testBolt", new TestBolt().withWindow(windowLengthCount, slidingIntervalCount));
            if (arg0 == null || arg1 == null) {
                fail(String.format("Window length or sliding window length cannot be null -- " + "windowLengthCount: %s slidingIntervalCount: %s", arg0, arg1));
            }
            if ((Integer) arg0 <= 0 || (Integer) arg1 <= 0) {
                fail(String.format("Window length or sliding window length cannot be zero or less -- " + "windowLengthCount: %s slidingIntervalCount: %s", arg0, arg1));
            }
        } catch (IllegalArgumentException e) {
            if (arg0 != null && arg1 != null && (Integer) arg0 > 0 && (Integer) arg1 > 0) {
                fail(String.format("Exception: %s thrown on valid input -- windowLengthCount: %s " + "slidingIntervalCount: %s", e.getMessage(), arg0, arg1));
            }
        }
    }
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) Test(org.junit.Test)

Example 8 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class BaseWindowedBoltTest method testSettingLagTime.

@Test
public void testSettingLagTime() {
    final Object[] args = new Object[] { -1L, 0L, 1L, 2L, 5L, 10L, null };
    for (Object arg : args) {
        TopologyBuilder builder = new TopologyBuilder();
        Object arg0 = arg;
        try {
            Duration lagTime = null;
            if (arg0 != null) {
                lagTime = Duration.ofMillis((Long) arg0);
            }
            builder.setBolt("testBolt", new TestBolt().withLag(lagTime));
            if (arg0 == null) {
                fail(String.format("Window lag duration cannot be null -- lagTime: %s", arg0));
            }
            if ((Long) arg0 <= 0) {
                fail(String.format("Window lag cannot be zero or less -- lagTime: %s", arg0));
            }
        } catch (IllegalArgumentException e) {
            if (arg0 != null && (Long) arg0 > 0) {
                fail(String.format("Exception: %s thrown on valid input -- lagTime: %s", e.getMessage(), arg0));
            }
        }
    }
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) Duration(java.time.Duration) Test(org.junit.Test)

Example 9 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class BaseWindowedBoltTest method testSettingTumblingCountWindow.

@Test
public void testSettingTumblingCountWindow() {
    final Object[] args = new Object[] { -1, 0, 1, 2, 5, 10, null };
    for (Object arg : args) {
        TopologyBuilder builder = new TopologyBuilder();
        Object arg0 = arg;
        try {
            BaseWindowedBolt.Count windowLengthCount = null;
            if (arg0 != null) {
                windowLengthCount = BaseWindowedBolt.Count.of((Integer) arg0);
            }
            builder.setBolt("testBolt", new TestBolt().withTumblingWindow(windowLengthCount));
            if (arg0 == null) {
                fail(String.format("Window length cannot be null -- windowLengthCount: %s", arg0));
            }
            if ((Integer) arg0 <= 0) {
                fail(String.format("Window length cannot be zero or less -- windowLengthCount: %s", arg0));
            }
        } catch (IllegalArgumentException e) {
            if (arg0 != null && (Integer) arg0 > 0) {
                fail(String.format("Exception: %s thrown on valid input -- windowLengthCount: %s", e.getMessage(), arg0));
            }
        }
    }
}
Also used : TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) Test(org.junit.Test)

Example 10 with TopologyBuilder

use of org.apache.heron.api.topology.TopologyBuilder in project heron by twitter.

the class Runner method run.

/**
 * Runs the computation
 * @param name The name of the topology
 * @param config Any config that is passed to the topology
 * @param builder The builder used to keep track of the sources.
 */
public void run(String name, Config config, Builder builder) {
    BuilderImpl bldr = (BuilderImpl) builder;
    TopologyBuilder topologyBuilder = bldr.build();
    try {
        HeronSubmitter.submitTopology(name, config.getHeronConfig(), topologyBuilder.createTopology());
    } catch (AlreadyAliveException | InvalidTopologyException e) {
        e.printStackTrace();
    }
}
Also used : BuilderImpl(org.apache.heron.streamlet.impl.BuilderImpl) TopologyBuilder(org.apache.heron.api.topology.TopologyBuilder) InvalidTopologyException(org.apache.heron.api.exception.InvalidTopologyException) AlreadyAliveException(org.apache.heron.api.exception.AlreadyAliveException)

Aggregations

TopologyBuilder (org.apache.heron.api.topology.TopologyBuilder)41 Config (org.apache.heron.api.Config)19 Test (org.junit.Test)15 HashMap (java.util.HashMap)8 Fields (org.apache.heron.api.tuple.Fields)6 Simulator (org.apache.heron.simulator.Simulator)6 TestWordSpout (org.apache.heron.examples.api.spout.TestWordSpout)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Duration (java.time.Duration)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 Arrays (java.util.Arrays)3 Collection (java.util.Collection)3 List (java.util.List)3 Set (java.util.Set)3 Consumer (java.util.function.Consumer)3 Function (java.util.function.Function)3 HeronTopology (org.apache.heron.api.HeronTopology)3 ShuffleStreamGrouping (org.apache.heron.api.grouping.ShuffleStreamGrouping)3 Utils (org.apache.heron.api.utils.Utils)3