@Test
public void testQueryWithVaryingTupleAndPatternLengths() {

    List<JoinHelper<String, String>> consumers1;
    JoinHelper<String, String> consumer1a, consumer1b;
    consumers1 = addQuery("query1", graphPattern(
            tuplePattern("?x", "knows", "?y"),
            tuplePattern("?y", "name", "'Ford Prefect'", "g1"))).getAllHelpers();
    consumer1a = consumers1.get(0);
    consumer1b = consumers1.get(1);
    assertArrayEquals(new String[]{"?x", "?y"}, consumer1a.getKeys());
    assertArrayEquals(new String[]{"?y"}, consumer1b.getKeys());
    // fully matching tuple of length 3
    queryIndex.add(tuple("Arthur", "knows", "Ford"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 1);
    expectSolutions(consumer1a, 1, "?x", "Arthur");
    expectSolutions(consumer1a, 1, "?y", "Ford");
    expectIndexSolutions(consumer1b, 0);
    expectQuerySolutions("query1", 0);
    // tuple of length 3 is too short; doesn't match
    queryIndex.add(tuple("Ford", "name", "'Ford Prefect'"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1b, 0);
    expectQuerySolutions("query1", 0);
    // fully matching tuple of length 4
    queryIndex.add(tuple("Ford", "name", "'Ford Prefect'", "g1"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 1);
    expectIndexSolutions(consumer1b, 1);
    expectSolutions(consumer1b, 1, "?y", "Ford");
    expectQuerySolutions("query1", 1);
    // tuple of length 5 is longer than needed; the first four terms match
    queryIndex.add(tuple("Zaphod", "knows", "Ford", "g1"), StreamProcessor.NEVER_EXPIRE);
    expectIndexSolutions(consumer1a, 2);
    expectSolutions(consumer1a, 1, "?x", "Arthur");
    expectSolutions(consumer1a, 1, "?x", "Zaphod");
    expectSolutions(consumer1a, 2, "?y", "Ford");
    expectIndexSolutions(consumer1b, 1);
    expectQuerySolutions("query1", 2);
}