-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_all.js
180 lines (154 loc) · 4.51 KB
/
test_all.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/**
* Created by gags on 11/14/15.
*/
var constants = require('./constants'),
KeyProvider = require('./keyProvider');
var logEnabled = false;
var argv = require('optimist')
.usage('Usage: $0 -k [KEY_RANGE]')
.demand(['d', 'k', 'i'])
.alias('d', 'dbName')
.describe('d', 'NoSQL DB Name')
.alias('h', 'host')
.describe('h', 'Host IP Address')
.alias('k', 'keyRange')
.describe('k', 'Key Range')
.alias('i', 'iterations')
.describe('i', 'Iterations')
.argv;
var iteration = 0,
maxIteration = argv.iterations;
var totalLatency = 0,
latency = 0,
startTime = Date.now();
// NOTE: Prepare Keys
KeyProvider.init(argv.keyRange, argv.iterations);
switch (argv.dbName) {
case 'mongo':
Store = require('./mongoDB');
break;
case 'redis':
Store = require('./redisDB');
break;
case 'dynamo':
Store = require('./dynamoDB');
break;
default:
console.log("Unable Initialize DB...");
process.exit();
}
// NOTE: Initialize Test
Store.init(argv.host).then(function (status) {
if (status) {
doTest(constants.TEST_PUT);
} else {
console.log("ERROR INITIALIZING DB !");
process.exit();
}
}, function (err) {
console.log(err);
process.exit();
});
function doTest(operation) {
switch (operation) {
case constants.TEST_PUT:
testPut();
break;
case constants.TEST_GET:
testGet();
break;
case constants.TEST_DELETE:
testDelete();
break;
default:
logMessage("ERROR PERFORMING TEST: SOMETHING WENT TERRIBLY WRONG !");
}
}
function testPut(value) {
if (value) {
latency = Date.now() - startTime;
logMessage(latency);
totalLatency += latency;
} else
startTime = Date.now();
if (iteration < maxIteration) {
performOperation(constants.TEST_PUT, KeyProvider.getKey(iteration), KeyProvider.getValue(iteration), testPut);
iteration++;
} else {
console.log("Total Put Latency / Lookup (ms) : ", totalLatency / maxIteration);
Store.getSize().then(function (size) {
console.log("Size after Put : ", size);
iteration = 0;
totalLatency = 0;
latency = 0;
doTest(constants.TEST_GET);
});
}
}
function testGet(value) {
if (value) {
latency = Date.now() - startTime;
logMessage(latency);
totalLatency += latency;
} else
startTime = Date.now();
if (iteration < maxIteration) {
performOperation(constants.TEST_GET, KeyProvider.getKey(iteration), KeyProvider.getValue(iteration), testGet);
iteration++;
} else {
console.log("Total Get Latency / Lookup (ms) : ", totalLatency / maxIteration);
Store.getSize().then(function (size) {
console.log("Size after Get : ", size);
iteration = 0;
totalLatency = 0;
latency = 0;
doTest(constants.TEST_DELETE);
});
}
}
function testDelete(value) {
if (value) {
latency = Date.now() - startTime;
logMessage(latency);
totalLatency += latency;
} else
startTime = Date.now();
if (iteration < maxIteration) {
performOperation(constants.TEST_DELETE, KeyProvider.getKey(iteration), KeyProvider.getValue(iteration), testDelete);
iteration++;
} else {
console.log("Total Delete Latency / Lookup (ms) : ", totalLatency / maxIteration);
Store.getSize().then(function (size) {
console.log("Size after Delete: ", size);
// NOTE: teardown
Store.tearDown();
process.exit();
});
iteration = 0;
totalLatency = 0;
latency = 0;
}
}
// NOTE: perform specific operation based on 'operation' using the 'key' and 'value'
function performOperation(operation, key, value, callback) {
startTime = Date.now();
switch (operation) {
case constants.TEST_PUT:
Store.putValue(key, value).then(callback);
break;
case constants.TEST_GET:
Store.getValue(key).then(callback);
break;
case constants.TEST_DELETE:
Store.deleteKey(key).then(callback);
break;
default:
callback(null);
logMessage("ERROR: SOMETHING WENT TERRIBLY WRONG !");
}
}
// NOTE: log client message
function logMessage(message) {
if (logEnabled)
console.log("[Client] : ", message);
}