<commit_before>// Load modules

var ChildProcess = require('child_process');
var Fs = require('fs');
var Http = require('http');
var Lab = require('lab');
var Path = require('path');

var Hapi = require('hapi');


// Declare internals

var internals = {};


// Test shortcuts

var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;


describe('Broadcast', function () {

    var broadcastPath = Path.join(__dirname, '..', 'bin', 'broadcast');
    var lastBroadcastPath = Path.join(__dirname, '..', 'lib', 'lastBroadcast_request_log_test.004');
    var logPath1 = Path.join(__dirname, 'request_log_test.001');
    var logPath2 = Path.join(__dirname, 'request_log_test.002');
    var logPath3 = Path.join(__dirname, 'request_log_test.003');
    var logPath4 = Path.join(__dirname, 'request_log_test.004');
    var logPath5 = Path.join(__dirname, 'request_log_test.005');
    var logPath6 = Path.join(__dirname, 'request_log_test.006');
    var logPath7 = Path.join(__dirname, 'request_log_test.007');
    var opsLogPath1 = Path.join(__dirname, 'ops_log_test.001');
    var broadcastJsonPath = Path.join(__dirname, 'broadcast.json');

    var data1 = '{"event":"request","timestamp":1369328752975,"id":"1369328752975-42369-3828","instance":"http://localhost:8080","labels":["api","http"],' +
        '"method":"get","path":"/test","query":{},"source":{"remoteAddress":"127.0.0.1"},"responseTime":71,"statusCode":200}';
    var data2 = '{"event":"request","timestamp":1369328753222,"id":"1369328753222-42369-62002","instance":"http://localhost:8080","labels":["api","http"],' +
        '"method":"get","path":"/test","query":{},"source":{"remoteAddress":"127.0.0.1"},"responseTime":9,"statusCode":200}';
    var opsData1 = '{"event":"ops","timestamp":1375466329196,"os":{"load":[0.38671875,0.390625,0.51171875],"mem":{"total":3221225472,"free":2790420480},"uptime":5690647,"cpu":"70.81"},"proc":{"uptime":414,"mem":{"rss":204468224,"heapTotal":64403456,"heapUsed":29650600,"total":3221225472},"delay":0},"load":{"requests":{"8080":1007,"8443":178},"concurrents":{"8080":8,"8443":-7}}}';

    var locations = [logPath1, logPath2, logPath3, logPath4, logPath5, logPath6, logPath7, opsLogPath1, broadcastJsonPath, lastBroadcastPath];
    var cleanup = function (done) {
        for (var i = 0, il = locations.length; i < il; ++i) {
            if (Fs.existsSync(locations[i])) {
                Fs.unlinkSync(locations[i]);
            }
        }

        return done();
    };

    before(cleanup);
    it('sends log file to remote server', function (done) {


        var broadcast = null;
        var server = Hapi.createServer('127.0.0.1', 8001);

        server.route({
            path: '/',
            method: 'POST',
            handler: function (request, reply) {

                expect(request.payload.schema).to.equal('good.v1');
                expect(request.payload.events[1].id).to.equal('1369328753222-42369-62002');

                broadcast.kill('SIGUSR2');
            }
        });

        server.start( function () {
            var url = 'http://127.0.0.1:8001/';

            broadcast = ChildProcess.spawn(process.execPath, [broadcastPath, '-l', '/Users/nvcexploder/src/git/spumko/good/test/fixtures/test_01.log', '-u', url, '-i', 5, '-p', 0]);

            broadcast.stderr.on('data', function (data) {
                expect(data.toString()).to.not.exist;
            });

            broadcast.once('close', function (code) {<commit_msg>fix up test 1 to be more generic and use hapi<commit_after>// Load modules

var ChildProcess = require('child_process');
var Fs = require('fs');
var Http = require('http');
var Lab = require('lab');
var Path = require('path');

var Hapi = require('hapi');


// Declare internals

var internals = {};


// Test shortcuts

var expect = Lab.expect;
var before = Lab.before;
var after = Lab.after;
var describe = Lab.experiment;
var it = Lab.test;


describe('Broadcast', function () {

    var broadcastPath = Path.join(__dirname, '..', 'bin', 'broadcast');
    var lastBroadcastPath = Path.join(__dirname, '..', 'lib', 'lastBroadcast_request_log_test.004');
    var logPath1 = Path.join(__dirname, 'request_log_test.001');
    var logPath2 = Path.join(__dirname, 'request_log_test.002');
    var logPath3 = Path.join(__dirname, 'request_log_test.003');
    var logPath4 = Path.join(__dirname, 'request_log_test.004');
    var logPath5 = Path.join(__dirname, 'request_log_test.005');
    var logPath6 = Path.join(__dirname, 'request_log_test.006');
    var logPath7 = Path.join(__dirname, 'request_log_test.007');
    var opsLogPath1 = Path.join(__dirname, 'ops_log_test.001');
    var broadcastJsonPath = Path.join(__dirname, 'broadcast.json');

    var data1 = '{"event":"request","timestamp":1369328752975,"id":"1369328752975-42369-3828","instance":"http://localhost:8080","labels":["api","http"],' +
        '"method":"get","path":"/test","query":{},"source":{"remoteAddress":"127.0.0.1"},"responseTime":71,"statusCode":200}';
    var data2 = '{"event":"request","timestamp":1369328753222,"id":"1369328753222-42369-62002","instance":"http://localhost:8080","labels":["api","http"],' +
        '"method":"get","path":"/test","query":{},"source":{"remoteAddress":"127.0.0.1"},"responseTime":9,"statusCode":200}';
    var opsData1 = '{"event":"ops","timestamp":1375466329196,"os":{"load":[0.38671875,0.390625,0.51171875],"mem":{"total":3221225472,"free":2790420480},"uptime":5690647,"cpu":"70.81"},"proc":{"uptime":414,"mem":{"rss":204468224,"heapTotal":64403456,"heapUsed":29650600,"total":3221225472},"delay":0},"load":{"requests":{"8080":1007,"8443":178},"concurrents":{"8080":8,"8443":-7}}}';

    var locations = [logPath1, logPath2, logPath3, logPath4, logPath5, logPath6, logPath7, opsLogPath1, broadcastJsonPath, lastBroadcastPath];
    var cleanup = function (done) {
        for (var i = 0, il = locations.length; i < il; ++i) {
            if (Fs.existsSync(locations[i])) {
                Fs.unlinkSync(locations[i]);
            }
        }

        return done();
    };

    before(cleanup);
    it('sends log file to remote server', function (done) {


        var broadcast = null;
        var server = Hapi.createServer('127.0.0.1', 0);

        server.route({
            path: '/',
            method: 'POST',
            handler: function (request, reply) {

                expect(request.payload.schema).to.equal('good.v1');
                expect(request.payload.events[1].id).to.equal('1369328753222-42369-62002');

                broadcast.kill('SIGUSR2');
            }
        });

        server.start( function () {
            var url = server.info.uri;

            broadcast = ChildProcess.spawn(process.execPath, [broadcastPath, '-l', './test/fixtures/test_01.log', '-u', url, '-i', 5, '-p', 0]);

            broadcast.stderr.on('data', function (data) {
                expect(data.toString()).to.not.exist;
            });

            broadcast.once('close', function (code) {
{'fraction_non_alphanumeric': 0.19602555003548616, 'fraction_numerical': 0.09198012775017743, 'mean_word_length': 3.747978436657682, 'pattern_counts': {'":': 96, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 7, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3171742', 'n_tokens_mistral': 2677, 'n_tokens_neox': 2264, 'n_words': 372}