forked from yfinkelstein/node-zookeeper
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexists.js
45 lines (33 loc) · 1.5 KB
/
exists.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
const { constants } = require('./wrapper');
const { createNodes } = require('./setup');
const logger = require('./logger');
async function verifyResultCodeCheckInAsyncCall(client) {
const tempNode = `/my-temporary-node-to-verify-async-call-${Date.now()}`;
const data = 'HELLOWORLD';
const version = 0;
createNodes(client, [tempNode], constants.ZOO_EPHEMERAL);
const res = await client.set(tempNode, data, version);
logger.log(`The client.set result: ${JSON.stringify(res)}`);
client.set('this-node-does-not-exist', data, version)
.then(() => logger.error('THIS WILL NOT HAPPEN.'))
.catch((error) => logger.log(`The error is: ${error}`));
}
async function verifyNonExisting(client) {
const tempNode = `/my-temporary-node-${Date.now()}`;
const doesExist = await client.w_pathExists(tempNode, (data) => logger.log(`Node created with data: ${data}`));
logger.log(`Does ${tempNode} exist? ${doesExist}`);
setTimeout(async () => {
createNodes(client, [tempNode], constants.ZOO_EPHEMERAL);
const exists = await client.pathExists(tempNode, false);
logger.log(`Does ${tempNode} exist now? ${exists}`);
}, 3000);
}
async function verifyTheNodeExistsFeature(client) {
const doesStatusExist = await client.pathExists('/status', false);
logger.log(`Does the /status node exist? ${doesStatusExist}`);
await verifyNonExisting(client);
await verifyResultCodeCheckInAsyncCall(client);
}
module.exports = {
verifyTheNodeExistsFeature,
};