Skip to content

Commit

Permalink
Merge pull request #4 from jdepoix/hotfix/testcase-performance-fix
Browse files Browse the repository at this point in the history
Hotfix/testcase performance fix
  • Loading branch information
jdepoix committed Jun 3, 2016
2 parents 947181a + ed962a6 commit e68cf84
Show file tree
Hide file tree
Showing 14 changed files with 348 additions and 64 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ apply plugin: 'idea'
apply plugin: 'shadow'

sourceCompatibility = 1.7
version = 'v4.0-alpha-1'
version = 'v4.0-alpha-2'

// download dependencies from Maven Central
repositories {
Expand Down
52 changes: 15 additions & 37 deletions src/main/java/de/fhbingen/wbs/controller/TestCaseController.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package de.fhbingen.wbs.controller;

import de.fhbingen.wbs.dbaccess.DBModelManager;
import de.fhbingen.wbs.dbaccess.data.TestCase;
import de.fhbingen.wbs.dbaccess.data.TestExecution;
import de.fhbingen.wbs.dbaccess.models.mysql.MySQLTestCaseModel;
import de.fhbingen.wbs.dbaccess.models.mysql.MySQLTestExecutionModel;
import de.fhbingen.wbs.dbaccess.repositories.TestCaseExecutionRepository;
import de.fhbingen.wbs.dbaccess.repositories.TestCaseRepository;
import de.fhbingen.wbs.globals.Workpackage;

import java.util.List;
Expand All @@ -13,66 +14,52 @@ public class TestCaseController {

private Workpackage workpackage;



public TestCaseController(Workpackage workpackage) {
this.workpackage = workpackage;
}


/**
* @return
* List of all Testcases
*/

public List<TestCase> getAllTestCases() {
return this.workpackage.getAllTestCases();
}



/**
* @param tc
* TestCase for which we want to fetch the latest execution
* @return
* latest execution for this Testcase
*/

public TestExecution getLatestExecutionForTestCase(TestCase tc){
return tc.getLatestExecution();
return TestCaseExecutionRepository.getLatestTestExecution(tc);
}



/**
*
* @param tc
* TestCase for wich we want to fetch the executions
* @return
* List of executions for this Testcase
*/


public List<TestExecution> getTestExecutionsForTestCase(TestCase tc){

MySQLTestExecutionModel sqlexecm = new MySQLTestExecutionModel();
return sqlexecm.getExecutionsForTestCase(tc);
return TestCaseExecutionRepository.getAllTestCaseExecutions(tc);
}


/**
*
* @param tc
* TestCase (belonging to this objects wp) to add to db
* @return
* success of this operation
*/

public boolean addTestCase(TestCase tc){
MySQLTestCaseModel sqltcm = new MySQLTestCaseModel();
return sqltcm.addNewTestCase(tc);
}
boolean result = DBModelManager.getTestCaseModel().addNewTestCase(tc);
TestCaseRepository.reloadCache();

return result;
}

/**
*
Expand All @@ -81,28 +68,23 @@ public boolean addTestCase(TestCase tc){
* @return
* success of this operation
*/

public boolean updateTestCase(TestCase tc){
MySQLTestCaseModel sqltcm = new MySQLTestCaseModel();
return sqltcm.updateTestCase(tc);
return TestCaseRepository.updateTestCase(tc);
}



/**
*
* @param te
* TestExecution to add
* @return
* success of this operation
*/

public boolean addTestExecution(TestExecution te){
MySQLTestExecutionModel sqlexecm = new MySQLTestExecutionModel();
return sqlexecm.addNewTestExecution(te);
}

boolean result = DBModelManager.getTestExecutionModel().addNewTestExecution(te);
TestCaseExecutionRepository.reloadCache();

return result;
}

/**
*
Expand All @@ -111,10 +93,8 @@ public boolean addTestExecution(TestExecution te){
* @return
* success of this operation
*/

public boolean updateTestExecution(TestExecution te){
MySQLTestExecutionModel sqlexecm = new MySQLTestExecutionModel();
return sqlexecm.updateTestExecution(te);
return TestCaseExecutionRepository.updateTestCaseExecution(te);
}

/**
Expand All @@ -124,6 +104,4 @@ public boolean updateTestExecution(TestExecution te){
public List<TestCase> getTestCases(){
return this.workpackage.getTestCases();
}


}
1 change: 0 additions & 1 deletion src/main/java/de/fhbingen/wbs/dbaccess/DBModelManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

package de.fhbingen.wbs.dbaccess;

import de.fhbingen.wbs.dbaccess.data.TestExecution;
import de.fhbingen.wbs.dbaccess.models.*;
import de.fhbingen.wbs.dbaccess.models.mysql.*;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ public interface TestExecutionModel {
*/
boolean addNewTestExecution(TestExecution testexec);

/**
* Gets all testexecutions
*
* @return list of all testexecutions
*/
List<TestExecution> getAllTestExecutions();

