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

« back to all changes in this revision

Viewing changes to jstests/sharding/update1.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:
 
1
// Test simple updates issued through mongos. Updates have different constraints through mongos,
 
2
// since shard key is immutable.
 
3
 
1
4
s = new ShardingTest( "auto1" , 2 , 1 , 1 );
2
5
 
3
6
s.adminCommand( { enablesharding : "test" } );
4
 
s.adminCommand( { shardcollection : "test.update1" , key : { key : 1 } } );
 
7
// repeat same tests with hashed shard key, to ensure identical behavior
 
8
s.adminCommand( { shardcollection : "test.update0" , key : { key : 1 } } );
 
9
s.adminCommand( { shardcollection : "test.update1" , key : { key : "hashed" } } );
5
10
 
6
11
db = s.getDB( "test" )
7
 
coll = db.update1;
8
 
 
9
 
coll.insert({_id:1, key:1});
10
 
 
11
 
// these are both upserts
12
 
coll.save({_id:2, key:2});
13
 
coll.update({_id:3, key:3}, {$set: {foo: 'bar'}}, {upsert: true});
14
 
 
15
 
assert.eq(coll.count(), 3, "count A")
16
 
assert.eq(coll.findOne({_id:3}).key, 3 , "findOne 3 key A")
17
 
assert.eq(coll.findOne({_id:3}).foo, 'bar' , "findOne 3 foo A")
18
 
 
19
 
// update existing using save()
20
 
coll.save({_id:1, key:1, other:1});
21
 
 
22
 
// update existing using update()
23
 
coll.update({_id:2}, {key:2, other:2});
24
 
coll.update({_id:3}, {key:3, other:3});
25
 
 
26
 
coll.update({_id:3, key:3}, {other:4});
27
 
assert.eq(db.getLastErrorObj().code, 12376, 'bad update error');
28
 
 
29
 
assert.eq(coll.count(), 3, "count B")
30
 
coll.find().forEach(function(x){
31
 
    assert.eq(x._id, x.key, "_id == key");
32
 
    assert.eq(x._id, x.other, "_id == other");
33
 
});
34
 
 
35
 
 
36
 
coll.update({_id:1, key:1}, {$set: {key:2}});
37
 
err = db.getLastErrorObj();
38
 
assert.eq(coll.findOne({_id:1}).key, 1, 'key unchanged');
39
 
assert.eq(err.code, 13123, 'key error code 1');
40
 
assert.eq(err.code, 13123, 'key error code 2');
41
 
 
42
 
coll.update({_id:1, key:1}, {$set: {foo:2}});
43
 
assert.isnull(db.getLastError(), 'getLastError reset');
44
 
 
45
 
coll.update( { key : 17 } , { $inc : { x : 5 } } , true  );
46
 
assert.eq( 5 , coll.findOne( { key : 17 } ).x , "up1" )
47
 
 
48
 
coll.update( { key : 18 } , { $inc : { x : 5 } } , true , true );
49
 
assert.eq( 5 , coll.findOne( { key : 18 } ).x , "up2" )
50
 
 
 
12
for(i=0; i < 2; i++){
 
13
    coll = db.getCollection("update" + i);
 
14
 
 
15
    coll.insert({_id:1, key:1});
 
16
 
 
17
    // these are both upserts
 
18
    coll.save({_id:2, key:2});
 
19
    coll.update({_id:3, key:3}, {$set: {foo: 'bar'}}, {upsert: true});
 
20
 
 
21
    assert.eq(coll.count(), 3, "count A")
 
22
    assert.eq(coll.findOne({_id:3}).key, 3 , "findOne 3 key A")
 
23
    assert.eq(coll.findOne({_id:3}).foo, 'bar' , "findOne 3 foo A")
 
24
 
 
25
    // update existing using save()
 
26
    coll.save({_id:1, key:1, other:1});
 
27
 
 
28
    // update existing using update()
 
29
    coll.update({_id:2}, {key:2, other:2});
 
30
    coll.update({_id:3}, {key:3, other:3});
 
31
 
 
32
    // do a replacement-style update which queries the shard key and keeps it constant
 
33
    coll.save( {_id:4, key:4} );
 
34
    coll.update({key:4}, {key:4, other:4});
 
35
    assert.eq( coll.find({key:4, other:4}).count() , 1 , 'replacement update error');
 
36
    coll.remove( {_id:4} )
 
37
 
 
38
    assert.eq(coll.count(), 3, "count B")
 
39
    coll.find().forEach(function(x){
 
40
        assert.eq(x._id, x.key, "_id == key");
 
41
        assert.eq(x._id, x.other, "_id == other");
 
42
    });
 
43
 
 
44
 
 
45
    coll.update({_id:1, key:1}, {$set: {key:2}});
 
46
    err = db.getLastErrorObj();
 
47
    assert.eq(coll.findOne({_id:1}).key, 1, 'key unchanged');
 
48
    assert.eq(err.code, 13123, 'key error code 1');
 
49
    assert.eq(err.code, 13123, 'key error code 2');
 
50
 
 
51
    coll.update({_id:1, key:1}, {$set: {foo:2}});
 
52
    assert.isnull(db.getLastError(), 'getLastError reset');
 
53
 
 
54
    coll.update( { key : 17 } , { $inc : { x : 5 } } , true  );
 
55
    assert.eq( 5 , coll.findOne( { key : 17 } ).x , "up1" )
 
56
 
 
57
    coll.update( { key : 18 } , { $inc : { x : 5 } } , true , true );
 
58
    assert.eq( 5 , coll.findOne( { key : 18 } ).x , "up2" )
 
59
}
51
60
 
52
61
s.stop()
53
62