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

« back to all changes in this revision

Viewing changes to src/mongo/s/type_mongos_test.cpp

  • 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
/**
 
2
 *    Copyright (C) 2012 10gen Inc.
 
3
 *
 
4
 *    This program is free software: you can redistribute it and/or  modify
 
5
 *    it under the terms of the GNU Affero General Public License, version 3,
 
6
 *    as published by the Free Software Foundation.
 
7
 *
 
8
 *    This program is distributed in the hope that it will be useful,
 
9
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 *    GNU Affero General Public License for more details.
 
12
 *
 
13
 *    You should have received a copy of the GNU Affero General Public License
 
14
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#include "mongo/bson/util/misc.h" // for Date_t
 
18
#include "mongo/s/type_mongos.h"
 
19
#include "mongo/unittest/unittest.h"
 
20
 
 
21
namespace {
 
22
 
 
23
    using std::string;
 
24
    using mongo::BSONObj;
 
25
    using mongo::MongosType;
 
26
    using mongo::Date_t;
 
27
 
 
28
    TEST(Validity, MissingName) {
 
29
        MongosType mongos;
 
30
        string errMsg;
 
31
        BSONObj obj = BSON(MongosType::ping(1ULL) <<
 
32
                           MongosType::up(100) <<
 
33
                           MongosType::waiting(false) <<
 
34
                           MongosType::mongoVersion("x.x.x") <<
 
35
                           MongosType::configVersion(0));
 
36
        ASSERT(mongos.parseBSON(obj, &errMsg));
 
37
        ASSERT_EQUALS(errMsg, "");
 
38
        ASSERT_FALSE(mongos.isNameSet());
 
39
        ASSERT_TRUE(mongos.isPingSet());
 
40
        ASSERT_TRUE(mongos.isUpSet());
 
41
        ASSERT_TRUE(mongos.isWaitingSet());
 
42
        ASSERT_TRUE(mongos.isMongoVersionSet());
 
43
        ASSERT_TRUE(mongos.isConfigVersionSet());
 
44
        ASSERT_FALSE(mongos.isValid(NULL));
 
45
    }
 
46
 
 
47
    TEST(Validity, MissingPing) {
 
48
        MongosType mongos;
 
49
        string errMsg;
 
50
        BSONObj obj = BSON(MongosType::name("localhost:27017") <<
 
51
                           MongosType::up(100) <<
 
52
                           MongosType::waiting(false) <<
 
53
                           MongosType::mongoVersion("x.x.x") <<
 
54
                           MongosType::configVersion(0));
 
55
        ASSERT(mongos.parseBSON(obj, &errMsg));
 
56
        ASSERT_EQUALS(errMsg, "");
 
57
        ASSERT_TRUE(mongos.isNameSet());
 
58
        ASSERT_FALSE(mongos.isPingSet());
 
59
        ASSERT_TRUE(mongos.isUpSet());
 
60
        ASSERT_TRUE(mongos.isWaitingSet());
 
61
        ASSERT_TRUE(mongos.isMongoVersionSet());
 
62
        ASSERT_TRUE(mongos.isConfigVersionSet());
 
63
        ASSERT_FALSE(mongos.isValid(NULL));
 
64
    }
 
65
 
 
66
    TEST(Validity, MissingUp) {
 
67
        MongosType mongos;
 
68
        string errMsg;
 
69
        BSONObj obj = BSON(MongosType::name("localhost:27017") <<
 
70
                           MongosType::ping(1ULL) <<
 
71
                           MongosType::waiting(false) <<
 
72
                           MongosType::mongoVersion("x.x.x") <<
 
73
                           MongosType::configVersion(0));
 
74
        ASSERT(mongos.parseBSON(obj, &errMsg));
 
75
        ASSERT_EQUALS(errMsg, "");
 
76
        ASSERT_TRUE(mongos.isNameSet());
 
77
        ASSERT_TRUE(mongos.isPingSet());
 
78
        ASSERT_FALSE(mongos.isUpSet());
 
79
        ASSERT_TRUE(mongos.isWaitingSet());
 
80
        ASSERT_TRUE(mongos.isMongoVersionSet());
 
81
        ASSERT_TRUE(mongos.isConfigVersionSet());
 
82
        ASSERT_FALSE(mongos.isValid(NULL));
 
83
    }
 
84
 
 
85
    TEST(Validity, MissingWaiting) {
 
86
        MongosType mongos;
 
87
        string errMsg;
 
88
        BSONObj obj = BSON(MongosType::name("localhost:27017") <<
 
89
                           MongosType::ping(1ULL) <<
 
90
                           MongosType::up(100) <<
 
91
                           MongosType::mongoVersion("x.x.x") <<
 
92
                           MongosType::configVersion(0));
 
93
        ASSERT(mongos.parseBSON(obj, &errMsg));
 
94
        ASSERT_EQUALS(errMsg, "");
 
95
        ASSERT_TRUE(mongos.isNameSet());
 
96
        ASSERT_TRUE(mongos.isPingSet());
 
97
        ASSERT_TRUE(mongos.isUpSet());
 
98
        ASSERT_FALSE(mongos.isWaitingSet());
 
99
        ASSERT_TRUE(mongos.isMongoVersionSet());
 
100
        ASSERT_TRUE(mongos.isConfigVersionSet());
 
101
        ASSERT_FALSE(mongos.isValid(NULL));
 
102
    }
 
103
 
 
104
    TEST(Validity, MissingMongoVersion) {
 
105
        MongosType mongos;
 
106
        string errMsg;
 
107
        BSONObj obj = BSON(MongosType::name("localhost:27017") <<
 
108
                           MongosType::ping(1ULL) <<
 
109
                           MongosType::up(100) <<
 
110
                           MongosType::waiting(false) <<
 
111
                           MongosType::configVersion(0));
 
112
        ASSERT(mongos.parseBSON(obj, &errMsg));
 
113
        ASSERT_EQUALS(errMsg, "");
 
114
        ASSERT_TRUE(mongos.isNameSet());
 
115
        ASSERT_TRUE(mongos.isPingSet());
 
116
        ASSERT_TRUE(mongos.isUpSet());
 
117
        ASSERT_TRUE(mongos.isWaitingSet());
 
118
        ASSERT_FALSE(mongos.isMongoVersionSet());
 
119
        ASSERT_TRUE(mongos.isConfigVersionSet());
 
120
        /* NOTE: mongoVersion should eventually become mandatory, but is optional now for backward
 
121
         * compatibility reasons */
 
