<commit_before>/*
Copyright 2013 <NAME>.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/   
package loadtestclient;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.URI;
import java.util.Date;
import java.util.Properties;

import loadtestclient.lightstreamer.BasicWSClient;
import loadtestclient.socket_io.SocketIOClient;





public class NodeLoadTest {

    
    private static int INCREASE_CLIENTS = 100;
    private static int TEST_DURATION_MS = 60000;
    private static int CONNECT_BATCH_SIZE = 100;
    private static int CONNECT_BATCH_INTERVAL = 1000;
    
    private static int MAX_DELAY_MILLIS = 5000;
    
    private static int PORT = 8080;
    private static String HOST = "localhost";
              
    private static String FILE_PATH = "results.log";
    private static boolean TAB_LOG = true;
    
    
    private static int currentClients = 0;
    private static int expectingClients = 0;
    private static int disconnectedClients = 0;
    
    private static Statistics stats = null;
    
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        
        if (args.length < 1) {
            return;
        }
        boolean useIO = args[0].equals("io");
        String type = useIO ? "io" : "ls";
        
        if (args.length > 1) {

            Properties props = new Properties();
            try {
                props.load(new FileInputStream(new File(args[1])));
            } catch (IOException e) {
            }
            
            INCREASE_CLIENTS = Integer.parseInt(props.getProperty("INCREASE_CLIENTS"));
            TEST_DURATION_MS = Integer.parseInt(props.getProperty("TEST_DURATION_MS"));
            CONNECT_BATCH_SIZE = Integer.parseInt(props.getProperty("CONNECT_BATCH_SIZE"));
            CONNECT_BATCH_INTERVAL = Integer.parseInt(props.getProperty("CONNECT_BATCH_INTERVAL"));
            
            MAX_DELAY_MILLIS = Integer.parseInt(props.getProperty("MAX_DELAY_MILLIS"));
            
            HOST = props.getProperty("HOST");
            PORT = Integer.parseInt(props.getProperty("PORT"));
            
            FILE_PATH = props.getProperty("FILE_PATH");
            
            TAB_LOG = props.getProperty("TAB_LOG").equals("true");
            
        }
        
        final String SERVER_URL = "http://"+HOST+":"+PORT;
        
        CListener currentTestListener = new CListener(); 
        
        while(true) {
            expectingClients += INCREASE_CLIENTS;
                     
            if (stats != null) {
                stats.onTestComplete();
            }
            
            System.out.println("Launching "+INCREASE_CLIENTS+ " new clients");
            
            stats = new Statistics(type,expectingClients,TAB_LOG,FILE_PATH,MAX_DELAY_MILLIS);
    
            //connect the clients CONNECT_BATCH_SIZE at a time, then wait CONNECT_BATCH_INTERVAL
            for (int i = 0; i < INCREASE_CLIENTS;) {
                for (int b = 0; b < CONNECT_BATCH_SIZE && i < INCREASE_CLIENTS; b++,i++) {
                    try {
                        if (useIO) {
                            URI uri = SocketIOClient.getNewSocketURI(HOST+":"+PORT);
                            SocketIOClient c = new SocketIOClient(uri,currentTestListener);
                            c.connect();
                        } else {
                            new BasicWSClient(SERVER_URL,currentTestListener);
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    
                }
                try {
                    Thread.sleep(CONNECT_BATCH_INTERVAL);
                } catch (InterruptedException e) {
                }
            }
            
            try {
                Thread.sleep(TEST_DURATION_MS);
            } catch (InterruptedException e) {
            }
        }
        <commit_msg>let the main test use the new client<commit_after>/*
Copyright 2013 <NAME>.

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/   
package loadtestclient;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Date;
import java.util.Properties;

import loadtestclient.client.BasicWSClient;





public class NodeLoadTest {

    
    private static int INCREASE_CLIENTS = 100;
    private static int TEST_DURATION_MS = 60000;
    private static int CONNECT_BATCH_SIZE = 100;
    private static int CONNECT_BATCH_INTERVAL = 1000;
    
    private static int MAX_DELAY_MILLIS = 5000;
    
    private static int PORT = 8080;
    private static String HOST = "localhost";
              
    private static String FILE_PATH = "results.log";
    private static boolean TAB_LOG = true;
    
    
    private static int currentClients = 0;
    private static int expectingClients = 0;
    private static int disconnectedClients = 0;
    
    private static Statistics stats = null;
    
    
    
    /**
     * @param args
     */
    public static void main(String[] args) {
        
        if (args.length < 1) {
            return;
        }
        boolean useIO = args[0].equals("io");
        String type = useIO ? "io" : "ls";
        
        if (args.length > 1) {

            Properties props = new Properties();
            try {
                props.load(new FileInputStream(new File(args[1])));
            } catch (IOException e) {
            }
            
            INCREASE_CLIENTS = Integer.parseInt(props.getProperty("INCREASE_CLIENTS"));
            TEST_DURATION_MS = Integer.parseInt(props.getProperty("TEST_DURATION_MS"));
            CONNECT_BATCH_SIZE = Integer.parseInt(props.getProperty("CONNECT_BATCH_SIZE"));
            CONNECT_BATCH_INTERVAL = Integer.parseInt(props.getProperty("CONNECT_BATCH_INTERVAL"));
            
            MAX_DELAY_MILLIS = Integer.parseInt(props.getProperty("MAX_DELAY_MILLIS"));
            
            HOST = props.getProperty("HOST");
            PORT = Integer.parseInt(props.getProperty("PORT"));
            
            FILE_PATH = props.getProperty("FILE_PATH");
            
            TAB_LOG = props.getProperty("TAB_LOG").equals("true");
            
        }
        
        final String SERVER_URL = HOST+":"+PORT;
        
        CListener currentTestListener = new CListener(); 
        
        while(true) {
            expectingClients += INCREASE_CLIENTS;
                     
            if (stats != null) {
                stats.onTestComplete();
            }
            
            System.out.println("Launching "+INCREASE_CLIENTS+ " new clients");
            
            stats = new Statistics(type,expectingClients,TAB_LOG,FILE_PATH,MAX_DELAY_MILLIS);
    
            //connect the clients CONNECT_BATCH_SIZE at a time, then wait CONNECT_BATCH_INTERVAL
            for (int i = 0; i < INCREASE_CLIENTS;) {
                for (int b = 0; b < CONNECT_BATCH_SIZE && i < INCREASE_CLIENTS; b++,i++) {
                    try {
                        
                        new BasicWSClient(SERVER_URL,currentTestListener,useIO);
                     
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    
                }
                try {
                    Thread.sleep(CONNECT_BATCH_INTERVAL);
                } catch (InterruptedException e) {
                }
            }
            
            try {
                Thread.sleep(TEST_DURATION_MS);
            } catch (InterruptedException e) {
            }
        }
        
{'fraction_non_alphanumeric': 0.08322737255808577, 'fraction_numerical': 0.009247485839787307, 'mean_word_length': 1.770413064361191, 'pattern_counts': {'":': 3, '<': 13, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4031591', 'n_tokens_mistral': 2367, 'n_tokens_neox': 2277, 'n_words': 580}