<commit_before>/*
 * Copyright (c) 2012-2013, Yahoo! Inc.  All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE file for terms.
 */

YUI.add('proxymanager-tests', function (Y, NAME) {

        //TODO - Stub portchecker

        var path = require('path'),
            http = require('http'),
            log4js = require("log4js"),
            logger = log4js.getLogger("ProxyManagerTests"),
            arrowRoot = path.join(__dirname, '../../../../'),
            ProxyManager = require("../../../../lib/proxy/proxymanager.js"),
            portchecker = require("../../../../ext-lib/portchecker"),
            localhostip = require('../../../../arrow_server/arrowservermanager').getLocalhostIPAddress(),
            suite = new Y.Test.Suite(NAME),
            A = Y.Assert,
            self = this;


        /**
         * If port is available, proxy server should be started
         */
        function testSendRequestToProxyServer() {

            //TODO - Not complete
            var
            // TODO - Check the first available port here starting from minPort
                minPort = 10801,
                maxPort = 10900,
                hostName = "localhost",
                routerJsonPath = __dirname + "/config/router.json",
                proxyManager = new ProxyManager(routerJsonPath, {}),
                options,
                req;

            function createProxyServerRequest(minPort, maxPort, hostName, callback) {

                proxyManager.runRouterProxy(minPort, maxPort, hostName, function (proxyHostMsg) {

                    A.areNotEqual(proxyHostMsg, 'localhost:' + minPort, 'Proxy host should not match');
                    A.areEqual(proxyHostMsg, localhostip + ':' + minPort, 'Proxy host doesn\'t match');
                    callback();

                });
            }

            A.areEqual(routerJsonPath, proxyManager.proxyConfig, 'Router jsonpath doesn\'t match');

            createProxyServerRequest(minPort, maxPort, hostName, function () {

                function onRequest(request, response) {

                    response.writeHead(200, {"Content-Type": "text/plain"});
                    response.write("Hello world");
                    response.end();

                }

                portchecker.getFirstAvailable(11000, 11100, "localhost", function (p) {

//                http.createServer(onRequest).listen(p);

                    options = {
                        host: hostName,
                        port: minPort,
                        path: '/',
                        method: 'GET'
                    };

                    req = http.request(options, function (res) {
                        res.setEncoding('utf8');
                        res.on('data', function (chunk) {
                            console.log('BODY: ' + chunk);
                        });
                    });

                    req.on('error', function (e) {
                        console.log('problem with request: ' + e.message);
                    });

                    // write data to request body
                    req.write('my data\n');
                    req.end();

                });

            });


        }

        /**
         * If port is available, proxy server should be started
         */
        function testClientSideInstrumentOnProxyServer() {

            // TODO - Check the first available port here starting from minPort
            var minPort = 10901,
                maxPort = 11000,
                hostName = "localhost",
                routerJsonPath = __dirname + "/config/router.json",
                proxyManager = new ProxyManager(routerJsonPath, {}),
                options,
                req;

            function createProxyServerRequest(minPort, maxPort, hostName, callback) {

                proxyManager.runRouterProxy(minPort, maxPort, hostName, function (proxyHostMsg) {

                    A.areNotEqual(proxyHostMsg, 'localhost:' + minPort, 'Proxy host should not match');
                    A.areEqual(proxyHostMsg, localhostip + ':' + minPort, 'Proxy host doesn\'t match');
                    callback();

                });
            }

            createProxyServerRequest(minPort, maxPort, hostName, function () {


                options = {
                    host: hostName,
                    port: minPort,
                    path: '/proxyCoverage?sid=12345',
                    method: 'GET'
                };

                function sentToCoverage(method, data) {
                    options.method = method;
                    req = http.request(options, function (res) {
                        res.setEncoding('utf8');
                        res.on('data', function (chunk) {<commit_msg>update ut<commit_after>/*
 * Copyright (c) 2012-2013, Yahoo! Inc.  All rights reserved.
 * Copyrights licensed under the New BSD License.
 * See the accompanying LICENSE file for terms.
 */

YUI.add('proxymanager-tests', function (Y, NAME) {

        //TODO - Stub portchecker

        var path = require('path'),
            http = require('http'),
            log4js = require("log4js"),
            logger = log4js.getLogger("ProxyManagerTests"),
            arrowRoot = path.join(__dirname, '../../../../'),
            ProxyManager = require("../../../../lib/proxy/proxymanager.js"),
            portchecker = require("../../../../ext-lib/portchecker"),
            localhostip = require('../../../../arrow_server/arrowservermanager').getLocalhostIPAddress(),
            suite = new Y.Test.Suite(NAME),
            A = Y.Assert,
            self = this;


        /**
         * If port is available, proxy server should be started
         */
        function testSendRequestToProxyServer() {

            //TODO - Not complete
            var
            // TODO - Check the first available port here starting from minPort
                minPort = 10801,
                maxPort = 10900,
                hostName = "localhost",
                routerJsonPath = __dirname + "/config/router.json",
                proxyManager = new ProxyManager(routerJsonPath, {}),
                options,
                req;

            function createProxyServerRequest(minPort, maxPort, hostName, callback) {

                proxyManager.runRouterProxy(minPort, maxPort, hostName, function (proxyHostMsg) {

                    A.areNotEqual(proxyHostMsg, 'localhost:' + minPort, 'Proxy host should not match');
                    A.areEqual(proxyHostMsg, localhostip + ':' + minPort, 'Proxy host doesn\'t match');
                    callback();

                });
            }

            A.areEqual(routerJsonPath, proxyManager.proxyConfig, 'Router jsonpath doesn\'t match');

            createProxyServerRequest(minPort, maxPort, hostName, function () {

                function onRequest(request, response) {

                    response.writeHead(200, {"Content-Type": "text/plain"});
                    response.write("Hello world");
                    response.end();

                }

                portchecker.getFirstAvailable(11000, 11100, "localhost", function (p) {

//                http.createServer(onRequest).listen(p);

                    options = {
                        host: hostName,
                        port: minPort,
                        path: '/',
                        method: 'GET'
                    };

                    req = http.request(options, function (res) {
                        res.setEncoding('utf8');
                        res.on('data', function (chunk) {
                            console.log('BODY: ' + chunk);
                        });
                    });

                    req.on('error', function (e) {
                        console.log('problem with request: ' + e.message);
                    });

                    // write data to request body
                    req.write('my data\n');
                    req.end();

                });

            });


        }

        /**
         * If port is available, proxy server should be started
         */
        function testClientSideInstrumentOnProxyServer() {

            // TODO - Check the first available port here starting from minPort
            var minPort = 10901,
                maxPort = 11000,
                hostName = "localhost",
                routerJsonPath = __dirname + "/config/router.json",
                proxyManager = new ProxyManager(routerJsonPath, {}),
                options,
                req;

            global.currentSessionid = global.currentSessionid || '12345';

            function createProxyServerRequest(minPort, maxPort, hostName, callback) {

                proxyManager.runRouterProxy(minPort, maxPort, hostName, function (proxyHostMsg) {

                    A.areNotEqual(proxyHostMsg, 'localhost:' + minPort, 'Proxy host should not match');
                    A.areEqual(proxyHostMsg, localhostip + ':' + minPort, 'Proxy host doesn\'t match');
                    callback();

                });
            }

            createProxyServerRequest(minPort, maxPort, hostName, function () {


                options = {
                    host: hostName,
                    port: minPort,
                    path: '/proxyCoverage?sid=12345',
                    method: 'GET'
                };

                function sentToCoverage(method, data) {
                    options.method = method;
                    req = http.request(options, function (res) {
                        res.setEncoding('utf8');
                        res.on('data', function (chunk) {
{'fraction_non_alphanumeric': 0.11130578171699475, 'fraction_numerical': 0.011027517262702256, 'mean_word_length': 1.359922178988327, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, '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': '358615', 'n_tokens_mistral': 2484, 'n_tokens_neox': 2202, 'n_words': 534}