1 | "use strict"
|
2 |
|
3 | var co = require('co'),
|
4 | f = require('util').format,
|
5 | Logger = require('../lib/logger'),
|
6 | assert = require('assert');
|
7 |
|
8 |
|
9 | if(!global.Promise) {
|
10 | require('es6-promise').polyfill();
|
11 | }
|
12 |
|
13 |
|
14 | require("babel-polyfill");
|
15 |
|
16 | describe('Sharded', function() {
|
17 | describe('manager', function() {
|
18 | it('establish server version for sharded system', function(done) {
|
19 | this.timeout(200000);
|
20 |
|
21 | co(function*() {
|
22 | var Sharded = require('../').Sharded;
|
23 |
|
24 | var topology = new Sharded('mongod');
|
25 |
|
26 | var version = yield topology.discover();
|
27 |
|
28 | assert.ok(typeof version.version[0] == 'number');
|
29 | assert.ok(typeof version.version[1] == 'number');
|
30 | assert.ok(typeof version.version[2] == 'number');
|
31 | done();
|
32 | }).catch(function(err) {
|
33 | console.log(err.stack);
|
34 | });
|
35 | });
|
36 |
|
37 | it('create a sharded system with 2 shards', function(done) {
|
38 | this.timeout(250000);
|
39 |
|
40 | co(function*() {
|
41 | var Sharded = require('../').Sharded;
|
42 |
|
43 | var topology = new Sharded({
|
44 | mongod: 'mongod',
|
45 | mongos: 'mongos'
|
46 | });
|
47 |
|
48 |
|
49 | yield topology.addShard([{
|
50 | options: {
|
51 | bind_ip: 'localhost', port: 31000, dbpath: f('%s/../db/31000', __dirname)
|
52 | }
|
53 | }, {
|
54 | options: {
|
55 | bind_ip: 'localhost', port: 31001, dbpath: f('%s/../db/31001', __dirname)
|
56 | }
|
57 | }, {
|
58 |
|
59 | arbiter: true,
|
60 |
|
61 | options: {
|
62 | bind_ip: 'localhost', port: 31002, dbpath: f('%s/../db/31002', __dirname)
|
63 | }
|
64 | }], {
|
65 | replSet: 'rs1'
|
66 | });
|
67 |
|
68 |
|
69 | yield topology.addShard([{
|
70 | options: {
|
71 | bind_ip: 'localhost', port: 31010, dbpath: f('%s/../db/31010', __dirname)
|
72 | }
|
73 | }, {
|
74 | options: {
|
75 | bind_ip: 'localhost', port: 31011, dbpath: f('%s/../db/31011', __dirname)
|
76 | }
|
77 | }, {
|
78 |
|
79 | arbiter: true,
|
80 |
|
81 | options: {
|
82 | bind_ip: 'localhost', port: 31012, dbpath: f('%s/../db/31012', __dirname)
|
83 | }
|
84 | }], {
|
85 | replSet: 'rs2'
|
86 | });
|
87 |
|
88 |
|
89 | yield topology.addConfigurationServers([{
|
90 | options: {
|
91 | bind_ip: 'localhost', port: 35000, dbpath: f('%s/../db/35000', __dirname)
|
92 | }
|
93 | }, {
|
94 | options: {
|
95 | bind_ip: 'localhost', port: 35001, dbpath: f('%s/../db/35001', __dirname)
|
96 | }
|
97 | }, {
|
98 | options: {
|
99 | bind_ip: 'localhost', port: 35002, dbpath: f('%s/../db/35002', __dirname)
|
100 | }
|
101 | }], {
|
102 | replSet: 'rs3'
|
103 | });
|
104 |
|
105 |
|
106 | yield topology.addProxies([{
|
107 | bind_ip: 'localhost', port: 51000, configdb: 'localhost:35000,localhost:35001,localhost:35002'
|
108 | }, {
|
109 | bind_ip: 'localhost', port: 51001, configdb: 'localhost:35000,localhost:35001,localhost:35002'
|
110 | }], {
|
111 | binary: 'mongos'
|
112 | });
|
113 |
|
114 |
|
115 |
|
116 |
|
117 |
|
118 | yield topology.start();
|
119 |
|
120 |
|
121 | yield topology.enableSharding('test');
|
122 |
|
123 | yield topology.shardCollection('test', 'testcollection', {_id: 1});
|
124 |
|
125 |
|
126 | yield topology.stop();
|
127 |
|
128 |
|
129 | done();
|
130 | }).catch(function(err) {
|
131 | console.log(err.stack);
|
132 | });
|
133 | });
|
134 |
|
135 | it('create a sharded system with a single shard and take down mongos and bring it back', function(done) {
|
136 | this.timeout(250000);
|
137 |
|
138 | co(function*() {
|
139 | var Sharded = require('../').Sharded;
|
140 |
|
141 | var topology = new Sharded({
|
142 | mongod: 'mongod',
|
143 | mongos: 'mongos'
|
144 | });
|
145 |
|
146 |
|
147 | yield topology.addShard([{
|
148 | options: {
|
149 | bind_ip: 'localhost', port: 31000, dbpath: f('%s/../db/31000', __dirname)
|
150 | }
|
151 | }, {
|
152 | options: {
|
153 | bind_ip: 'localhost', port: 31001, dbpath: f('%s/../db/31001', __dirname)
|
154 | }
|
155 | }, {
|
156 |
|
157 | arbiter: true,
|
158 |
|
159 | options: {
|
160 | bind_ip: 'localhost', port: 31002, dbpath: f('%s/../db/31002', __dirname)
|
161 | }
|
162 | }], {
|
163 | replSet: 'rs1'
|
164 | });
|
165 |
|
166 |
|
167 | yield topology.addConfigurationServers([{
|
168 | options: {
|
169 | bind_ip: 'localhost', port: 35000, dbpath: f('%s/../db/35000', __dirname)
|
170 | }
|
171 | }, {
|
172 | options: {
|
173 | bind_ip: 'localhost', port: 35001, dbpath: f('%s/../db/35001', __dirname)
|
174 | }
|
175 | }, {
|
176 | options: {
|
177 | bind_ip: 'localhost', port: 35002, dbpath: f('%s/../db/35002', __dirname)
|
178 | }
|
179 | }], {
|
180 | replSet: 'rs3'
|
181 | });
|
182 |
|
183 |
|
184 | yield topology.addProxies([{
|
185 | bind_ip: 'localhost', port: 51000, configdb: 'localhost:35000,localhost:35001,localhost:35002'
|
186 | }, {
|
187 | bind_ip: 'localhost', port: 51001, configdb: 'localhost:35000,localhost:35001,localhost:35002'
|
188 | }], {
|
189 | binary: 'mongos'
|
190 | });
|
191 |
|
192 |
|
193 |
|
194 |
|
195 |
|
196 | yield topology.start();
|
197 |
|
198 |
|
199 | yield topology.enableSharding('test');
|
200 |
|
201 |
|
202 | yield topology.shardCollection('test', 'testcollection', {_id: 1});
|
203 |
|
204 |
|
205 | var mongos = topology.proxies[0];
|
206 |
|
207 | yield mongos.stop();
|
208 |
|
209 |
|
210 | yield mongos.start();
|
211 |
|
212 |
|
213 | yield topology.stop();
|
214 |
|
215 |
|
216 | done();
|
217 | }).catch(function(err) {
|
218 | console.log(err.stack);
|
219 | });
|
220 | });
|
221 | });
|
222 | });
|