ShuffleModel analyzed = shuffle(CoGroupStage.class);
ShuffleKeyEmitter emitter = new ShuffleKeyEmitter(environment);
Name name = emitter.emit(analyzed);
ClassLoader loader = start();
SegmentedWritable key = (SegmentedWritable) create(loader, name);
List<Segment> segments = analyzed.getSegments();
assertThat(segments.size(), is(2));
Segment seg1 = segments.get(0);
Segment seg2 = segments.get(1);
assertThat(seg1.getTerms().size(), is(2));
assertThat(seg2.getTerms().size(), is(2));
Ex1 ex1 = new Ex1();
ex1.setSid(1);
ex1.setValue(100);
ex1.setStringAsString("ex1");
setShuffleKey(seg1, key, ex1);
assertThat(key.getSegmentId(), is(seg1.getPortId()));
Object k1value = getKeyGroupField(seg1, "value", key);
assertThat(k1value, is((Object) ex1.getValueOption()));
Object k1sid = getKeySortField(seg1, "sid", key);
assertThat(k1sid, is((Object) ex1.getSidOption()));
Ex2 ex2 = new Ex2();
ex2.setSid(2);
ex2.setValue(200);
ex2.setStringAsString("ex2");
setShuffleKey(seg2, key, ex2);
assertThat(key.getSegmentId(), is(seg2.getPortId()));
Object k2value = getKeyGroupField(seg2, "value", key);
assertThat(k2value, is((Object) ex2.getValueOption()));
Object k2string = getKeySortField(seg2, "string", key);
assertThat(k2string, is((Object) ex2.getStringOption()));
}