john pfeiffer
  • Home
  • Categories
  • Tags
  • Archives

threads logger log4j commandline parameters array to arraylist

    private static final Logger logger = Logger.getLogger(NirvanixStorageConnectorTestClient.class.getName());

    private enum ConnectorType
    {
        NIRVANIX_PUBLIC, NIRVANIX_IBM, NIRVANIX_PARTNER_LAB
    };

    private enum TestType
    {
        SIMPLE, EXTENDED
    };

    private static TestType testType = TestType.SIMPLE;     // Which tests to run, default is SIMPLE
    private static ConnectorType connectorType = ConnectorType.NIRVANIX_PUBLIC; //Which environment to test against, default is PUBLIC
    private static int reportLevel = Level.INFO_INT;        // Logging level of detail, default is INFO


    // Simply set up the debug log on classes we are interest
    public static void setUpBeforeClass(int logLevel) throws Exception
    {
        Class<?>[] debuggingclasses = { NirvanixStorageConnector.class, NirvanixStorageConnectorTestClient.class };
        NirvanixStorageConnectorTestClient.configureLogging(debuggingclasses, logLevel);
    }


        if (args != null)
        {
            ArrayList<String> wordList = new ArrayList <String>( Arrays.asList(args) );
             for (String word : wordList)
              {
                 if( word.equalsIgnoreCase("partnerlab"))
                 {
                     connectorType = ConnectorType.NIRVANIX_PARTNER_LAB;
                 }
                 if( word.equalsIgnoreCase("ibm"))
                 {
                     connectorType = ConnectorType.NIRVANIX_IBM;
                 }
                 if( word.equalsIgnoreCase("extended"))
                 {
                    testType = TestType.EXTENDED;
                 }
                 if( word.equalsIgnoreCase("debug"))
                 {
                    reportLevel = Level.DEBUG_INT;
                 }
              }
        }
        System.out.println("==================================================");
        System.out.println("P R O J E C T    A C C E P T A N C E     T E S T S");
        System.out.println("==================================================");
        System.out.println( "Logging=" + reportLevel + " , ConnectorType=" + connectorType + " TestType=" + testType );
        System.out.println( Arrays.toString( args ) );
        NirvanixStorageConnectorTestClient testClient = new NirvanixStorageConnectorTestClient();

        setUpBeforeClass( reportLevel );
        testClient.initializeTestConnector(connectorType);


...

    private static void configureLogging(Class<?>[] loggedClasses, int level_)
    {
        String LogLevel;
        switch (level_)
        {
        case Level.INFO_INT:
            LogLevel = Level.INFO.toString();
            break;
        default:
            LogLevel = Level.DEBUG.toString();
            break;
        }
        Properties props = new Properties();
        props.put("log4j.rootLogger", Level.INFO.toString() + ", " + "R");
        props.put("log4j.appender.R", ConsoleAppender.class.getName());
        props.put("log4j.appender.R.encoding", "UTF-8");
        props.put("log4j.appender.R.layout", PatternLayout.class.getName());
        props.put("log4j.appender.R.layout.ConversionPattern", "%d %5p (%F:%L) - %m%n");
        for (@SuppressWarnings("rawtypes")
        Class clazz : loggedClasses)
        {
            props.put("log4j.logger." + clazz.getName(), LogLevel);
        }
        PropertyConfigurator.configure(props);
    }

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


        final int TOTAL_FILES = 100;
        final int MAX_WORKERS = 200;
        final int MAX_ALLOWED_RUNTIME_IN_MILLISECONDS = 120000;

        final int OPERATIONS_PER_WORKER = TOTAL_FILES / MAX_WORKERS;
        ExecutorService executorService = Executors.newFixedThreadPool(MAX_WORKERS);
        Set<Callable<String>> gets = new HashSet<Callable<String>>(MAX_WORKERS);

        logger.debug("expectation:" + "Make " + MAX_WORKERS + " concurrent threads to complete " + TOTAL_FILES + " gets in "
                + MAX_ALLOWED_RUNTIME_IN_MILLISECONDS / 1000 + " seconds");
        for (int i = 0; i < MAX_WORKERS; i++)
        {
            final int workerId = i;
            Callable<String> task = new Callable<String>()
            {
                @Override
                public String call() throws Exception
                {
                    String success = "";
                    for (int i = 0; i < OPERATIONS_PER_WORKER; i++)
                    {
                        String filename = filename_ + "_" + (MAX_WORKERS * i + workerId);
                        InputStream resultStream = connector.getFile(rootFolder + "/" + filename, sessionToken);

                        byte[] returnedData = NirvanixStorageConnectorTestClient.convertStreamToByteArray(resultStream);
                        if (!Arrays.equals(rawData, returnedData))
                        {
                            throw new Exception("Assertion fail: get file return corrupted data");
                        }
                    }
                    return success;
                }
            };
            gets.add(task);
        }

  • « HTTP Post multipart form
  • wireshark winpcap npf windows »

Published

Nov 2, 2012

Category

java

~293 words

Tags

  • array 16
  • arraylist 3
  • commandline 12
  • java 252
  • log4j 3
  • logger 1
  • parameters 15
  • threads 1
  • to 63