@Test
  public void testMultipleIndependentRegionsWithRangeJunction() {

    try {
      Region r3 = CacheUtils.createRegion("employees", Employee.class);
      Set add1 = new HashSet();
      add1.add(new Address("411045", "Baner"));
      add1.add(new Address("411001", "DholePatilRd"));
      for (int i = 0; i < 4; i++) {
        r3.put(i + "", new Employee("empName", (20 + i), i, "Mr.", (5000 + i), add1));
      }
      // compileFromClause returns a List<CompiledIteratorDef>
      QCompiler compiler = new QCompiler();
      List list = compiler
          .compileFromClause(SEPARATOR + "portfolio p, p.positions," + SEPARATOR + "employees e");
      ExecutionContext context = new QueryExecutionContext(null, CacheUtils.getCache());
      context.newScope(context.associateScopeID());

      // qs.createIndex("statusIndex",
      // IndexType.FUNCTIONAL,"status","/portfolio");
      qs.createIndex("idIndex", IndexType.FUNCTIONAL, "ID", SEPARATOR + "portfolio p");
      qs.createIndex("empid", IndexType.FUNCTIONAL, "empId", SEPARATOR + "employees e");
      for (final Object o : list) {
        CompiledIteratorDef iterDef = (CompiledIteratorDef) o;
        context.addDependencies(new CompiledID("dummy"), iterDef.computeDependencies(context));
        RuntimeIterator rIter = iterDef.getRuntimeIterator(context);
        context.bindIterator(rIter);
        context.addToIndependentRuntimeItrMap(iterDef);
      }
      CompiledComparison[] cv = new CompiledComparison[5];
      cv[0] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "status"),
          new CompiledLiteral("active"), OQLLexerTokenTypes.TOK_EQ);
      cv[1] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "type"),
          new CompiledLiteral("type1"), OQLLexerTokenTypes.TOK_EQ);

      cv[2] = new CompiledComparison(new CompiledPath(new CompiledID("e"), "empId"),
          new CompiledLiteral(10), OQLLexerTokenTypes.TOK_GT);
      cv[3] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"),
          new CompiledLiteral(10), OQLLexerTokenTypes.TOK_GT);
      cv[4] = new CompiledComparison(new CompiledPath(new CompiledID("p"), "ID"),
          new CompiledLiteral(15), OQLLexerTokenTypes.TOK_GT);
      CompiledJunction cj = new CompiledJunction(cv, OQLLexerTokenTypes.LITERAL_and);
      context.addDependencies(new CompiledID("dummy"), cj.computeDependencies(context));
      cj.getPlanInfo(context);
      OrganizedOperands oo = cj.testOrganizedOperands(context);
      assertNotNull("OO is null", oo);
      assertTrue("Filter operand of OO not AllGroupJunction",
          oo.filterOperand instanceof AllGroupJunction);
      AllGroupJunction agj = (AllGroupJunction) oo.filterOperand;
      List filterableCC = agj.getGroupOperands();
      assertTrue(agj.getIterOperands().isEmpty());
      assertTrue(agj.getGroupOperands().size() == 2);
      assertTrue(agj.getGroupOperands().get(0) instanceof GroupJunction
          || agj.getGroupOperands().get(1) instanceof GroupJunction);
      assertTrue(agj.getGroupOperands().get(0) instanceof RangeJunction
          || agj.getGroupOperands().get(1) instanceof RangeJunction);
      RangeJunction rj = null;
      if (agj.getGroupOperands().get(0) instanceof RangeJunction) {
        rj = (RangeJunction) agj.getGroupOperands().get(0);
      } else {
        rj = (RangeJunction) agj.getGroupOperands().get(1);
      }

      OrganizedOperands oo1 = rj.organizeOperands(context);
      assertTrue(oo1.filterOperand == cv[4]);
      assertNotNull(oo1.iterateOperand);
      assertTrue(((CompiledJunction) oo1.iterateOperand).getOperands().contains(cv[0]));
      assertTrue(((CompiledJunction) oo1.iterateOperand).getOperands().contains(cv[1]));
    } catch (Exception e) {
      e.printStackTrace();
      fail("Test failed sue to Exception = " + e);
    }

  }
Tests that the organized operands work correctly whether it is multiple GroupJunctions as part
of AllGroupJunction or a RangeJunction and GroupJunction. Since where previously it used to be
only Group can now be Group or Range , the source code needs to ensure that it does not type
cast wrongly a RangeJunction into a GroupJunction. Instead the source code should only type
cast it to AbstractGroupOrRangeJunction Case p.status = active and p.type = type1 and emp.id
>10 and p.id > 10 and p.id > 15
geode-core/src/integrationTest/java/org/apache/geode/cache/query/internal/CompiledJunctionInternalsJUnitTest.java