summaryrefslogtreecommitdiff
path: root/jstests/ssl/sharding_with_x509.js
blob: 37741513dbf5b3137a9565e35c49d98fcc991836 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Tests basic sharding with x509 cluster auth 
// The purpose is to verify the connectivity between mongos and the shards

var x509_options = {sslMode : "sslOnly",
                    sslPEMKeyFile : "jstests/libs/server.pem",
                    sslCAFile: "jstests/libs/ca.pem",
                    sslClusterFile: "jstests/libs/cluster-cert.pem",
                    clusterAuthMode: "x509"};

var st = new ShardingTest({ name : "sharding_with_x509" ,
                            shards : 2,
                            mongos : 1,
                            keyFile : "jstests/libs/key1",
                            other: {
                                configOptions : x509_options,
                                mongosOptions : x509_options,
                                rsOptions : x509_options,
                                shardOptions : x509_options
                            }});

var mongos = new Mongo( "localhost:" + st.s0.port )
var coll = mongos.getCollection( "test.foo" )

st.shardColl( coll, { _id : 1 }, false )

// Create an index so we can find by num later
coll.ensureIndex({ insert : 1 })

print( "starting insertion phase" )

// Insert a bunch of data
var toInsert = 2000
for( var i = 0; i < toInsert; i++ ){
    coll.insert({ my : "test", data : "to", insert : i })
}

assert.eq( coll.getDB().getLastError(), null )

print( "starting updating phase" )

// Update a bunch of data
var toUpdate = toInsert
for( var i = 0; i < toUpdate; i++ ){
    var id = coll.findOne({ insert : i })._id
    coll.update({ insert : i, _id : id }, { $inc : { counter : 1 } })
}

assert.eq( coll.getDB().getLastError(), null )

print( "starting deletion" )

// Remove a bunch of data
var toDelete = toInsert / 2
for( var i = 0; i < toDelete; i++ ){
    coll.remove({ insert : i })
}

assert.eq( coll.getDB().getLastError(), null )

// Make sure the right amount of data is there
assert.eq( coll.find().count(), toInsert / 2 )

// Finish
st.stop()