-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpool_cluster.js
60 lines (54 loc) · 1.81 KB
/
pool_cluster.js
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
var _ = require('underscore');
var configuration = require('../configuration');
var mysql = require('mysql');
var connection = mysql.createConnection({
host: configuration.database.host,
user: configuration.database.user,
password: configuration.database.password,
database: configuration.database.name
});
var poolCluster = mysql.createPoolCluster({
canRetry: true,
removeNodeErrorCount: 1,
restoreNodeTimeout: 20000,
defaultSelector: 'RR'
});
poolCluster.add('MASTER', {
connectionLimit: 200,
host: configuration.database.host,
port: 3306,
user: configuration.database.user,
password: configuration.database.password,
database: configuration.database.name
});
var createNodeMySQL = require('../mysql-wrap');
exports.setUp = function (done) {
this.sql = createNodeMySQL(poolCluster, {
replication: {
write: 'MASTER',
read: '*'
}
});
poolCluster.getConnection('*', function (err, connection) {
connection.query('TRUNCATE TABLE `table`', function (err, res) {
connection.query(
'INSERT INTO `table` (`unique`, `field`) ' +
'VALUES ("a", "foo"), ("b", "bar"), ("c", "foo")',
function (err, res) {
connection.query('TRUNCATE TABLE `table2`', function (err, res) {
connection.query(
'INSERT INTO `table2` (`field`) ' +
'VALUES ("bar")',
function () {
done();
}
);
});
}
);
});
});
};
_.each(require('./shared_tests.js')(connection, createNodeMySQL), function (test, name) {
exports[name] = test;
});