From: <tho...@us...> - 2010-09-24 14:36:56
|
Revision: 3623 http://bigdata.svn.sourceforge.net/bigdata/?rev=3623&view=rev Author: thompsonbry Date: 2010-09-24 14:36:50 +0000 (Fri, 24 Sep 2010) Log Message: ----------- Added a unit test for MapBindingSetsOverShards which exercises the condition where the key for the target access path is only partly bound (a prefix). Modified Paths: -------------- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/shards/TestMapBindingSetsOverShards.java Modified: branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/shards/TestMapBindingSetsOverShards.java =================================================================== --- branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/shards/TestMapBindingSetsOverShards.java 2010-09-24 14:30:39 UTC (rev 3622) +++ branches/QUADS_QUERY_BRANCH/bigdata/src/test/com/bigdata/bop/fed/shards/TestMapBindingSetsOverShards.java 2010-09-24 14:36:50 UTC (rev 3623) @@ -69,10 +69,6 @@ * @author <a href="mailto:tho...@us...">Bryan Thompson</a> * @version $Id: TestMapBindingSetsOverShards.java 3448 2010-08-18 20:55:58Z * thompsonbry $ - * - * FIXME More unit tests. It appears that none of these tests cover the - * case where there is a shared prefix, e.g., because at least one - * component of the selected key order is bound. */ public class TestMapBindingSetsOverShards extends AbstractEmbeddedFederationTestCase { @@ -297,13 +293,14 @@ // } } - + /** - * Unit test verifies that binding sets are correctly mapped over shards. + * Unit test verifies that binding sets are correctly mapped over shards + * when the target access path will be fully bound. * - * @throws IOException + * @throws IOException */ - public void test_mapShards() throws IOException { + public void test_mapShards_fullyBound() throws IOException { // scale-out view of the relation. final R rel = (R) fed.getResourceLocator().locate(namespace, @@ -451,6 +448,154 @@ } /** + * Unit test verifies that binding sets are correctly mapped over shards + * when only one component of the key is bound (the key has two components, + * this unit test only binds the first component in the key). + * + * @throws IOException + */ + public void test_mapShards_oneBound() throws IOException { + + // scale-out view of the relation. + final R rel = (R) fed.getResourceLocator().locate(namespace, + ITx.UNISOLATED); + + /* + * Setup the binding sets to be mapped across the shards. + */ + final Var<?> x = Var.var("x"); + final Var<?> y = Var.var("y"); + + final List<IBindingSet> data = new LinkedList<IBindingSet>(); + final List<IBindingSet> expectedPartition0 = new LinkedList<IBindingSet>(); + final List<IBindingSet> expectedPartition1 = new LinkedList<IBindingSet>(); + { + IBindingSet bset = null; + { // partition0 + bset = new HashBindingSet(); + bset.set(x, new Constant<String>("John")); +// bset.set(y, new Constant<String>("Mary")); + data.add(bset); + expectedPartition0.add(bset); + } + { // partition1 + bset = new HashBindingSet(); + bset.set(x, new Constant<String>("Mary")); +// bset.set(y, new Constant<String>("Paul")); + data.add(bset); + expectedPartition1.add(bset); + } + { // partition1 + bset = new HashBindingSet(); + bset.set(x, new Constant<String>("Paul")); +// bset.set(y, new Constant<String>("John")); + data.add(bset); + expectedPartition1.add(bset); + } + { // partition0 + bset = new HashBindingSet(); + bset.set(x, new Constant<String>("Leon")); +// bset.set(y, new Constant<String>("Paul")); + data.add(bset); + expectedPartition0.add(bset); + } + +// // partition0 +// new E("John", "Mary"),// +// new E("Leon", "Paul"),// +// // partition1 +// new E("Mary", "John"),// +// new E("Mary", "Paul"),// +// new E("Paul", "Leon"),// + + } + + final Predicate<E> pred = new Predicate<E>(new BOp[] { x, y }, NV + .asMap(new NV[] {// + new NV(Predicate.Annotations.RELATION_NAME, + new String[] { namespace }) // + })); + + final long tx = fed.getTransactionService().newTx(ITx.READ_COMMITTED); + + try { + + final MockMapBindingSetsOverShardsBuffer<E> fixture = new MockMapBindingSetsOverShardsBuffer<E>( + fed, pred, rel.getPrimaryKeyOrder(), tx, 100/* capacity */); + + // write the binding sets on the fixture. + for (IBindingSet bindingSet : data) { + + fixture.add(bindingSet); + + } + + // flush (verify #of binding sets reported by flush). + assertEquals((long) data.size(), fixture.flush()); + + /* + * Examine the output sinks, verifying that each binding set was + * mapped onto the correct index partition. + */ + { + + final List<Bundle> flushedChunks = fixture.flushedChunks; + final List<IBindingSet[]> actualPartition0 = new LinkedList<IBindingSet[]>(); + final List<IBindingSet[]> actualPartition1 = new LinkedList<IBindingSet[]>(); + for (Bundle b : flushedChunks) { + if (b.locator.getPartitionId() == 0) { + actualPartition0.add(b.bindingSets); + } else if (b.locator.getPartitionId() == 1) { + actualPartition1.add(b.bindingSets); + } else { + fail("Not expecting: " + b.locator); + } + } + + final int nflushed = flushedChunks.size(); + +// assertEquals("#of sinks", 2, nflushed); + + // partition0 + { + +// assertEquals("#of binding sets", partition0.size(), +// bundle0.bindingSets.length); + + TestQueryEngine.assertSameSolutionsAnyOrder( + expectedPartition0.toArray(new IBindingSet[0]), + new Dechunkerator<IBindingSet>(actualPartition0 + .iterator())); + + } + + // partition1 + { +// final Bundle bundle1 = flushedChunks.get(1); +// +// assertEquals("partitionId", 1/* partitionId */, +// bundle1.locator.getPartitionId()); + +// assertEquals("#of binding sets", partition1.size(), +// bundle1.bindingSets.length); + + TestQueryEngine.assertSameSolutionsAnyOrder( + expectedPartition1.toArray(new IBindingSet[0]), + new Dechunkerator<IBindingSet>(actualPartition1 + .iterator())); + } + + } + + } finally { + + fed.getTransactionService().abort(tx); + + } + + } + + /** * A unit test where no variables are bound. This should cause the binding * sets to be mapped across all shards. * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |