This commit is contained in:
Steve Faulkner 2018-08-27 23:04:47 -04:00 коммит произвёл GitHub
Родитель 461299e281
Коммит 28648b998f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
5 изменённых файлов: 1878 добавлений и 1936 удалений

3661
package-lock.json сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -70,8 +70,7 @@
"priorityqueuejs": "1.0.0",
"semaphore": "1.0.5",
"stream-http": "^2.8.3",
"tunnel": "0.0.5",
"underscore": "1.8.3"
"tunnel": "0.0.5"
},
"repository": {
"type": "git",

Просмотреть файл

@ -2,6 +2,18 @@ import * as _ from "underscore";
import { InMemoryCollectionRoutingMap } from ".";
import { Constants } from "../common";
function compareRanges(a: any, b: any) {
const aVal = a[0][Constants.PartitionKeyRange.MinInclusive];
const bVal = b[0][Constants.PartitionKeyRange.MinInclusive];
if (aVal > bVal) {
return 1;
}
if (aVal < bVal) {
return -1;
}
return 0;
}
/** @hidden */
export class CollectionRoutingMapFactory {
public static createCompleteRoutingMap(partitionKeyRangeInfoTuppleList: any[], collectionUniqueId: string) {
@ -17,9 +29,7 @@ export class CollectionRoutingMapFactory {
sortedRanges.push(r);
}
sortedRanges = _.sortBy(sortedRanges, r => {
return r[0][Constants.PartitionKeyRange.MinInclusive];
});
sortedRanges = sortedRanges.sort(compareRanges);
const partitionKeyOrderedRange = sortedRanges.map(r => r[0]);
const orderedPartitionInfo = sortedRanges.map(r => r[1]);

Просмотреть файл

@ -1,5 +1,4 @@
import * as assert from "assert";
import * as _ from "underscore";
import * as util from "util";
import { Constants } from "../..";
import { Container, ContainerDefinition } from "../../client";
@ -8,6 +7,18 @@ import { SqlQuerySpec } from "../../queryExecutionContext";
import { QueryIterator } from "../../queryIterator";
import { bulkInsertItems, getTestContainer, removeAllDatabases } from "../common/TestHelpers";
function compare(key: string) {
return function(a: any, b: any): number {
if (a[key] > b[key]) {
return 1;
}
if (a[key] < b[key]) {
return -1;
}
return 0;
};
}
describe("Cross Partition", function() {
this.timeout(process.env.MOCHA_TIMEOUT || "30000");
const generateDocuments = function(docSize: number) {
@ -313,10 +324,6 @@ describe("Cross Partition", function() {
maxDegreeOfParallelism: 0
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = [1, 10, 18, 2, 3, 13, 14, 16, 17, 0, 11, 12, 5, 9, 19, 4, 6, 7, 8, 15];
// validates the results size and order
@ -333,10 +340,6 @@ describe("Cross Partition", function() {
populateQueryMetrics: true
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = [1, 10, 18, 2, 3, 13, 14, 16, 17, 0, 11, 12, 5, 9, 19, 4, 6, 7, 8, 15];
// validates the results size and order
@ -352,10 +355,6 @@ describe("Cross Partition", function() {
maxDegreeOfParallelism: 1
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = [1, 10, 18, 2, 3, 13, 14, 16, 17, 0, 11, 12, 5, 9, 19, 4, 6, 7, 8, 15];
// validates the results size and order
@ -371,10 +370,6 @@ describe("Cross Partition", function() {
maxDegreeOfParallelism: 3
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = [1, 10, 18, 2, 3, 13, 14, 16, 17, 0, 11, 12, 5, 9, 19, 4, 6, 7, 8, 15];
// validates the results size and order
@ -476,11 +471,7 @@ describe("Cross Partition", function() {
maxDegreeOfParallelism: 0
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -497,11 +488,7 @@ describe("Cross Partition", function() {
maxDegreeOfParallelism: 1
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -518,11 +505,7 @@ describe("Cross Partition", function() {
maxDegreeOfParallelism: 3
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -539,11 +522,7 @@ describe("Cross Partition", function() {
maxDegreeOfParallelism: -1
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -559,11 +538,7 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -581,11 +556,7 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -603,11 +574,7 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -625,11 +592,8 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey)
const expectedOrderedIds = documentDefinitions
.sort(compare("spam"))
.map(function(r) {
return r["id"];
})
@ -650,11 +614,8 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey)
const expectedOrderedIds = documentDefinitions
.sort(compare("spam"))
.map(function(r) {
return r["id"];
})
@ -676,11 +637,7 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});
@ -816,11 +773,8 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey)
const expectedOrderedIds = documentDefinitions
.sort(compare("spam"))
.map(function(r) {
return r["id"];
})
@ -840,11 +794,8 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey)
const expectedOrderedIds = documentDefinitions
.sort(compare("spam"))
.filter(function(r) {
return r["cnt"] > 5;
})
@ -883,11 +834,7 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["cnt"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("cnt")).map(function(r) {
return r["id"];
});
@ -903,11 +850,7 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["number"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("number")).map(function(r) {
return r["id"];
});
@ -952,11 +895,7 @@ describe("Cross Partition", function() {
maxItemCount: 2
};
// prepare expected results
const getOrderByKey = function(r: any) {
return r["spam"];
};
const expectedOrderedIds = _.sortBy(documentDefinitions, getOrderByKey).map(function(r) {
const expectedOrderedIds = documentDefinitions.sort(compare("spam")).map(function(r) {
return r["id"];
});

Просмотреть файл

@ -1,5 +1,4 @@
import * as assert from "assert";
import * as _ from "underscore";
import { CollectionRoutingMapFactory, InMemoryCollectionRoutingMap, QueryRange } from "../../routing";
describe("InMemoryCollectionRoutingMap Tests", function() {
@ -137,19 +136,19 @@ describe("InMemoryCollectionRoutingMap Tests", function() {
it("validate getOverlappingRanges", function() {
const completeRange = new QueryRange("", "FF", true, false);
const getKey = function(r: any) {
const compareId = function(a: any, b: any) {
// TODO: any
return r["id"];
return a["id"] - b["id"];
};
const overlappingRanges = _.sortBy(collectionRoutingMap.getOverlappingRanges([completeRange]), getKey);
const overlappingRanges = collectionRoutingMap.getOverlappingRanges([completeRange]).sort(compareId);
assert.equal(4, overlappingRanges.length);
let onlyParitionRanges = partitionRangeWithInfo.map(function(item) {
return item[0];
});
onlyParitionRanges = _.sortBy(onlyParitionRanges, getKey);
onlyParitionRanges = onlyParitionRanges.sort(compareId);
assert.deepEqual(overlappingRanges, onlyParitionRanges);
const noPoint = new QueryRange("", "", false, false);
@ -165,7 +164,7 @@ describe("InMemoryCollectionRoutingMap Tests", function() {
new QueryRange("0000000045", "0000000046", true, true),
new QueryRange("0000000046", "0000000050", true, true)
];
overlappingPartitionKeyRanges = _.sortBy(collectionRoutingMap.getOverlappingRanges(ranges), getKey);
overlappingPartitionKeyRanges = collectionRoutingMap.getOverlappingRanges(ranges).sort(compareId);
assert.equal(2, overlappingPartitionKeyRanges.length);
assert.equal("1", overlappingPartitionKeyRanges[0].id);