~ubuntu-branches/ubuntu/trusty/mongodb/trusty-proposed

« back to all changes in this revision

Viewing changes to dbtests/clienttests.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Antonin Kral
  • Date: 2010-01-29 19:48:45 UTC
  • Revision ID: james.westby@ubuntu.com-20100129194845-8wbmkf626fwcavc9
Tags: upstream-1.3.1
ImportĀ upstreamĀ versionĀ 1.3.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// client.cpp
 
2
 
 
3
#include "stdafx.h"
 
4
#include "../client/dbclient.h"
 
5
#include "dbtests.h"
 
6
#include "../db/concurrency.h"
 
7
 
 
8
namespace ClientTests {
 
9
    
 
10
    class Base {
 
11
    public:
 
12
        
 
13
        Base( string coll ){
 
14
            _ns = (string)"test." + coll;
 
15
        }
 
16
        
 
17
        virtual ~Base(){
 
18
            db.dropCollection( _ns );
 
19
        }
 
20
        
 
21
        const char * ns(){ return _ns.c_str(); }
 
22
        
 
23
        string _ns;
 
24
        DBDirectClient db;
 
25
    };
 
26
        
 
27
 
 
28
    class DropIndex : public Base {
 
29
    public:
 
30
        DropIndex() : Base( "dropindex" ){}
 
31
        void run(){
 
32
            db.insert( ns() , BSON( "x" << 2 ) );
 
33
            ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
 
34
            
 
35
            db.ensureIndex( ns() , BSON( "x" << 1 ) );
 
36
            ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
 
37
            
 
38
            db.dropIndex( ns() , BSON( "x" << 1 ) );
 
39
            ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
 
40
            
 
41
            db.ensureIndex( ns() , BSON( "x" << 1 ) );
 
42
            ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
 
43
 
 
44
            db.dropIndexes( ns() );
 
45
            ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
 
46
        }
 
47
    };
 
48
    
 
49
    class ReIndex : public Base {
 
50
    public:
 
51
        ReIndex() : Base( "reindex" ){}
 
52
        void run(){
 
53
            
 
54
            db.insert( ns() , BSON( "x" << 2 ) );
 
55
            ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
 
56
            
 
57
            db.ensureIndex( ns() , BSON( "x" << 1 ) );
 
58
            ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
 
59
            
 
60
            db.reIndex( ns() );
 
61
            ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
 
62
        }
 
63
 
 
64
    };
 
65
 
 
66
    class ReIndex2 : public Base {
 
67
    public:
 
68
        ReIndex2() : Base( "reindex2" ){}
 
69
        void run(){
 
70
            
 
71
            db.insert( ns() , BSON( "x" << 2 ) );
 
72
            ASSERT_EQUALS( 1 , db.getIndexes( ns() )->itcount() );
 
73
            
 
74
            db.ensureIndex( ns() , BSON( "x" << 1 ) );
 
75
            ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
 
76
            
 
77
            BSONObj out;
 
78
            ASSERT( db.runCommand( "test" , BSON( "reIndex" << "reindex2" ) , out ) );
 
79
            ASSERT_EQUALS( 2 , out["nIndexes"].number() );
 
80
            ASSERT_EQUALS( 2 , db.getIndexes( ns() )->itcount() );
 
81
        }
 
82
 
 
83
    };
 
84
 
 
85
 
 
86
    class All : public Suite {
 
87
    public:
 
88
        All() : Suite( "client" ){
 
89
        }
 
90
 
 
91
        void setupTests(){
 
92
            add<DropIndex>();
 
93
            add<ReIndex>();
 
94
            add<ReIndex2>();
 
95
        }
 
96
        
 
97
    } all;
 
98
}