~evarlast/ubuntu/utopic/mongodb/upstart-workaround-debian-bug-718702

« back to all changes in this revision

Viewing changes to jstests/aggregation/testshard1.js

  • Committer: Package Import Robot
  • Author(s): James Page, James Page, Robie Basak
  • Date: 2013-05-29 17:44:42 UTC
  • mfrom: (44.1.7 sid)
  • Revision ID: package-import@ubuntu.com-20130529174442-z0a4qmoww4y0t458
Tags: 1:2.4.3-1ubuntu1
[ James Page ]
* Merge from Debian unstable, remaining changes:
  - Enable SSL support:
    + d/control: Add libssl-dev to BD's.
    + d/rules: Enabled --ssl option.
    + d/mongodb.conf: Add example SSL configuration options.
  - d/mongodb-server.mongodb.upstart: Add upstart configuration.
  - d/rules: Don't strip binaries during scons build for Ubuntu.
  - d/control: Add armhf to target archs.
  - d/p/SConscript.client.patch: fixup install of client libraries.
  - d/p/0010-install-libs-to-usr-lib-not-usr-lib64-Closes-588557.patch:
    Install libraries to lib not lib64.
* Dropped changes:
  - d/p/arm-support.patch: Included in Debian.
  - d/p/double-alignment.patch: Included in Debian.
  - d/rules,control: Debian also builds with avaliable system libraries
    now.
* Fix FTBFS due to gcc and boost upgrades in saucy:
  - d/p/0008-ignore-unused-local-typedefs.patch: Add -Wno-unused-typedefs
    to unbreak building with g++-4.8.
  - d/p/0009-boost-1.53.patch: Fixup signed/unsigned casting issue.

[ Robie Basak ]
* d/p/0011-Use-a-signed-char-to-store-BSONType-enumerations.patch: Fixup
  build failure on ARM due to missing signed'ness of char cast.

Show diffs side-by-side

added added

removed removed

Lines of Context:
57
57
var nItems = 200000;
58
58
for(i = 1; i <= nItems; ++i) {
59
59
    db.ts1.save(
60
 
        {counter: ++count, number: strings[i % 20],
 
60
        {counter: ++count, number: strings[i % 20], random: Math.random(),
61
61
         filler: "0123456789012345678901234567890123456789"});
62
62
}
63
63
 
65
65
assert.eq(db.getLastError(), null);
66
66
 
67
67
// a project and group in shards, result combined in mongos
68
 
var a1 = db.runCommand({ aggregate:"ts1", pipeline:[
 
68
var a1 = db.ts1.aggregate(
69
69
    { $project: {
70
70
        cMod10: {$mod:["$counter", 10]},
71
71
        number: 1,
77
77
        avgCounter: {$avg: "$cMod10"}
78
78
    }},
79
79
    { $sort: {_id:1} }
80
 
]});
 
80
);
81
81
 
82
82
var a1result = a1.result;
83
83
for(i = 0 ; i < 10; ++i) {
88
88
}
89
89
 
90
90
// an initial group starts the group in the shards, and combines them in mongos
91
 
var a2 = db.runCommand({ aggregate:"ts1", pipeline:[
 
91
var a2 = db.ts1.aggregate(
92
92
    { $group: {
93
93
        _id: "all",
94
94
        total: {$sum: "$counter"}
95
95
    }}
96
 
]});
 
96
);
97
97
 
98
98
// sum of an arithmetic progression S(n) = (n/2)(a(1) + a(n));
99
99
assert.eq(a2.result[0].total, (nItems/2)*(1 + nItems),
100
100
       'agg sharded test counter sum failed');
101
101
 
102
102
// an initial group starts the group in the shards, and combines them in mongos
103
 
var a3 = db.runCommand({ aggregate:"ts1", pipeline:[
 
103
var a3 = db.ts1.aggregate(
104
104
    { $group: {
105
105
        _id: "$number",
106
106
        total: {$sum: 1}
107
107
    }},
108
108
    { $sort: {_id:1} }
109
 
]});
 
109
);
110
110
 
111
111
var a3result = a3.result;
112
112
for(i = 0 ; i < strings.length; ++i) {
115
115
}
116
116
 
117
117
// a match takes place in the shards; just returning the results from mongos
118
 
var a4 = db.runCommand({ aggregate:"ts1", pipeline:[
 
118
var a4 = db.ts1.aggregate(
119
119
    { $match: {$or:[{counter:55}, {counter:1111},
120
120
                    {counter: 2222}, {counter: 33333},
121
121
                    {counter: 99999}, {counter: 55555}]}
122
122
    }
123
 
]});
 
123
);
124
124
 
125
125
var a4result = a4.result;
126
126
for(i = 0; i < 6; ++i) {
139
139
 
140
140
    ops.push({$group: {_id:1, count: {$sum: 1}}});
141
141
 
142
 
    var out = db.runCommand({aggregate:"ts1", pipeline:ops});
 
142
    var out = db.ts1.aggregate(ops);
143
143
    assert.commandWorked(out);
144
144
    assert.eq(out.result[0].count, expectedCount);
145
145
}
153
153
testSkipLimit([{$skip:5}, {$limit:10}, {$skip: 3}], 10 - 3);
154
154
testSkipLimit([{$limit:10}, {$skip:5}, {$skip: 3}], 10 - 3 - 5);
155
155
 
 
156
// test sort + limit (using random to pull from both shards)
 
157
function testSortLimit(limit, direction) {
 
158
    var from_cursor = db.ts1.find({},{random:1, _id:0})
 
159
                            .sort({random: direction})
 
160
                            .limit(limit)
 
161
                            .toArray();
 
162
    var from_agg = db.ts1.aggregate({$project: {random:1, _id:0}}
 
163
                                   ,{$sort: {random: direction}}
 
164
                                   ,{$limit: limit}
 
165
                                   ).result;
 
166
    assert.eq(from_cursor, from_agg);
 
167
}
 
168
testSortLimit(1,  1);
 
169
testSortLimit(1, -1);
 
170
testSortLimit(10,  1);
 
171
testSortLimit(10, -1);
 
172
testSortLimit(100,  1);
 
173
testSortLimit(100, -1);
 
174
 
 
175
 
156
176
// shut everything down
157
177
shardedAggTest.stop();