@Test
public void testQueriesWithIdenticalPatterns() {

    List<JoinHelper<String, String>> consumers1;
    JoinHelper<String, String> consumer1a, consumer1b, consumer1c, consumer1d;
    consumers1 = addQuery("query1", graphPattern(
            tuplePattern("?x", "likes", "?y", "?g"),
            tuplePattern("?x", "likes", "?y"),
            tuplePattern("?x", "likes", "?y"),
            tuplePattern("?y", "name", "'Tricia McMillan'"))).getAllHelpers();
    consumer1a = consumers1.get(0);
    consumer1b = consumers1.get(1);
    consumer1c = consumers1.get(2);
    consumer1d = consumers1.get(3);
    assertArrayEquals(new String[]{"?x", "?y", "?g"}, consumer1a.getKeys());
    assertArrayEquals(new String[]{"?x", "?y"}, consumer1b.getKeys());
    assertArrayEquals(new String[]{"?x", "?y"}, consumer1c.getKeys());
    assertArrayEquals(new String[]{"?y"}, consumer1d.getKeys());
    // irrelevant tuple
    queryIndex.add(tuple("Eddie", "name", "'Eddie'"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 0);
    expectIndexSolutions(consumer1b, 0);
    expectIndexSolutions(consumer1c, 0);
    expectIndexSolutions(consumer1d, 0);
    expectQuerySolutions("query1", 0);
    // relevant tuple
    queryIndex.add(tuple("Trillian", "name", "'Tricia McMillan'"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 0);
    expectIndexSolutions(consumer1b, 0);
    expectIndexSolutions(consumer1c, 0);
    expectIndexSolutions(consumer1d, 1);
    expectQuerySolutions("query1", 0);
    // tuple matches patterns b and c, but not a, which requires a graph
    queryIndex.add(tuple("Arthur", "likes", "Trillian"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 0);
    expectIndexSolutions(consumer1b, 1);
    expectIndexSolutions(consumer1c, 1);
    expectIndexSolutions(consumer1d, 1);
    expectQuerySolutions("query1", 0);
    // tuple matches patterns a, b, and c, and completes a single solution
    queryIndex.add(tuple("Zaphod", "likes", "Trillian", "g1"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 1);
    expectIndexSolutions(consumer1b, 2);
    expectIndexSolutions(consumer1c, 2);
    expectIndexSolutions(consumer1d, 1);
    expectQuerySolutions("query1", 1);
    // tuple matches patterns a, b, and c, but does not create duplicate solutions at b and c.
    // Another single solution is completed.
    queryIndex.add(tuple("Arthur", "likes", "Trillian", "g1"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 2);
    expectIndexSolutions(consumer1b, 2);
    expectIndexSolutions(consumer1c, 2);
    expectIndexSolutions(consumer1d, 1);
    expectQuerySolutions("query1", 2);
}