Package com.asakusafw.compiler.flow

Examples of com.asakusafw.compiler.flow.FlowGraphGenerator


    /**
     * {@link FlowPath#createBlock(FlowGraph, int, boolean, boolean)}
     */
    @Test
    public void createBlock_empty() {
        FlowGraphGenerator gen = graph();
        gen.defineInput("in");
        gen.defineOutput("out");
        gen.connect("in", "out");
        FlowPath path = FlowGraphUtil.getSucceedBoundaryPath(gen.get("in"));

        FlowBlock b0 = path.createBlock(gen.toGraph(), 0, true, true);
        assertThat(b0.getElements(), is(gen.getAsSet("in", "out")));
        assertThat(input(b0.getBlockInputs()), is(gen.inputs()));
        assertThat(output(b0.getBlockOutputs()), is(gen.outputs()));

        FlowBlock b1 = path.createBlock(gen.toGraph(), 0, false, true);
        assertThat(b1.getElements(), is(gen.getAsSet("out")));
        assertThat(input(b1.getBlockInputs()), is(gen.inputs("out")));
        assertThat(output(b1.getBlockOutputs()), is(gen.outputs()));

        FlowBlock b2 = path.createBlock(gen.toGraph(), 0, true, false);
        assertThat(b2.getElements(), is(gen.getAsSet("in")));
        assertThat(input(b2.getBlockInputs()), is(gen.inputs()));
        assertThat(output(b2.getBlockOutputs()), is(gen.outputs("in")));

        try {
            path.createBlock(gen.toGraph(), 0, false, false);
            fail();
        } catch (IllegalArgumentException e) {
            // ok
        }
    }
View Full Code Here


            // ok
        }
    }

    private FlowGraphGenerator graph() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.defineInput("in2");
        gen.defineInput("in3");
        gen.defineOutput("out1");
        gen.defineOutput("out2");
        gen.defineOutput("out3");
        gen.definePseud("a", FlowBoundary.STAGE);
        gen.definePseud("b", FlowBoundary.STAGE);
        gen.definePseud("c", FlowBoundary.STAGE);
        gen.definePseud("d", FlowBoundary.STAGE);
        gen.definePseud("e", FlowBoundary.STAGE);
        gen.definePseud("f", FlowBoundary.STAGE);
        gen.defineOperator("op1", "in", "out");
        gen.defineOperator("op2", "in", "out");
        gen.connect("in1", "a").connect("a", "op1").connect("op1", "d").connect("d", "out1");
        gen.connect("in2", "b").connect("b", "op2").connect("op2", "e").connect("e", "out2");
        gen.connect("in1", "c").connect("c", "op1").connect("op2", "f").connect("f", "out1");
        gen.connect("in3", "op2").connect("op1", "out3");
        return gen;
    }
View Full Code Here

    /**
     * {@link FlowPath#union(FlowPath)}
     */
    @Test
    public void union() {
        FlowGraphGenerator gen = new FlowGraphGenerator();
        gen.defineInput("in1");
        gen.defineInput("in2");
        gen.defineOutput("out1");
        gen.defineOutput("out2");
        gen.definePseud("a", FlowBoundary.STAGE);
        gen.definePseud("b", FlowBoundary.STAGE);
        gen.definePseud("c", FlowBoundary.STAGE);
        gen.definePseud("d", FlowBoundary.STAGE);
        gen.definePseud("e", FlowBoundary.STAGE);
        gen.defineOperator("op1", "in", "out");
        gen.defineOperator("op2", "in", "out");

        gen.connect("in1", "a").connect("a", "op1").connect("op1", "c").connect("c", "out1");
        gen.connect("in2", "b").connect("b", "op2").connect("op2", "d").connect("d", "out2");
        gen.connect("op1", "e").connect("e", "out2");

        FlowPath a = FlowGraphUtil.getSucceedBoundaryPath(gen.get("a"));
        FlowPath b = FlowGraphUtil.getSucceedBoundaryPath(gen.get("b"));

        FlowPath path = a.union(b);
        assertThat(path.getStartings(), is(gen.getAsSet("a", "b")));
        assertThat(path.getPassings(), is(gen.getAsSet("op1", "op2")));
        assertThat(path.getArrivals(), is(gen.getAsSet("c", "d", "e")));
    }
