UNPKG

2.62 kBJavaScriptView Raw
1// Copyright (c) 2015 Uber Technologies, Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21var test = require('tape');
22var KafkaServer = require(
23 './lib/kafka-rest-server.js');
24
25var Logger = require('../index.js');
26
27test('kafka is disabled', function (assert) {
28 var server = KafkaServer(function onMessage(err, msg) {
29 assert.ifError(err, 'no unexpected server error');
30 server.emit('message', msg);
31 });
32
33 var isDisabledFlag = false;
34 var logger = Logger({
35 meta: {
36 team: 'rt',
37 project: 'foobar'
38 },
39 backends: Logger.defaultBackends({
40 kafka: {
41 proxyHost: 'localhost',
42 proxyPort: server.port
43 }
44 }, {
45 isKafkaDisabled: function isDisabled() {
46 return isDisabledFlag;
47 }
48 })
49 });
50
51 logger.info('writing to kafka');
52 server.once('message', function (msg) {
53 assert.ok(msg);
54
55 isDisabledFlag = true;
56 logger.info('writing to kafka', {});
57 server.on('message', failure);
58
59 setTimeout(function onTimeout() {
60 isDisabledFlag = false;
61 server.removeListener('message', failure);
62
63 logger.info('writing to kafka', {});
64 server.once('message', function (msg) {
65 assert.ok(msg);
66
67 logger.destroy();
68 server.close();
69 assert.end();
70 });
71 }, 1000);
72
73 function failure(msg) {
74 assert.ok(false, 'unexpected message');
75 }
76 });
77});