@Test
public void testMergeOfTwoStreams() throws Exception
{

	// iterators
	List<MutableObjectIterator<Tuple2<Integer, String>>> iterators = new ArrayList<>();
	iterators.add(newIterator(new int[] { 1, 2, 4, 5, 10 }, new String[] { "1", "2", "4", "5", "10" }));
	iterators.add(newIterator(new int[] { 3, 6, 7, 10, 12 }, new String[] { "3", "6", "7", "10", "12" }));
	
	final int[] expected = new int[] {1, 2, 3, 4, 5, 6, 7, 10, 10, 12};
	// comparator
	TypeComparator<Integer> comparator = new IntComparator(true);
	// merge iterator
	MutableObjectIterator<Tuple2<Integer, String>> iterator = new MergeIterator<>(iterators, this.comparator);
	// check expected order
	Tuple2<Integer, String> rec1 = new Tuple2<>();
	Tuple2<Integer, String> rec2 = new Tuple2<>();
	int k1 = 0;
	int k2 = 0;
	
	int pos = 1;
	
	Assert.assertTrue((rec1 = iterator.next(rec1)) != null);
	Assert.assertEquals(expected[0], rec1.f0.intValue());
	
	while ((rec2 = iterator.next(rec2)) != null) {
		k1 = rec1.f0;
		k2 = rec2.f0;
		
		Assert.assertTrue(comparator.compare(k1, k2) <= 0);
		Assert.assertEquals(expected[pos++], k2); 
		
		Tuple2<Integer, String> tmp = rec1;
		rec1 = rec2;
		rec2 = tmp;
	}
}