Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const t = require('tape');
const sc = require('skale').context();
const data = [['hello', 1], ['hello', 1], ['world', 1]];
const nPartitions = 2;
const init = 0;
function reducer(a, b) {return a + b;}
function combiner(a, b) {return a + b;}
t.test('aggregateByKey', function (t) {
t.plan(1);
sc.parallelize(data, nPartitions)
.aggregateByKey(reducer, combiner, init)
.collect(function(err, res) {
t.deepEqual(res, [['hello', 2], ['world', 1]]);
sc.end();
});
});
// TODO: test passing args in combiner / reducer
// TODO: test using worker contex in combiner / reducer
'use strict'
var test = require('tape').test
var bp = require('../')
test('decode stream', function (t) {
t.test('decode version', function (t) {
var stream = bp.createDecodeStream()
stream.once('data', function (message) {
t.true(message, 'got data')
t.same(message.magic, 3652501241, 'correct magic')
t.same(message.command, 'version', 'correct command')
t.same(message.length, 86, 'correct length')
t.same(message.checksum, new Buffer('d33fa729', 'hex'), 'correct checksum')
t.same(message.payload.version, 31900, 'correct version')
t.same(message.payload.services, new Buffer('0100000000000000', 'hex'), 'correct services')
t.same(message.payload.timestamp, 1292899814, 'correct timestamp')
t.same(message.payload.receiverAddress.services, new Buffer('0100000000000000', 'hex'), 'correct receiver address services')
t.same(message.payload.receiverAddress.address, '10.0.0.1', 'correct receiver address IP')
t.same(message.payload.receiverAddress.port, 8333, 'correct receiver address port')
t.same(message.payload.senderAddress.services, new Buffer('0100000000000000', 'hex'), 'correct sender address services')
t.same(message.payload.senderAddress.address, '10.0.0.2', 'correct sender address IP')
});
});
test("created
target.push(item);
cb(null, item);
}, 25 * item);
return clearTimeout.bind(null, id);
},
function(err, result)
{
t.error(err, 'expect no error response');
t.deepEqual(result, salvaged, 'expect result to contain salvaged parts of the source object');
t.deepEqual(target, expected, 'expect target to contain passed numbers');
});
});
test('parallel: object: terminated prematurely from outside', function(t)
{
var source = { first: 1, one: 1, four: 4, sixteen: 16, sixtyFour: 64, thirtyTwo: 32, eight: 8, two: 2 }
, salvaged = { }
, terminator
;
t.plan(2);
terminator = parallel(source, function(item, cb)
{
var id = setTimeout(function()
{
t.fail('do not expect it to come that far');
cb(null, item);
}, 25 * item);
function test (name, fn) {
tape.test(name, function (t) {
var source = MemDB();
var cache = MemDB();
var db = Cache(source, cache);
fn(t, db, source, cache);
});
}
lines[i + 1]);
t.strictEqual(nline.value,
'おはよう', 'CN should be set');
t.strictEqual(nline.tag, 'UTF8STRING',
'CN should be a utf8string');
foundString = true;
}
}
t.ok(foundString);
t.end();
});
kid.stdin.write(certPem);
kid.stdin.end();
});
test('make a self-signed cert with non-printable chars', function (t) {
var pem = fs.readFileSync(path.join(testDir, 'id_' + algo));
var key = sshpk.parsePrivateKey(pem, 'pkcs1');
var id = sshpk.identityFromDN('cn=foo_bar@');
var cert = sshpk.createSelfSignedCertificate(id, key);
var certPem = cert.toBuffer('pem');
var kid = spawn('openssl', ['asn1parse']);
var bufs = [];
kid.stdout.on('data', bufs.push.bind(bufs));
kid.on('close', function (rc) {
t.equal(rc, 0);
var output = Buffer.concat(bufs).toString('utf8');
var lines = output.split('\n');
var foundString = false;
for (var i = 0; i < lines.length; ++i) {
t.test('just-command', function(t) {
var res = protocol.parse('CMD')
t.equal(res.cmd, 'CMD');
t.end();
});
t.test('prefixed command', function(t) {
var res = protocol.parse(':prefix CMD')
t.equal(res.cmd, 'CMD');
t.equal(res.source, 'prefix');
t.end();
});
t.test('last argument', function(t) {
var res = protocol.construct(['TOPIC','#channel','topic text']);
var hasLast = res.split(':').length > 1;
t.ok(hasLast);
t.end();
});
t.test('no last argument', function(t) {
var res = protocol.construct(['TOPIC','#channel','topic text', null]);
var hasLast = res.split(':').length > 1;
t.ok(!hasLast);
t.end();
});
topic: '$SYS/+/new/clients',
qos: 0
}]
}, function (err) {
t.error(err, 'no error')
})
})
var s1 = connect(setup(broker), { clientId: client1 })
s1.outStream.on('data', function (packet) {
t.equal(client1, packet.payload.toString())
})
})
test('get message when client disconnects', function (t) {
t.plan(2)
var client1 = 'gav'
var client2 = 'friend'
var broker = aedes()
broker.on('client', function (client) {
if (client.id === client1) {
client.subscribe({
subscriptions: [{
topic: '$SYS/+/disconnect/clients',
qos: 0
}]
}, function (err) {
t.error(err, 'no error')
})
test('resolve:: process modules', function (t) {
var processedModule = function () {
return 1;
}
var tree = new Wiretree();
tree
.add('processedModule', processedModule, { processing: getProcessed })
.resolve(function () {
t.is(tree.plugins.processedModule.res, 'number 1');
t.end();
});
});
test('resolve:: process sync plugins', function (t) {
var processedSync = function (getOne) {
return getOne;
}
var tree = new Wiretree();
tree
.add('getOne', getOne)
.add('processedSync', {wiretree: processedSync}, { processing: getProcessed })
.resolve(function () {
t.is(tree.plugins.processedSync.res, 'number 1');
t.end();
});
});
test('resolve:: process async plugins', function (t) {
var processedAsync = function (wtDone) {
test('resolve:: resolve all async tree dependencies before call callback', function (t) {
var tree = new Wiretree();
tree
.add('mod', mod)
.add('plugin', plugin)
.add('asyncPlugin', asyncPlugin)
.resolve(function () {
t.ok(tree.plugins.plugin.res);
t.ok(tree.plugins.asyncPlugin.res);
t.end();
});
});
test('resolve:: can resolve groups', function (t) {
var tree = new Wiretree();
var salad = function (fruits) {
return fruits.orange + ' and ' + fruits.apple + ' are fruits';
};
tree
.add('apple', 'apple', {group: 'fruits' })
.add('orange', 'orange', {group: 'fruits' })
.add('salad', { wiretree: salad })
.resolve(function () {
t.is(tree.plugins.salad.res, 'orange and apple are fruits');
t.end();
});
});
test('resolve:: resolve files', function (t) {