/**
* Gets all testexecutions for a specific testcase.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public List<TestCase> getAllTestCases() {
ResultSet sqlResult = null;
PreparedStatement stm = null;

String storedProcedure = "CALL test_case_select_by_wp()";
String storedProcedure = "CALL test_case_select()";

try {
stm = connection.prepareStatement(storedProcedure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,41 @@ public boolean addNewTestExecution(TestExecution testexec) {
return success;
}

@Override
public List<TestExecution> getAllTestExecutions() {
final Connection connection = SQLExecuter.getConnection();
List<TestExecution> teList = new ArrayList<TestExecution>();
ResultSet sqlResult = null;
PreparedStatement stm = null;

String storedProcedure = "CALL test_execution_select()";

try {
stm = connection.prepareStatement(storedProcedure);
sqlResult = stm.executeQuery();

while (sqlResult.next()) {
teList.add(teFromResultSet(sqlResult));
}

} catch (SQLException e) {
e.printStackTrace();
} finally {
try {
if (sqlResult != null) {
sqlResult.close();
}
if (stm != null) {
stm.close();
}
} catch (SQLException e) {
e.printStackTrace();
}
}

return teList;
}

@Override
public List<TestExecution> getExecutionsForTestCase(TestCase testcase) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package de.fhbingen.wbs.dbaccess.repositories;

import de.fhbingen.wbs.dbaccess.DBModelManager;
import de.fhbingen.wbs.dbaccess.data.TestCase;
import de.fhbingen.wbs.dbaccess.data.TestExecution;
import de.fhbingen.wbs.dbaccess.repositories.core.ParentToElementMappedCache;

import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class TestCaseExecutionRepository {
private static class TestCaseExecutionParentToElementMappedCache extends ParentToElementMappedCache<TestExecution> {
@Override
protected List<TestExecution> loadAllElements() {
return DBModelManager.getTestExecutionModel().getAllTestExecutions();
}

@Override
protected Integer getParentId(TestExecution element) {
return element.getTestcaseID();
}

@Override
protected Integer getId(TestExecution element) {
return element.getId();
}
}

private static TestCaseExecutionParentToElementMappedCache testCaseExecutionMap;

private TestCaseExecutionRepository() {}

public static List<TestExecution> getAllTestCaseExecutions(TestCase testCase) {
return getTestCaseExecutionMap().getAllByParentElement(testCase.getId());
}

public static TestExecution getLatestTestExecution(TestCase testCase) {
List<TestExecution> allTestCaseExecutions = getAllTestCaseExecutions(testCase);

if (!allTestCaseExecutions.isEmpty()) {
Collections.sort(allTestCaseExecutions, new Comparator<TestExecution>() {
@Override
public int compare(TestExecution o1, TestExecution o2) {
return o2.getTime().compareTo(o1.getTime());
}
});

return allTestCaseExecutions.get(0);
}

return null;
}

public static TestCaseExecutionParentToElementMappedCache getTestCaseExecutionMap() {
if (testCaseExecutionMap == null) {
testCaseExecutionMap = new TestCaseExecutionParentToElementMappedCache();
}

return testCaseExecutionMap;
}

public static boolean updateTestCaseExecution(TestExecution testExecution) {
testCaseExecutionMap.setElement(testExecution);
return DBModelManager.getTestExecutionModel().updateTestExecution(testExecution);
}

public static void reloadCache() {
testCaseExecutionMap.loadCache();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,51 @@

import de.fhbingen.wbs.dbaccess.DBModelManager;
import de.fhbingen.wbs.dbaccess.data.TestCase;
import de.fhbingen.wbs.dbaccess.data.Workpackage;
import de.fhbingen.wbs.dbaccess.repositories.core.ParentToElementMappedCache;

import java.util.HashMap;
import java.util.Map;
import java.util.List;

/**
* Created by jdepoix on 01.06.16.
*/
public class TestCaseRepository {
private static Map<Integer, Map<Integer, TestCase>> workpackageTestCaseMap = getWorkpackageTestCasesMap();
private static class TestCaseParentToElementMappedCache extends ParentToElementMappedCache<TestCase> {
@Override
protected List<TestCase> loadAllElements() {
return DBModelManager.getTestCaseModel().getAllTestCases();
}

@Override
protected Integer getParentId(TestCase element) {
return element.getWorkpackageID();
}

@Override
protected Integer getId(TestCase element) {
return element.getId();
}
}

private static TestCaseParentToElementMappedCache workpackageTestCaseMap;

private TestCaseRepository() {}

private static Map<Integer, Map<Integer, TestCase>> getWorkpackageTestCasesMap() {
Map<Integer, Map<Integer, TestCase>> newWorkpackageTestCaseMap = new HashMap<>();
Map<Integer, TestCase> currentTestCaseMap = null;

for (TestCase testCase : DBModelManager.getTestCaseModel().getAllTestCases()) {
if ((currentTestCaseMap = newWorkpackageTestCaseMap.get(testCase.getWorkpackageID())) == null) {
currentTestCaseMap = new HashMap<>();
currentTestCaseMap.put(testCase.getId(), testCase);
newWorkpackageTestCaseMap.put(testCase.getWorkpackageID(), currentTestCaseMap);
} else {
currentTestCaseMap.put(testCase.getId(), testCase);
}
public static List<TestCase> getAllTestCases(Workpackage workpackage) {
return getWorkpackageTestCaseMap().getAllByParentElement(workpackage.getId());
}

public static TestCaseParentToElementMappedCache getWorkpackageTestCaseMap() {
if (workpackageTestCaseMap == null) {
workpackageTestCaseMap = new TestCaseParentToElementMappedCache();
}

return newWorkpackageTestCaseMap;
return workpackageTestCaseMap;
}

public static boolean updateTestCase(TestCase testCase) {
workpackageTestCaseMap.setElement(testCase);
return DBModelManager.getTestCaseModel().updateTestCase(testCase);
}

public static void reloadAll() {
TestCaseRepository.workpackageTestCaseMap = TestCaseRepository.getWorkpackageTestCasesMap();
public static void reloadCache() {
workpackageTestCaseMap.loadCache();
}
}
Loading

0 comments on commit e68cf84

Please sign in to comment.