浏览代码

EAGLESIX-3087: Shard test cases now working

Jason Walton 11 年之前
父节点
当前提交
41143b8619
共有 2 个文件被更改,包括 16 次插入13 次删除
  1. 11 7
      lib/pipeline/Pipeline.js
  2. 5 6
      test/lib/pipeline/Pipeline.js

+ 11 - 7
lib/pipeline/Pipeline.js

@@ -203,16 +203,18 @@ klass.optimizations.sharded.findSplitPoint = function findSplitPoint(shardPipe,
 		var current = mergePipe.sources[0];
 		mergePipe.sources.splice(0, 1);
 
-		if (typeof current.isSplittable != "undefined") {
-			shardPipe.sources.push(current);
-		}
-		else {
+		if (current.isSplittable && current.isSplittable()) {
 			var shardSource = current.getShardSource(),
 				mergeSource = current.getMergeSource();
 			if (typeof shardSource != "undefined") { shardPipe.sources.push(shardSource); }		//push_back
 			if (typeof mergeSource != "undefined") { mergePipe.sources.unshift(mergeSource); }	//push_front
 			break;
 		}
+		else {
+			debugger
+			if (!shardPipe.sources) { shardPipe.sources = []; }
+			shardPipe.sources.push(current);
+		}
 	}
 };
 
@@ -395,9 +397,11 @@ proto.serialize = function serialize() {
 		array = [];
 
 	// create an array out of the pipeline operations
-	for (var source in this.sources) {
-	//this.sources.forEach(function(source) {
-		source.serializeToArray(array);
+	if (this.sources) {
+		for (var i = 0; i < this.sources.length; i++) {
+		//this.sources.forEach(function(source) {
+			this.sources[i].serializeToArray(array);
+		}
 	}
 
 	serialized[klass.COMMAND_NAME] = this.ctx && this.ctx.ns && this.ctx.ns.coll ? this.ctx.ns.coll : '';

+ 5 - 6
test/lib/pipeline/Pipeline.js

@@ -150,7 +150,6 @@ module.exports = {
 		"sharded": {
 
 			"should handle empty pipeline for sharded": function () {
-				debugger
 				var inputPipe = "[]",
 					expectedMergePipe = "[]",
 					expectedShardPipe = "[]";
@@ -158,16 +157,16 @@ module.exports = {
 			},
 
 			"should handle one unwind": function () {
-				var inputPipe = [{"$unwind":"$a"}],
-					expectedMergePipe = '[]',
+				var inputPipe = '[{"$unwind":"$a"}]',
+					expectedMergePipe = "[]",
 					expectedShardPipe = '[{"$unwind":"$a"}]';
-				shardedTest(inputPipe,  expectedMergePipe, expectedShardPipe);
+				shardedTest(inputPipe, expectedMergePipe, expectedShardPipe);
 			},
 
 			"should handle two unwinds": function () {
-				var inputPipe = "[{$unwind: '$a'}, {$unwind: '$b'}]}",
+				var inputPipe = '[{"$unwind":"$a"}, {"$unwind":"$b"}]',
 					expectedMergePipe = "[]",
-					expectedShardPipe = "[{$unwind: '$a'}, {$unwind: '$b'}]}";
+					expectedShardPipe = '[{"$unwind": "$a"}, {"$unwind": "$b"}]';
 				shardedTest(inputPipe, expectedMergePipe, expectedShardPipe);
 
 			}