122
        ASSERT_TRUE(mongos.isValid(NULL));
 
123
    }
 
124
 
 
125
    TEST(Validity, MissingConfigVersion) {
 
126
        MongosType mongos;
 
127
        string errMsg;
 
128
        BSONObj obj = BSON(MongosType::name("localhost:27017") <<
 
129
                           MongosType::ping(1ULL) <<
 
130
                           MongosType::up(100) <<
 
131
                           MongosType::waiting(false) <<
 
132
                           MongosType::mongoVersion("x.x.x"));
 
133
        ASSERT(mongos.parseBSON(obj, &errMsg));
 
134
        ASSERT_EQUALS(errMsg, "");
 
135
        ASSERT_TRUE(mongos.isNameSet());
 
136
        ASSERT_TRUE(mongos.isPingSet());
 
137
        ASSERT_TRUE(mongos.isUpSet());
 
138
        ASSERT_TRUE(mongos.isWaitingSet());
 
139
        ASSERT_TRUE(mongos.isMongoVersionSet());
 
140
        ASSERT_FALSE(mongos.isConfigVersionSet());
 
141
        /* NOTE: configVersion should eventually become mandatory, but is optional now for backward
 
142
         * compatibility reasons */
 
143
        ASSERT_TRUE(mongos.isValid(NULL));
 
144
    }
 
145
 
 
146
    TEST(Validity, Valid) {
 
147
        MongosType mongos;
 
148
        BSONObj obj = BSON(MongosType::name("localhost:27017") <<
 
149
                           MongosType::ping(1ULL) <<
 
150
                           MongosType::up(100) <<
 
151
                           MongosType::waiting(false) <<
 
152
                           MongosType::mongoVersion("x.x.x") <<
 
153
                           MongosType::configVersion(0));
 
154
        string errMsg;
 
155
        ASSERT(mongos.parseBSON(obj, &errMsg));
 
156
        ASSERT_EQUALS(errMsg, "");
 
157
        ASSERT_TRUE(mongos.isValid(NULL));
 
158
        ASSERT_EQUALS(mongos.getName(), "localhost:27017");
 
159
        ASSERT_EQUALS(mongos.getPing(), 1ULL);
 
160
        ASSERT_EQUALS(mongos.getUp(), 100);
 
161
        ASSERT_EQUALS(mongos.getWaiting(), false);
 
162
        ASSERT_EQUALS(mongos.getMongoVersion(), "x.x.x");
 
163
        ASSERT_EQUALS(mongos.getConfigVersion(), 0);
 
164
    }
 
165
 
 
166
    TEST(Validity, BadType) {
 
167
        MongosType mongos;
 
168
        BSONObj obj = BSON(MongosType::name() << 0);
 
169
        string errMsg;
 
170
        ASSERT((!mongos.parseBSON(obj, &errMsg)) && (errMsg != ""));
 
171
    }
 
172
 
 
173
} // unnamed namespace