View Full Code Here

    /**
     * {@link StagePlanner#validate(FlowGraph)}
     */
    @Test
    public void validate_componentError() {
        FlowGraphGenerator comp = new FlowGraphGenerator();
        comp.defineInput("in");
        comp.defineOperator("op", "in", "out opened");
        comp.defineOutput("out");
        comp.connect("in", "op.in").connect("op.out", "out");


        gen.defineInput("in");
        gen.defineFlowPart("c", comp.toGraph());
        gen.defineOutput("out");
        gen.connect("in", "c.in").connect("c.out", "out");

        FlowGraph graph = gen.toGraph();
        assertThat(getPlanner().validate(graph), is(false));
View Full Code Here

    /**
     * {@link StagePlanner#normalizeFlowGraph(FlowGraph)}
     */
    @Test
    public void normalizeFlowGraph_component() {
        FlowGraphGenerator comp = new FlowGraphGenerator();
        comp.defineInput("in");
        comp.defineOperator("op1", "in", "out");
        comp.definePseud("id");
        comp.defineOutput("out1");
        comp.defineOutput("out2");
        comp.connect("in", "op1").connect("op1", "id").connect("id", "out1");
        comp.connect("id", "out2");

        gen.defineInput("in");
        gen.defineFlowPart("c", comp.toGraph());
        gen.defineOutput("out");
        gen.connect("in", "c").connect("c.out1", "out").connect("c.out2", "out");

        FlowGraph graph = gen.toGraph();
        getPlanner().normalizeFlowGraph(graph);
        deletePseuds(graph);

        assertThat(succ(gen.get("in")), is(comp.get("op1")));
        assertThat(succ(comp.get("op1")), is(gen.get("out")));
        assertThat(pred(gen.get("out")), is(comp.get("op1")));
        assertThat(pred(comp.get("op1")), is(gen.get("in")));
    }
View Full Code Here

    /**
     * {@link StagePlanner#plan(FlowGraph)}
     */
    @Test
    public void plan_flowpart() {
        FlowGraphGenerator comp = new FlowGraphGenerator();
        comp.defineInput("in");
        comp.defineOperator("op1", "in", "out");
        comp.defineOperator("op2", "in", "out", FlowBoundary.SHUFFLE);
        comp.defineOutput("out");
        comp.connect("in", "op1").connect("op1", "op2").connect("op2", "out");

        gen.defineInput("in");
        gen.defineFlowPart("c", comp.toGraph());
        gen.defineOutput("out");
        gen.connect("in", "c").connect("c", "out");

        StageGraph stages = getPlanner().plan(gen.toGraph());

        assertThat(stages.getInput().getBlockOutputs().size(), is(1));
        assertThat(stages.getOutput().getBlockInputs().size(), is(1));
        assertThat(stages.getStages().size(), is(1));

        StageBlock mr = stages.getStages().get(0);
        assertThat(mr.getMapBlocks().size(), is(1));
        assertThat(mr.getReduceBlocks().isEmpty(), is(false));

        FlowBlock mapper = single(mr.getMapBlocks());
        FlowBlock reducer = single(mr.getReduceBlocks());

        assertThat(FlowBlock.isConnected(
                stages.getInput().getBlockOutputs().get(0),
                mapper.getBlockInputs().get(0)), is(true));
        assertThat(FlowBlock.isConnected(
                mapper.getBlockOutputs().get(0),
                reducer.getBlockInputs().get(0)), is(true));
        assertThat(FlowBlock.isConnected(
                reducer.getBlockOutputs().get(0),
                stages.getOutput().getBlockInputs().get(0)), is(true));

        assertThat(mapper.getElements().size(), is(1));
        FlowElement mapperOp = single(mapper.getElements());
        assertThat(mapperOp.getDescription(), is(comp.desc("op1")));

        assertThat(reducer.getElements().size(), is(1));
        FlowElement reducerOp = single(reducer.getElements());
        assertThat(reducerOp.getDescription(), is(comp.desc("op2")));
    }
View Full Code Here

    /**
     * {@link StagePlanner#plan(FlowGraph)}
     */
    @Test
    public void plan_flowpart_nested() {
        FlowGraphGenerator fp2 = new FlowGraphGenerator();
        fp2.defineInput("in");
        fp2.defineOperator("op1", "in", "out");
        fp2.defineOutput("out");
        fp2.connect("in", "op1").connect("op1", "out");

        FlowGraphGenerator fp1 = new FlowGraphGenerator();
        fp1.defineInput("in");
        fp1.defineFlowPart("fp2", fp2.toGraph());
        fp1.defineOutput("out");
        fp1.connect("in", "fp2").connect("fp2", "out");

        gen.defineInput("in");
        gen.defineFlowPart("fp1", fp1.toGraph());
        gen.defineOutput("out");
        gen.connect("in", "fp1").connect("fp1", "out");

        StageGraph stages = getPlanner().plan(gen.toGraph());

View Full Code Here

    /**
     * {@link StagePlanner#plan(FlowGraph)}
     */
    @Test
    public void plan_flowpart_deep() {
        FlowGraphGenerator fp4 = new FlowGraphGenerator();
        fp4.defineInput("in");
        fp4.defineOperator("op1", "in", "out");
        fp4.defineOutput("out");
        fp4.connect("in", "op1").connect("op1", "out");

        FlowGraphGenerator fp3 = new FlowGraphGenerator();
        fp3.defineInput("in");
        fp3.defineFlowPart("fp4", fp4.toGraph());
        fp3.defineOutput("out");
        fp3.connect("in", "fp4").connect("fp4", "out");

        FlowGraphGenerator fp2 = new FlowGraphGenerator();
        fp2.defineInput("in");
        fp2.defineFlowPart("fp3", fp3.toGraph());
        fp2.defineOutput("out");
        fp2.connect("in", "fp3").connect("fp3", "out");

        FlowGraphGenerator fp1 = new FlowGraphGenerator();
        fp1.defineInput("in");
        fp1.defineFlowPart("fp2", fp2.toGraph());
        fp1.defineOutput("out");
        fp1.connect("in", "fp2").connect("fp2", "out");

        gen.defineInput("in");
        gen.defineFlowPart("fp1", fp1.toGraph());
        gen.defineOutput("out");
        gen.connect("in", "fp1").connect("fp1", "out");

        StageGraph stages = getPlanner().plan(gen.toGraph());

View Full Code Here

    /**
     * {@link StagePlanner#plan(FlowGraph)}
     */
    @Test
    public void plan_flowpart_wide() {
        FlowGraphGenerator fp2a = new FlowGraphGenerator();
        fp2a.defineInput("in");
        fp2a.defineOperator("op1", "in", "out");
        fp2a.defineOutput("out");
        fp2a.connect("in", "op1").connect("op1", "out");

        FlowGraphGenerator fp2b = new FlowGraphGenerator();
        fp2b.defineInput("in");
        fp2b.defineOperator("op2", "in", "out");
        fp2b.defineOutput("out");
        fp2b.connect("in", "op2").connect("op2", "out");

        FlowGraphGenerator fp1 = new FlowGraphGenerator();
        fp1.defineInput("in");
        fp1.defineFlowPart("fp2a", fp2a.toGraph());
        fp1.defineFlowPart("fp2b", fp2b.toGraph());
        fp1.defineOutput("out");
        fp1.connect("in", "fp2a").connect("fp2a", "fp2b").connect("fp2b", "out");

        gen.defineInput("in");
        gen.defineFlowPart("fp1", fp1.toGraph());
        gen.defineOutput("out");
        gen.connect("in", "fp1").connect("fp1", "out");

        FlowCompilerOptions options = new FlowCompilerOptions();
        options.setCompressFlowPart(true);
View Full Code Here

TOP

Related Classes of com.asakusafw.compiler.flow.FlowGraphGenerator

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.