Package oracletestapplication.services

Source Code of oracletestapplication.services.TestService

package oracletestapplication.services;

import oracletestapplication.tests.ExecutionThread;
import oracletestapplication.tests.TestCase;
import oracletestapplication.tests.TestSuite;
import oracletestapplication.tests.log.ILogWriter;

public class TestService {
 
 
 
  private TestService() {
    // Az oszt�lyb�l nem lehet p�ld�nyt l�trehozni.
  }
 
  public static long executeTestCase(TestCase testCase) {
    // A teszteset v�grehajt�s�nak idej�t t�bb v�grehajt�sb�l sz�rmaz� �tlag
    // seg�ts�g�vel adjuk meg.
    long durationTime = 0;

    for (int i = 0; i < testCase.getNumExecution(); i++) {
      ExecutionThread[] threads = new ExecutionThread[testCase.getNumThreads()];
      for (int j = 0; j < threads.length; j++) {
        threads[j] = new ExecutionThread(DatabaseService.createConnection(testCase.getConnectionData()),
            testCase.getTestStatement());
      }

      for (ExecutionThread thread : threads) {
        thread.start();
      }

      long beginTime = System.nanoTime();

      boolean isFinished = false;
      while (isFinished != true) {
        isFinished = true;
        for (ExecutionThread thread : threads) {
          isFinished = isFinished && (!thread.isAlive());
        }
      }

      durationTime += ((System.nanoTime() - beginTime) / 1000 / 1000);

      for (ExecutionThread thread : threads) {
        DatabaseService.closeConnection(thread.getConnection());
      }

      // Minden tesztv�grehajt�s ut�n ki�r�tj�k a shared pool-t.
      DatabaseService.flushSharedPool(testCase.getConnectionData());
    }

    // A sz�mtani �tlag kisz�m�t�sa.
    durationTime /= testCase.getNumExecution();

    return durationTime;
  }

  // public static long executeTestCase(TestCase testCase) {
  // ExecutionThread[] threads = new
  // ExecutionThread[testCase.getNumThreads()];
  // for (int i = 0; i < threads.length; i++) {
  // threads[i] = new
  // ExecutionThread(DatabaseService.createConnection(testCase.getConnectionData()),
  // testCase
  // .getTestStatement());
  // }
  //   
  // //A teszteset v�grehajt�s�nak idej�t t�bb v�grehajt�sb�l sz�rmaz� �tlag
  // seg�ts�g�vel adjuk meg.
  // long durationTime = 0;
  //
  // for (int i = 0; i < testCase.getNumExecution(); i++) {
  //
  // for (ExecutionThread thread : threads) {
  // thread.start();
  // }
  //
  // long beginTime = System.nanoTime();
  //
  // boolean isFinished = false;
  // while (isFinished != true) {
  // isFinished = true;
  // for (ExecutionThread thread : threads) {
  // isFinished = isFinished && (!thread.isAlive());
  // }
  // }
  //
  // durationTime += ((System.nanoTime() - beginTime) / 1000 / 1000);
  // }
  //   
  // //A sz�mtani �tlag kisz�m�t�sa.
  // durationTime /= testCase.getNumExecution();
  //
  // for (ExecutionThread thread : threads) {
  // DatabaseService.closeConnection(thread.getConnection());
  // }
  //
  // return durationTime;
  // }

  public static long executeTestSuite(TestSuite testSuite, ILogWriter logWriter) {
    long sumDuration = 0;

    for (TestCase testCase : testSuite.getTestCases()) {
      long duration = executeTestCase(testCase);
      logWriter.writeLine(testCase.toString() + " V�grehajt�si id�: " + duration+ " ms");
      sumDuration += duration;
    }
    return sumDuration;
  }
}
TOP

Related Classes of oracletestapplication.services.TestService

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.