/** グループごとの最小値を求めるテスト。 */ @Test public void withParameter() { List<StageModel> stages = compile(GroupSortFlowWithParameter.class); StageModel stage = stages.get(0); Assume.assumeThat(stage.getReduceUnits().size(), is(1)); ReduceUnit reduce = stage.getReduceUnits().get(0); Fragment fragment = reduce.getFragments().get(0); Name name = fragment.getCompiled().getQualifiedName(); ClassLoader loader = start(); PortMapper mapper = new PortMapper(fragment); MockResult<Ex1> r1 = mapper.add("r1", new Ex1Copier()); MockResult<Ex1> r2 = mapper.add("r2", new Ex1Copier()); @SuppressWarnings("unchecked") Rendezvous<Writable> f = (Rendezvous<Writable>) create(loader, name, mapper.toArguments()); Segment segment = stage.getShuffleModel().findSegment(fragment.getInputPorts().get(0)); SegmentedWritable value = createShuffleValue(loader, stage); Ex1 ex1 = new Ex1(); f.begin(); ex1.setValue(50); setShuffleValue(segment, value, ex1); f.process(value); ex1.setValue(100); setShuffleValue(segment, value, ex1); f.process(value); ex1.setValue(101); setShuffleValue(segment, value, ex1); f.process(value); ex1.setValue(150); setShuffleValue(segment, value, ex1); f.process(value); f.end(); assertThat(r1.getResults().size(), is(2)); assertThat(r2.getResults().size(), is(2)); assertThat(r1.getResults().get(0).getValue(), is(50)); assertThat(r1.getResults().get(1).getValue(), is(100)); assertThat(r2.getResults().get(0).getValue(), is(101)); assertThat(r2.getResults().get(1).getValue(), is(150)); }
/** 単純なテスト。 */ @Test public void simple() { List<StageModel> stages = compile(BranchFlowSimple.class); Fragment fragment = stages.get(0).getMapUnits().get(0).getFragments().get(0); Name name = fragment.getCompiled().getQualifiedName(); ClassLoader loader = start(); PortMapper mapper = new PortMapper(fragment); MockResult<Ex1> high = mapper.create("high"); MockResult<Ex1> low = mapper.create("low"); MockResult<Ex1> stop = mapper.create("stop"); @SuppressWarnings("unchecked") Result<Ex1> f = (Result<Ex1>) create(loader, name, mapper.toArguments()); Ex1 ex1 = new Ex1(); ex1.setValue(-100); f.add(ex1); assertThat(high.getResults().size(), is(0)); assertThat(low.getResults().size(), is(0)); assertThat(stop.getResults().size(), is(1)); assertThat(stop.getResults().get(0), is(ex1)); stop.getResults().clear(); ex1.setValue(0); f.add(ex1); assertThat(high.getResults().size(), is(0)); assertThat(low.getResults().size(), is(0)); assertThat(stop.getResults().size(), is(1)); assertThat(stop.getResults().get(0), is(ex1)); stop.getResults().clear(); ex1.setValue(1); f.add(ex1); assertThat(high.getResults().size(), is(0)); assertThat(low.getResults().size(), is(1)); assertThat(stop.getResults().size(), is(0)); assertThat(low.getResults().get(0), is(ex1)); low.getResults().clear(); ex1.setValue(50); f.add(ex1); assertThat(high.getResults().size(), is(0)); assertThat(low.getResults().size(), is(1)); assertThat(stop.getResults().size(), is(0)); assertThat(low.getResults().get(0), is(ex1)); low.getResults().clear(); ex1.setValue(100); f.add(ex1); assertThat(high.getResults().size(), is(0)); assertThat(low.getResults().size(), is(1)); assertThat(stop.getResults().size(), is(0)); assertThat(low.getResults().get(0), is(ex1)); low.getResults().clear(); ex1.setValue(101); f.add(ex1); assertThat(high.getResults().size(), is(1)); assertThat(low.getResults().size(), is(0)); assertThat(stop.getResults().size(), is(0)); assertThat(high.getResults().get(0), is(ex1)); high.getResults().clear(); ex1.setValue(150); f.add(ex1); assertThat(high.getResults().size(), is(1)); assertThat(low.getResults().size(), is(0)); assertThat(stop.getResults().size(), is(0)); assertThat(high.getResults().get(0), is(ex1)); high.getResults().clear(); }