@itentialopensource/adapter-kafkav2 0.3.12
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintignore +6 -0
- package/.eslintrc.js +18 -0
- package/.gitlab/.gitkeep +0 -0
- package/.gitlab/issue_templates/.gitkeep +0 -0
- package/.gitlab/issue_templates/Default.md +17 -0
- package/.gitlab/issue_templates/bugReportTemplate.md +76 -0
- package/.gitlab/issue_templates/featureRequestTemplate.md +14 -0
- package/.jshintrc +0 -0
- package/CHANGELOG.md +152 -0
- package/CODE_OF_CONDUCT.md +48 -0
- package/CONTRIBUTING.md +158 -0
- package/LICENSE +201 -0
- package/README.md +380 -0
- package/Release_Notes.md +0 -0
- package/adapter.js +814 -0
- package/error.json +178 -0
- package/package.json +71 -0
- package/pronghorn.json +44 -0
- package/propertiesSchema.json +198 -0
- package/refs?service=git-upload-pack +0 -0
- package/sampleProperties.json +41 -0
- package/test/integration/adapterTestIntegration.js +445 -0
- package/test/unit/adapterTestUnit.js +412 -0
- package/utils/artifactize.js +146 -0
- package/utils/packModificationScript.js +35 -0
- package/utils/pre-commit.sh +27 -0
- package/utils/setup.js +33 -0
- package/utils/testRunner.js +298 -0
- package/workflows/kafka_test.json +1 -0
|
@@ -0,0 +1,445 @@
|
|
|
1
|
+
/* @copyright Itential, LLC 2019 (pre-modifications) */
|
|
2
|
+
|
|
3
|
+
// Set globals
|
|
4
|
+
/* global describe it log pronghornProps */
|
|
5
|
+
/* eslint no-unused-vars: warn */
|
|
6
|
+
/* eslint no-underscore-dangle: warn */
|
|
7
|
+
|
|
8
|
+
// include required items for testing & logging
|
|
9
|
+
const assert = require('assert');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const mocha = require('mocha');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
const winston = require('winston');
|
|
14
|
+
const { expect } = require('chai');
|
|
15
|
+
const { use } = require('chai');
|
|
16
|
+
const td = require('testdouble');
|
|
17
|
+
|
|
18
|
+
const anything = td.matchers.anything();
|
|
19
|
+
|
|
20
|
+
// stub and attemptTimeout are used throughout the code so set them here
|
|
21
|
+
let logLevel = 'none';
|
|
22
|
+
const stub = true;
|
|
23
|
+
const isRapidFail = false;
|
|
24
|
+
const isSaveMockData = false;
|
|
25
|
+
const attemptTimeout = 10000;
|
|
26
|
+
|
|
27
|
+
// these variables can be changed to run in integrated mode so easier to set them here
|
|
28
|
+
// always check these in with bogus data!!!
|
|
29
|
+
const host = 'localhost';
|
|
30
|
+
const username = 'username';
|
|
31
|
+
const password = 'password';
|
|
32
|
+
const protocol = 'mongodb';
|
|
33
|
+
const port = 9092;
|
|
34
|
+
const sslenable = false;
|
|
35
|
+
const sslinvalid = false;
|
|
36
|
+
|
|
37
|
+
const randExt = `${Math.random()}`;
|
|
38
|
+
|
|
39
|
+
// these are the adapter properties. You generally should not need to alter
|
|
40
|
+
// any of these after they are initially set up
|
|
41
|
+
global.pronghornProps = {
|
|
42
|
+
pathProps: {
|
|
43
|
+
encrypted: false
|
|
44
|
+
},
|
|
45
|
+
adapterProps: {
|
|
46
|
+
adapters: [{
|
|
47
|
+
id: 'Test-kafka',
|
|
48
|
+
type: 'Kafa',
|
|
49
|
+
interval_time: 5000,
|
|
50
|
+
stub: true,
|
|
51
|
+
properties: {
|
|
52
|
+
host: 'localhost',
|
|
53
|
+
port: 9092
|
|
54
|
+
}
|
|
55
|
+
}]
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
global.$HOME = `${__dirname}/../..`;
|
|
60
|
+
|
|
61
|
+
// set the log levels that Pronghorn uses, spam and trace are not defaulted in so without
|
|
62
|
+
// this you may error on log.trace calls.
|
|
63
|
+
const myCustomLevels = {
|
|
64
|
+
levels: {
|
|
65
|
+
spam: 6,
|
|
66
|
+
trace: 5,
|
|
67
|
+
debug: 4,
|
|
68
|
+
info: 3,
|
|
69
|
+
warn: 2,
|
|
70
|
+
error: 1,
|
|
71
|
+
none: 0
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
// need to see if there is a log level passed in
|
|
76
|
+
process.argv.forEach((val) => {
|
|
77
|
+
// is there a log level defined to be passed in?
|
|
78
|
+
if (val.indexOf('--LOG') === 0) {
|
|
79
|
+
// get the desired log level
|
|
80
|
+
const inputVal = val.split('=')[1];
|
|
81
|
+
|
|
82
|
+
// validate the log level is supported, if so set it
|
|
83
|
+
if (Object.hasOwnProperty.call(myCustomLevels.levels, inputVal)) {
|
|
84
|
+
logLevel = inputVal;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
// need to set global logging
|
|
90
|
+
global.log = winston.createLogger({
|
|
91
|
+
level: logLevel,
|
|
92
|
+
levels: myCustomLevels.levels,
|
|
93
|
+
transports: [
|
|
94
|
+
new winston.transports.Console()
|
|
95
|
+
]
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
/**
|
|
99
|
+
* Runs the common asserts for test
|
|
100
|
+
*/
|
|
101
|
+
function runCommonAsserts(data, error) {
|
|
102
|
+
assert.equal(undefined, error);
|
|
103
|
+
assert.notEqual(undefined, data);
|
|
104
|
+
assert.notEqual(null, data);
|
|
105
|
+
assert.notEqual(undefined, data.response);
|
|
106
|
+
assert.notEqual(null, data.response);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// require the adapter that we are going to be using
|
|
110
|
+
const Kafka = require('../../adapter');
|
|
111
|
+
|
|
112
|
+
// begin the testing - these should be pretty well defined between the describe and the it!
|
|
113
|
+
describe('[integration] Kafka Adapter Test', () => {
|
|
114
|
+
describe('Kafka Class Tests', () => {
|
|
115
|
+
const a = new Kafka(
|
|
116
|
+
pronghornProps.adapterProps.adapters[0].id,
|
|
117
|
+
pronghornProps.adapterProps.adapters[0].properties
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
if (isRapidFail) {
|
|
121
|
+
const state = {};
|
|
122
|
+
state.passed = true;
|
|
123
|
+
|
|
124
|
+
mocha.afterEach(function x() {
|
|
125
|
+
state.passed = state.passed
|
|
126
|
+
&& (this.currentTest.state === 'passed');
|
|
127
|
+
});
|
|
128
|
+
mocha.beforeEach(function x() {
|
|
129
|
+
if (!state.passed) {
|
|
130
|
+
return this.currentTest.skip();
|
|
131
|
+
}
|
|
132
|
+
return true;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
describe('#class instance created', () => {
|
|
137
|
+
it('should be a class with properties', (done) => {
|
|
138
|
+
assert.notEqual(null, a);
|
|
139
|
+
assert.notEqual(undefined, a);
|
|
140
|
+
const check = global.pronghornProps.adapterProps.adapters[0].id;
|
|
141
|
+
assert.equal(check, a.id);
|
|
142
|
+
done();
|
|
143
|
+
}).timeout(attemptTimeout);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe('#connect', () => {
|
|
147
|
+
if (!stub) {
|
|
148
|
+
it('should get connected', (done) => {
|
|
149
|
+
a.connect();
|
|
150
|
+
assert.equal(true, a.alive);
|
|
151
|
+
done();
|
|
152
|
+
}).timeout(attemptTimeout);
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
/*
|
|
157
|
+
-----------------------------------------------------------------------
|
|
158
|
+
-----------------------------------------------------------------------
|
|
159
|
+
*** All code above this comment will be replaced during a migration ***
|
|
160
|
+
******************* DO NOT REMOVE THIS COMMENT BLOCK ******************
|
|
161
|
+
-----------------------------------------------------------------------
|
|
162
|
+
-----------------------------------------------------------------------
|
|
163
|
+
*/
|
|
164
|
+
const topics = [{
|
|
165
|
+
topic: `test${randExt}`,
|
|
166
|
+
partitions: 1,
|
|
167
|
+
replicationFactor: 1
|
|
168
|
+
}];
|
|
169
|
+
describe('#createTopics', () => {
|
|
170
|
+
if (!stub) {
|
|
171
|
+
it('should create topics', (done) => {
|
|
172
|
+
try {
|
|
173
|
+
a.createTopics(topics, (data, error) => {
|
|
174
|
+
try {
|
|
175
|
+
runCommonAsserts(data, error);
|
|
176
|
+
assert.equal(200, data.code);
|
|
177
|
+
done();
|
|
178
|
+
} catch (ex) {
|
|
179
|
+
log.error(`Test Failure: ${ex}`);
|
|
180
|
+
done(ex);
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
} catch (exc) {
|
|
184
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
185
|
+
done(exc);
|
|
186
|
+
}
|
|
187
|
+
}).timeout(attemptTimeout);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
const payloads = [
|
|
192
|
+
{ topic: topics[0].topic, messages: `hello world${randExt}`, partitions: 1 }
|
|
193
|
+
];
|
|
194
|
+
describe('#sendMessage', () => {
|
|
195
|
+
if (!stub) {
|
|
196
|
+
it('should send message', (done) => {
|
|
197
|
+
try {
|
|
198
|
+
a.sendMessage(payloads, (data, error) => {
|
|
199
|
+
try {
|
|
200
|
+
runCommonAsserts(data, error);
|
|
201
|
+
assert.equal(200, data.code);
|
|
202
|
+
done();
|
|
203
|
+
} catch (ex) {
|
|
204
|
+
log.error(`Test Failure: ${ex}`);
|
|
205
|
+
done(ex);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
} catch (exc) {
|
|
209
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
210
|
+
done(exc);
|
|
211
|
+
}
|
|
212
|
+
}).timeout(attemptTimeout);
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
const subscribeTopicsConsumer = [topics[0].topic];
|
|
217
|
+
describe('#subscribe', () => {
|
|
218
|
+
if (!stub) {
|
|
219
|
+
it('should add topics', (done) => {
|
|
220
|
+
try {
|
|
221
|
+
a.subscribe(subscribeTopicsConsumer, 0, 0, (data, error) => {
|
|
222
|
+
try {
|
|
223
|
+
runCommonAsserts(data, error);
|
|
224
|
+
assert.equal(200, data.code);
|
|
225
|
+
done();
|
|
226
|
+
} catch (ex) {
|
|
227
|
+
log.error(`Test Failure: ${ex}`);
|
|
228
|
+
done(ex);
|
|
229
|
+
}
|
|
230
|
+
});
|
|
231
|
+
} catch (exc) {
|
|
232
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
233
|
+
done(exc);
|
|
234
|
+
}
|
|
235
|
+
}).timeout(attemptTimeout);
|
|
236
|
+
}
|
|
237
|
+
});
|
|
238
|
+
|
|
239
|
+
const subscribeAvroTopicsConsumer = [topics[0].topic];
|
|
240
|
+
describe('#subscribeAvro', () => {
|
|
241
|
+
if (!stub) {
|
|
242
|
+
it('should add topics', (done) => {
|
|
243
|
+
try {
|
|
244
|
+
a.subscribeAvro(subscribeAvroTopicsConsumer, 0, 0, (data, error) => {
|
|
245
|
+
try {
|
|
246
|
+
runCommonAsserts(data, error);
|
|
247
|
+
assert.equal(200, data.code);
|
|
248
|
+
done();
|
|
249
|
+
} catch (ex) {
|
|
250
|
+
log.error(`Test Failure: ${ex}`);
|
|
251
|
+
done(ex);
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
} catch (exc) {
|
|
255
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
256
|
+
done(exc);
|
|
257
|
+
}
|
|
258
|
+
}).timeout(attemptTimeout);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
const topicToSetOffset = topics[0].topic;
|
|
263
|
+
const partition = 1;
|
|
264
|
+
const offset = 0;
|
|
265
|
+
describe('#setOffset', () => {
|
|
266
|
+
if (!stub) {
|
|
267
|
+
it('should set offset', (done) => {
|
|
268
|
+
try {
|
|
269
|
+
a.setOffset(topicToSetOffset, partition, offset, (data, error) => {
|
|
270
|
+
try {
|
|
271
|
+
runCommonAsserts(data, error);
|
|
272
|
+
assert.equal(200, data.code);
|
|
273
|
+
done();
|
|
274
|
+
} catch (ex) {
|
|
275
|
+
log.error(`Test Failure: ${ex}`);
|
|
276
|
+
done(ex);
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
} catch (exc) {
|
|
280
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
281
|
+
done(exc);
|
|
282
|
+
}
|
|
283
|
+
}).timeout(attemptTimeout);
|
|
284
|
+
}
|
|
285
|
+
});
|
|
286
|
+
|
|
287
|
+
const topicsToPause = [topics[0].topic];
|
|
288
|
+
describe('#pauseTopics', () => {
|
|
289
|
+
if (!stub) {
|
|
290
|
+
it('should pause Topics', (done) => {
|
|
291
|
+
try {
|
|
292
|
+
a.pauseTopics(topicsToPause, (data, error) => {
|
|
293
|
+
try {
|
|
294
|
+
runCommonAsserts(data, error);
|
|
295
|
+
assert.equal(200, data.code);
|
|
296
|
+
done();
|
|
297
|
+
} catch (ex) {
|
|
298
|
+
log.error(`Test Failure: ${ex}`);
|
|
299
|
+
done(ex);
|
|
300
|
+
}
|
|
301
|
+
});
|
|
302
|
+
} catch (exc) {
|
|
303
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
304
|
+
done(exc);
|
|
305
|
+
}
|
|
306
|
+
}).timeout(attemptTimeout);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
const topicsToResume = [topics[0].topic];
|
|
311
|
+
describe('#resumeTopics', () => {
|
|
312
|
+
if (!stub) {
|
|
313
|
+
it('should resume Topics', (done) => {
|
|
314
|
+
try {
|
|
315
|
+
a.resumeTopics(topicsToResume, (data, error) => {
|
|
316
|
+
try {
|
|
317
|
+
runCommonAsserts(data, error);
|
|
318
|
+
assert.equal(200, data.code);
|
|
319
|
+
done();
|
|
320
|
+
} catch (ex) {
|
|
321
|
+
log.error(`Test Failure: ${ex}`);
|
|
322
|
+
done(ex);
|
|
323
|
+
}
|
|
324
|
+
});
|
|
325
|
+
} catch (exc) {
|
|
326
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
327
|
+
done(exc);
|
|
328
|
+
}
|
|
329
|
+
}).timeout(attemptTimeout);
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
|
|
333
|
+
describe('#pauseConsumer', () => {
|
|
334
|
+
if (!stub) {
|
|
335
|
+
it('should pause consumer', (done) => {
|
|
336
|
+
try {
|
|
337
|
+
a.pauseConsumer((data, error) => {
|
|
338
|
+
try {
|
|
339
|
+
runCommonAsserts(data, error);
|
|
340
|
+
assert.equal(200, data.code);
|
|
341
|
+
done();
|
|
342
|
+
} catch (ex) {
|
|
343
|
+
log.error(`Test Failure: ${ex}`);
|
|
344
|
+
done(ex);
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
} catch (exc) {
|
|
348
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
349
|
+
done(exc);
|
|
350
|
+
}
|
|
351
|
+
}).timeout(attemptTimeout);
|
|
352
|
+
}
|
|
353
|
+
});
|
|
354
|
+
|
|
355
|
+
describe('#resumeConsumer', () => {
|
|
356
|
+
if (!stub) {
|
|
357
|
+
it('should resume consumer', (done) => {
|
|
358
|
+
try {
|
|
359
|
+
a.resumeConsumer((data, error) => {
|
|
360
|
+
try {
|
|
361
|
+
runCommonAsserts(data, error);
|
|
362
|
+
assert.equal(200, data.code);
|
|
363
|
+
done();
|
|
364
|
+
} catch (ex) {
|
|
365
|
+
log.error(`Test Failure: ${ex}`);
|
|
366
|
+
done(ex);
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
} catch (exc) {
|
|
370
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
371
|
+
done(exc);
|
|
372
|
+
}
|
|
373
|
+
}).timeout(attemptTimeout);
|
|
374
|
+
}
|
|
375
|
+
});
|
|
376
|
+
|
|
377
|
+
describe('#commitOffset', () => {
|
|
378
|
+
if (!stub) {
|
|
379
|
+
it('should commit offset', (done) => {
|
|
380
|
+
try {
|
|
381
|
+
a.commitOffset((data, error) => {
|
|
382
|
+
try {
|
|
383
|
+
runCommonAsserts(data, error);
|
|
384
|
+
assert.equal(200, data.code);
|
|
385
|
+
done();
|
|
386
|
+
} catch (ex) {
|
|
387
|
+
log.error(`Test Failure: ${ex}`);
|
|
388
|
+
done(ex);
|
|
389
|
+
}
|
|
390
|
+
});
|
|
391
|
+
} catch (exc) {
|
|
392
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
393
|
+
done(exc);
|
|
394
|
+
}
|
|
395
|
+
}).timeout(attemptTimeout);
|
|
396
|
+
}
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
const unsubscribeTopicsConsumer = [topics[0].topic];
|
|
400
|
+
describe('#unsubscribe', () => {
|
|
401
|
+
if (!stub) {
|
|
402
|
+
it('should remove topics', (done) => {
|
|
403
|
+
try {
|
|
404
|
+
a.unsubscribe(unsubscribeTopicsConsumer, (data, error) => {
|
|
405
|
+
try {
|
|
406
|
+
runCommonAsserts(data, error);
|
|
407
|
+
assert.equal(200, data.code);
|
|
408
|
+
done();
|
|
409
|
+
} catch (ex) {
|
|
410
|
+
log.error(`Test Failure: ${ex}`);
|
|
411
|
+
done(ex);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
} catch (exc) {
|
|
415
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
416
|
+
done(exc);
|
|
417
|
+
}
|
|
418
|
+
}).timeout(attemptTimeout);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
const closeForce = false;
|
|
423
|
+
describe('#closeConsumer', () => {
|
|
424
|
+
if (!stub) {
|
|
425
|
+
it('should close consumer', (done) => {
|
|
426
|
+
try {
|
|
427
|
+
a.closeConsumer(closeForce, (data, error) => {
|
|
428
|
+
try {
|
|
429
|
+
runCommonAsserts(data, error);
|
|
430
|
+
assert.equal(200, data.code);
|
|
431
|
+
done();
|
|
432
|
+
} catch (ex) {
|
|
433
|
+
log.error(`Test Failure: ${ex}`);
|
|
434
|
+
done(ex);
|
|
435
|
+
}
|
|
436
|
+
});
|
|
437
|
+
} catch (exc) {
|
|
438
|
+
log.error(`Adapter Exception: ${exc}`);
|
|
439
|
+
done(exc);
|
|
440
|
+
}
|
|
441
|
+
}).timeout(attemptTimeout);
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
});
|
|
445
|
+
});
|