From: <tho...@us...> - 2010-09-14 19:18:49
|
Revision: 3551 http://bigdata.svn.sourceforge.net/bigdata/?rev=3551&view=rev Author: thompsonbry Date: 2010-09-14 19:18:42 +0000 (Tue, 14 Sep 2010) Log Message: ----------- minor edit Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-09-14 19:15:27 UTC (rev 3550) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-09-14 19:18:42 UTC (rev 3551) @@ -488,8 +488,8 @@ initialBindings.set(Var.var("x"), new Constant<String>("Mary")); - runningQuery.startQuery(new BindingSetChunk(queryEngine, queryId, - startId,// + runningQuery.startQuery(new BindingSetChunk<IBindingSet>( + queryEngine, queryId, startId,// -1, // partitionId newBindingSetIterator(initialBindings))); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <ble...@us...> - 2010-10-21 17:23:14
|
Revision: 3835 http://bigdata.svn.sourceforge.net/bigdata/?rev=3835&view=rev Author: blevine218 Date: 2010-10-21 17:23:06 +0000 (Thu, 21 Oct 2010) Log Message: ----------- added true and false test cases for ConditionalRoutingOp Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-10-20 18:39:05 UTC (rev 3834) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-10-21 17:23:06 UTC (rev 3835) @@ -1623,15 +1623,262 @@ } /** - * @todo Write unit tests for the {@link ConditionalRoutingOp}? + * Unit test for {@link ConditionalRoutingOp}. This test case tests when the + * condition is true (the joins are not skipped) in which case the test + * (and results) are essentially identical to test_query_join2(). */ - public void test_query_join2_conditionalRouting() { + public void test_query_join2_conditionalRoutingTrue() throws Exception { + int startId = 1; + int joinId1 = 2; + int joinId2 = 3; + + IConstraint condition = new EQConstant(Var.var("x"), new Constant<String>("Mary")); + RunningQuery runningQuery = initQueryWithConditionalRoutingOp(condition, startId, joinId1, joinId2); - fail("write test"); + // verify solutions. + { + // the expected solution. + final IBindingSet[] expected = new IBindingSet[] {// + new ArrayBindingSet(// + new IVariable[] { Var.var("x"), Var.var("y"), Var.var("z")},// + new IConstant[] { new Constant<String>("Mary"), + new Constant<String>("Paul"), + new Constant<String>("Leon")}// + ) }; + assertSameSolutions(expected, runningQuery.iterator()); + + } + + // Wait until the query is done. + runningQuery.get(); + final Map<Integer, BOpStats> statsMap = runningQuery.getStats(); + { + // validate the stats map. + assertNotNull(statsMap); + log.info(statsMap.toString()); + assertEquals(5, statsMap.size()); + } + + // validate the stats for the start operator. + { + final BOpStats stats = statsMap.get(startId); + assertNotNull(stats); + if (log.isInfoEnabled()) + log.info("start: " + stats.toString()); + + // verify query solution stats details. + assertEquals(1L, stats.chunksIn.get()); + assertEquals(1L, stats.unitsIn.get()); + assertEquals(1L, stats.unitsOut.get()); + assertEquals(1L, stats.chunksOut.get()); + } + + // validate the stats for the 1st join operator. + { + final BOpStats stats = statsMap.get(joinId1); + assertNotNull(stats); + if (log.isInfoEnabled()) + log.info("join1: " + stats.toString()); + + // verify query solution stats details. + assertEquals(1L, stats.chunksIn.get()); + assertEquals(1L, stats.unitsIn.get()); + assertEquals(1L, stats.unitsOut.get()); + assertEquals(1L, stats.chunksOut.get()); + } + + // validate the stats for the 2nd join operator. + { + final BOpStats stats = statsMap.get(joinId2); + assertNotNull(stats); + if (log.isInfoEnabled()) + log.info("join2: " + stats.toString()); + + // verify query solution stats details. + assertEquals(1L, stats.chunksIn.get()); + assertEquals(1L, stats.unitsIn.get()); + assertEquals(1L, stats.unitsOut.get()); + assertEquals(1L, stats.chunksOut.get()); + } + } + + /** + * Unit test for {@link ConditionalRoutingOp}. This test case tests when the + * condition is false (the joins are skipped). + */ + public void test_query_join2_conditionalRoutingFalse() throws Exception { + int startId = 1; + int joinId1 = 2; + int joinId2 = 3; + + // 'x' is actually bound to "Mary" so this condition will be false. + IConstraint condition = new EQConstant(Var.var("x"), new Constant<String>("Fred")); + + RunningQuery runningQuery = initQueryWithConditionalRoutingOp(condition, startId, joinId1, joinId2); + // verify solutions. + { + // the expected solution. + final IBindingSet[] expected = new IBindingSet[] {// + new ArrayBindingSet(// + new IVariable[] { Var.var("x")},// + new IConstant[] { new Constant<String>("Mary")}// + ) }; + + assertSameSolutions(expected, runningQuery.iterator()); + + } + + // Wait until the query is done. + runningQuery.get(); + final Map<Integer, BOpStats> statsMap = runningQuery.getStats(); + { + // validate the stats map. + assertNotNull(statsMap); + log.info(statsMap.toString()); + assertEquals(5, statsMap.size()); + } + + // validate the stats for the start operator. + { + final BOpStats stats = statsMap.get(startId); + assertNotNull(stats); + + if (log.isInfoEnabled()) + log.info("start: " + stats.toString()); + + // verify query solution stats details. + assertEquals(1L, stats.chunksIn.get()); + assertEquals(1L, stats.unitsIn.get()); + assertEquals(1L, stats.unitsOut.get()); + assertEquals(1L, stats.chunksOut.get()); + } + + // validate the stats for the 1st join operator. This will have been skipped + // and so the counts will be 0. + { + final BOpStats stats = statsMap.get(joinId1); + assertNotNull(stats); + if (log.isInfoEnabled()) + log.info("join1: " + stats.toString()); + + // verify query solution stats details. + assertEquals(0L, stats.chunksIn.get()); + assertEquals(0L, stats.unitsIn.get()); + assertEquals(0L, stats.unitsOut.get()); + assertEquals(0L, stats.chunksOut.get()); + } + + // validate the stats for the 2nd join operator. This will have been skipped + // and so the counts will be 0. + { + final BOpStats stats = statsMap.get(joinId2); + assertNotNull(stats); + if (log.isInfoEnabled()) + log.info("join2: " + stats.toString()); + + // verify query solution stats details. + assertEquals(0L, stats.chunksIn.get()); + assertEquals(0L, stats.unitsIn.get()); + assertEquals(0L, stats.unitsOut.get()); + assertEquals(0L, stats.chunksOut.get()); + } + } + /** + * Helper method to initialize a BOp tree that includes a ConditionalRoutinOp + * + * @param condition the condition to be tested in the ConditionalalRoutingOp + * @param startId the bopId of the startOp + * @param joinId1 the bopId of the first join + * @param joinId2 the bopId of the second join + * + * @return the RunningQuery created + * + * @throws Exception + */ + private RunningQuery initQueryWithConditionalRoutingOp(IConstraint condition, int startId, int joinId1, int joinId2) throws Exception { + final int predId1 = 10; + final int predId2 = 11; + final int condId = 12; + final int sliceId = 13; + + final PipelineOp startOp = new StartOp(new BOp[] {}, + NV.asMap(new NV[] {// + new NV(Predicate.Annotations.BOP_ID, startId),// + new NV(SliceOp.Annotations.EVALUATION_CONTEXT, + BOpEvaluationContext.CONTROLLER),// + })); + + final Predicate<?> pred1Op = new Predicate<E>(new IVariableOrConstant[] { + Var.var("x"), Var.var("y") }, NV + .asMap(new NV[] {// + new NV(Predicate.Annotations.RELATION_NAME, + new String[] { namespace }),// + new NV(Predicate.Annotations.BOP_ID, predId1),// + new NV(Predicate.Annotations.TIMESTAMP, ITx.READ_COMMITTED),// + })); + + final Predicate<?> pred2Op = new Predicate<E>(new IVariableOrConstant[] { + Var.var("y"), Var.var("z") }, NV + .asMap(new NV[] {// + new NV(Predicate.Annotations.RELATION_NAME, + new String[] { namespace }),// + new NV(Predicate.Annotations.BOP_ID, predId2),// + new NV(Predicate.Annotations.TIMESTAMP, ITx.READ_COMMITTED),// + })); + + final ConditionalRoutingOp cond = new ConditionalRoutingOp(new BOp[]{startOp}, + NV.asMap(new NV[]{// + new NV(BOp.Annotations.BOP_ID,condId), + new NV(PipelineOp.Annotations.SINK_REF, joinId1), + new NV(PipelineOp.Annotations.ALT_SINK_REF, sliceId), + new NV(ConditionalRoutingOp.Annotations.CONDITION, condition), + })); + + final PipelineOp join1Op = new PipelineJoin<E>(// + cond, pred1Op,// + NV.asMap(new NV[] {// + new NV(Predicate.Annotations.BOP_ID, joinId1),// + })); + + final PipelineOp join2Op = new PipelineJoin<E>(// + join1Op, pred2Op, // + NV.asMap(new NV[] {// + new NV(Predicate.Annotations.BOP_ID, joinId2),// + })); + + final PipelineOp sliceOp = new SliceOp(// + new BOp[]{join2Op}, + NV.asMap(new NV[] {// + new NV(BOp.Annotations.BOP_ID, sliceId),// + new NV(BOp.Annotations.EVALUATION_CONTEXT, + BOpEvaluationContext.CONTROLLER),// + })); + + final PipelineOp query = sliceOp; + + // start the query. + final UUID queryId = UUID.randomUUID(); + final IChunkMessage<IBindingSet> initialChunkMessage; + { + final IBindingSet initialBindings = new HashBindingSet(); + initialBindings.set(Var.var("x"), new Constant<String>("Mary")); + + initialChunkMessage = new LocalChunkMessage<IBindingSet>(queryEngine, + queryId, startId,// + -1, // partitionId + newBindingSetIterator(initialBindings)); + } + + RunningQuery runningQuery = queryEngine.eval(queryId, query,initialChunkMessage); + + return runningQuery; + } + + /** * Verify the expected solutions. * * @param expected This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-11-02 12:42:28
|
Revision: 3864 http://bigdata.svn.sourceforge.net/bigdata/?rev=3864&view=rev Author: thompsonbry Date: 2010-11-02 12:42:22 +0000 (Tue, 02 Nov 2010) Log Message: ----------- Additional edit to TestQueryEngine to work around the fact that a Slice can interrupt an operator before its BOpStats have been reported/aggregated. In this case, the race appeared with the StartOp. Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-11-02 12:11:41 UTC (rev 3863) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-11-02 12:42:22 UTC (rev 3864) @@ -911,20 +911,28 @@ log.info(statsMap.toString()); } - // validate the stats for the start operator. - { - final BOpStats stats = statsMap.get(startId); - assertNotNull(stats); - if (log.isInfoEnabled()) - log.info("start: " + stats.toString()); + /* + * Note: SliceOp can cause the Start operator to be interrupted. If this + * occurs, the BOpStats for the join are not reported and aggregated + * reliably (there is a race between the completion of the Start and its + * interrupt by the slice). Since this unit test has a slice which will + * interrupt the running query, we can not test the stats on the Start + * reliably for this unit test. + */ +// // validate the stats for the start operator. +// { +// final BOpStats stats = statsMap.get(startId); +// assertNotNull(stats); +// if (log.isInfoEnabled()) +// log.info("start: " + stats.toString()); +// +// // verify query solution stats details. +// assertEquals(1L, stats.chunksIn.get()); +// assertEquals(1L, stats.unitsIn.get()); +// assertEquals(1L, stats.unitsOut.get()); +// assertEquals(1L, stats.chunksOut.get()); +// } - // verify query solution stats details. - assertEquals(1L, stats.chunksIn.get()); - assertEquals(1L, stats.unitsIn.get()); - assertEquals(1L, stats.unitsOut.get()); - assertEquals(1L, stats.chunksOut.get()); - } - /* * Note: SliceOp can cause the Join operator to be interrupted. If this * occurs, the BOpStats for the join are not reported and aggregated This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <tho...@us...> - 2010-12-12 23:22:57
|
Revision: 4005 http://bigdata.svn.sourceforge.net/bigdata/?rev=4005&view=rev Author: thompsonbry Date: 2010-12-12 22:22:27 +0000 (Sun, 12 Dec 2010) Log Message: ----------- Modified to use a different pattern to construct the binding sets in one of the unit tests (this relied on a constructor which is no longer public). Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-12-12 22:22:01 UTC (rev 4004) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/engine/TestQueryEngine.java 2010-12-12 22:22:27 UTC (rev 4005) @@ -458,20 +458,31 @@ * * Note: We can't bind y in advance for the primary index! */ - final IBindingSet[] source = new IBindingSet[] {// - new HashBindingSet(new ArrayBindingSet(// - new IVariable[] { x },// - new IConstant[] { new Constant<String>("Paul") }// - )),// - new HashBindingSet(new ArrayBindingSet(// - new IVariable[] { x },// - new IConstant[] { new Constant<String>("Leon") }// - )), - new HashBindingSet(new ArrayBindingSet(// - new IVariable[] { x },// - new IConstant[] { new Constant<String>("Mary") }// - )), + final IBindingSet[] source; + { + final IBindingSet bset1 = new HashBindingSet(); + bset1.set(x, new Constant<String>("Paul")); + final IBindingSet bset2 = new HashBindingSet(); + bset2.set(x, new Constant<String>("Leon")); + final IBindingSet bset3 = new HashBindingSet(); + bset3.set(x, new Constant<String>("Mary")); + + source = new IBindingSet[] {// + bset1,bset2,bset3 +// new HashBindingSet(new ArrayBindingSet(// +// new IVariable[] { x },// +// new IConstant[] { new Constant<String>("Paul") }// +// )),// +// new HashBindingSet(new ArrayBindingSet(// +// new IVariable[] { x },// +// new IConstant[] { new Constant<String>("Leon") }// +// )), +// new HashBindingSet(new ArrayBindingSet(// +// new IVariable[] { x },// +// new IConstant[] { new Constant<String>("Mary") }// +// )), }; + } // Put each source binding set into a chunk by itself. final IBindingSet[][] sources = new IBindingSet[source.length][]; for (int i = 0; i < sources.length; i++) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |