2
* Copyright (C) 2012 10gen Inc.
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.
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.
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/>.
17
#include "mongo/bson/util/misc.h" // for Date_t
18
#include "mongo/s/type_mongos.h"
19
#include "mongo/unittest/unittest.h"
25
using mongo::MongosType;
28
TEST(Validity, MissingName) {
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));
47
TEST(Validity, MissingPing) {
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));
66
TEST(Validity, MissingUp) {
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));
85
TEST(Validity, MissingWaiting) {
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));
104
TEST(Validity, MissingMongoVersion) {
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));
125
TEST(Validity, MissingConfigVersion) {
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));
146
TEST(Validity, Valid) {
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));
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);
166
TEST(Validity, BadType) {
168
BSONObj obj = BSON(MongosType::name() << 0);
170
ASSERT((!mongos.parseBSON(obj, &errMsg)) && (errMsg != ""));
173
} // unnamed namespace