    @Test
    public void testMergingIntTermDocIterator() throws ImhotepOutOfMemoryException, IOException {

        /* make session 1 */
        MockFlamdexReader r1 =
                new MockFlamdexReader(Arrays.asList("if1", "if2", "if3"), Arrays.asList("sf1"),
                                      Arrays.asList("if1", "if2"), 10);

        r1.addIntTerm("if1", 0, 0);
        r1.addIntTerm("if1", 1, 1);
        r1.addIntTerm("if1", 2, 2);
        r1.addIntTerm("if1", 3, 3);
        r1.addIntTerm("if1", 4, 4);

        r1.addIntTerm("if2", 5, 5);
        r1.addIntTerm("if2", 6, 6);
        r1.addIntTerm("if2", 7, 7);
        r1.addIntTerm("if2", 8, 8);
        r1.addIntTerm("if2", 9, 9);

        r1.addIntTerm("if3", 0, 0);
        r1.addIntTerm("if3", 1, 1);
        r1.addIntTerm("if3", 2, 2);
        r1.addIntTerm("if3", 3, 3);
        r1.addIntTerm("if3", 4, 4);

        r1.addStringTerm("sf1", "☃", Arrays.asList(1, 4, 5, 6, 7));

        ImhotepLocalSession session1 = new ImhotepLocalSession(r1);

        /* make session 2 */
        MockFlamdexReader r2 =
                new MockFlamdexReader(Arrays.asList("if1", "if2"), Arrays.asList("sf1"),
                                      Arrays.asList("if1", "if2"), 10);
        r2.addIntTerm("if1", 0, 5);
        r2.addIntTerm("if1", 1, 6);
        r2.addIntTerm("if1", 2, 7);
        r2.addIntTerm("if1", 3, 8);
        r2.addIntTerm("if1", 4, 9);

        r2.addIntTerm("if2", 0, 0);
        r2.addIntTerm("if2", 1, 1);
        r2.addIntTerm("if2", 2, 2);
        r2.addIntTerm("if2", 3, 3);
        r2.addIntTerm("if2", 4, 4);

        r2.addStringTerm("sf1", "☃", Arrays.asList(1, 4, 5, 6, 7));

        ImhotepLocalSession session2 = new ImhotepLocalSession(r2);

        /* make session 3 */
        MockFlamdexReader r3 =
                new MockFlamdexReader(Arrays.asList("if1", "if2"), Arrays.asList("sf1"),
                                      Arrays.asList("if1", "if2"), 5);
        r3.addIntTerm("if2", 0, 0);
        r3.addIntTerm("if2", 1, 1);
        r3.addIntTerm("if2", 2, 2);
        r3.addIntTerm("if2", 3, 3);
        r3.addIntTerm("if2", 4, 4);

        r2.addStringTerm("sf1", "☃", Arrays.asList(1, 4, 5, 6, 7));

        ImhotepLocalSession session3 = new ImhotepLocalSession(r3);

        /* merge sessions */
        MockFlamdexWriter w = new MockFlamdexWriter("foo");
        IndexReWriter irw =
                new IndexReWriter(
                                  Arrays.asList(session3, session1, session2),
                                  session1,
                                  new MemoryReservationContext(
                                                               new ImhotepMemoryPool(Long.MAX_VALUE)));
        irw.optimizeIndecies(Arrays.asList("if1", "if2"), new ArrayList<String>(), w);

        assertEquals("Merged Int Fields are wrong", Arrays.asList("if1", "if2"), w.getIntFields());
        assertEquals("Merged Int Terms are wrong", Arrays.asList(5, 20), w.getIntTerms().get("if1")
                                                                          .get(0L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(6, 21), w.getIntTerms().get("if1")
                                                                          .get(1L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(7, 22), w.getIntTerms().get("if1")
                                                                          .get(2L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(8, 23), w.getIntTerms().get("if1")
                                                                          .get(3L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(9, 24), w.getIntTerms().get("if1")
                                                                          .get(4L));

        assertEquals("Merged Int Terms are wrong", Arrays.asList(0, 15), w.getIntTerms().get("if2")
                                                                          .get(0L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(1, 16), w.getIntTerms().get("if2")
                                                                          .get(1L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(2, 17), w.getIntTerms().get("if2")
                                                                          .get(2L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(3, 18), w.getIntTerms().get("if2")
                                                                          .get(3L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(4, 19), w.getIntTerms().get("if2")
                                                                          .get(4L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(10), w.getIntTerms().get("if2")
                                                                       .get(5L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(11), w.getIntTerms().get("if2")
                                                                       .get(6L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(12), w.getIntTerms().get("if2")
                                                                       .get(7L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(13), w.getIntTerms().get("if2")
                                                                       .get(8L));
        assertEquals("Merged Int Terms are wrong", Arrays.asList(14), w.getIntTerms().get("if2")
                                                                       .get(9L));

        session1.close();
        session2.close();
        session3.close();
    }