@Test
public void testMergeOfTwoStreams() throws Exception
{

	// iterators
	List<MutableObjectIterator<Record>> iterators = new ArrayList<MutableObjectIterator<Record>>();
	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
	Comparator<TestData.Key> comparator = new TestData.KeyComparator();
	// merge iterator
	MutableObjectIterator<Record> iterator = new MergeIterator<Record>(iterators, this.serializer, this.comparator);
	// check expected order
	Record rec1 = new Record();
	Record rec2 = new Record();
	final Key k1 = new Key();
	final Key k2 = new Key();
	
	int pos = 1;
	
	Assert.assertTrue((rec1 = iterator.next(rec1)) != null);
	Assert.assertEquals(expected[0], rec1.getField(0, TestData.Key.class).getKey());
	
	while ((rec2 = iterator.next(rec2)) != null) {
		k1.setKey(rec1.getField(0, TestData.Key.class).getKey());
		k2.setKey(rec2.getField(0, TestData.Key.class).getKey());
		
		Assert.assertTrue(comparator.compare(k1, k2) <= 0);
		Assert.assertEquals(expected[pos++], k2.getKey()); 
		
		Record tmp = rec1;
		rec1 = rec2;
		rec2 = tmp;
	}
}