Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/issue 160 perf testresult #106

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,22 @@
# CHANGELOG
## 1.5.2 (2024-08-11)
Performance:
- Decrease time of the response for test result by test_id
- Decrease time of the response for test result by test_result_id

## 1.5.1 (2024-04-12)
Bugfixes:
- Fixed 500 (Entity is locked) issue
- Fixed SQL connections leak
- Improved /public/test/create-or-update, /public/test/result/start, /public/test/result/finish performance
- Fixed INSERT_TEST_RESULT final_result_id comparison

## 1.5.1 (2024-04-12)
Bugfixes:
- Fixed 500 (Entity is locked) issue
- Fixed SQL connections leak
- Improved /public/test/create-or-update, /public/test/result/start, /public/test/result/finish performance
- Fixed INSERT_TEST_RESULT final_result_id comparison

## 1.5.0 (2023-07-28)
- Added `/issues/assign` endpoint, which allows to check previously created Test Runs and Test Results and assign Issues to them if there's a RegEx match
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>unifi_reporting_api</groupId>
<artifactId>api</artifactId>
<packaging>war</packaging>
<version>1.5.0</version>
<version>1.5.2</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
114 changes: 69 additions & 45 deletions src/main/java/main/controllers/Project/ResultController.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
import main.model.dto.settings.UserDto;
import main.utils.RegexpUtil;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

public class ResultController extends BaseController<TestResultDto> {
Expand Down Expand Up @@ -56,15 +54,29 @@ public TestResultDto create(TestResultDto template) throws AqualityException {
}
}

@Override
public List<TestResultDto> get(TestResultDto template) throws AqualityException {
if (baseUser.isFromGlobalManagement() || baseUser.getProjectUser(template.getProject_id()).isViewer()) {
return fillResults(testResultDao.searchAll(template));
public TestResultDto updateWithFinalResultIdAndFailReason(TestResultDto testResult) throws AqualityException {
if (baseUser.isManager() || baseUser.getProjectUser(testResult.getProject_id()).isEditor()) {
return testResultDao.updateFinalResultIdAndFailReason(
testResult.getId(),
testResult.getFinal_result_id(),
testResult.getFail_reason(),
testResult.getFinish_date());
} else {
throw new AqualityPermissionsException("Account is not allowed to view Test Results", baseUser);
throw new AqualityPermissionsException("Account is not allowed to update Test Result", baseUser);
}
}

@Override
public List<TestResultDto> get(TestResultDto template) throws AqualityException {
checkReadPermissions(template.getProject_id());
return fillResults(testResultDao.searchAll(template), template);
}

public List<TestResultDto> getRaw(TestResultDto template) throws AqualityException {
checkReadPermissions(template.getProject_id());
return testResultDao.searchAll(template);
}

@Override
public boolean delete(TestResultDto template) throws AqualityException {
if (baseUser.isManager() || baseUser.getProjectUser(template.getProject_id()).isEditor()) {
Expand All @@ -76,8 +88,11 @@ public boolean delete(TestResultDto template) throws AqualityException {

public List<TestResultDto> getOnlyFailedResults(TestResultDto testResultTemplate) throws AqualityException {
List<TestResultDto> testResults = this.get(testResultTemplate);
return testResults.stream().filter(x -> x.getFinal_result_id() != FAILED_STATUS_ID && x.getFail_reason() != null
&& x.getIssue_id() == null).collect(Collectors.toList());
return testResults.stream()
.filter(x -> !Objects.equals(x.getFinal_result_id(), FAILED_STATUS_ID) &&
x.getFail_reason() != null &&
x.getIssue_id() == null)
.collect(Collectors.toList());
}

public boolean createMultiple(List<TestResultAttachmentDto> listOfAttachments) throws AqualityException {
Expand All @@ -91,14 +106,14 @@ public boolean createMultiple(List<TestResultAttachmentDto> listOfAttachments) t
public List<TestResultDto> getLatestResultsByMilestone(Integer projectId, Integer milestoneId)
throws AqualityException {
if (baseUser.isFromGlobalManagement() || baseUser.getProjectUser(projectId).isViewer()) {
return fillResults(testResultDao.selectLatestResultsByMilestone(milestoneId));
return fillResults(testResultDao.selectLatestResultsByMilestone(milestoneId), new TestResultDto());
} else {
throw new AqualityPermissionsException("Account is not allowed to view Test Results", baseUser);
}
}

public boolean updateMultipleTestResults(List<TestResultDto> entities) throws AqualityException {
if (entities.size() > 0
if (!entities.isEmpty()
&& (baseUser.isManager() || baseUser.getProjectUser(entities.get(0).getProject_id()).isEditor())) {
return testResultDao.updateMultiply(entities);
} else {
Expand All @@ -114,6 +129,38 @@ public List<TestResultStatDto> get(TestResultStatDto template) throws AqualityEx
}
}

public Map<String, Integer> matchIssues(Integer testResultId) throws AqualityException {
TestResultDto testResultTemplate = new TestResultDto();
testResultTemplate.setId(testResultId);
List<TestResultDto> testResults = this.getOnlyFailedResults(testResultTemplate);
if (testResults.isEmpty()) {
throw new AqualityParametersException("No test result found to update. Wrong ID might be provided.");
}
IssueDto issueTemplate = new IssueDto();
issueTemplate.setProject_id(testResults.get(0).getProject_id());
List<IssueDto> issues = issueController.get(issueTemplate);
Integer count = assignIssuesToResults(issues, testResults);
Map<String, Integer> results = new HashMap<>();
results.put("Issues assigned", count);
return results;
}

public Integer assignIssuesToResults(List<IssueDto> issues, List<TestResultDto> testResults)
throws AqualityException {
Integer count = 0;
for (TestResultDto testResult : testResults) {
for (IssueDto issue : issues) {
if (issue.getExpression() != null
&& RegexpUtil.match(testResult.getFail_reason(), issue.getExpression())) {
testResult.setIssue_id(issue.getId());
this.create(testResult);
count++;
}
}
}
return count;
}

private void createPendingStepResults(TestResultDto template) throws AqualityException {
Step2TestDto step2TestTemplate = new Step2TestDto();
step2TestTemplate.setProject_id(template.getProject_id());
Expand All @@ -131,21 +178,24 @@ private void createPendingStepResults(TestResultDto template) throws AqualityExc
}
}

private List<TestResultDto> fillResults(List<TestResultDto> results) throws AqualityException {
private List<TestResultDto> fillResults(List<TestResultDto> results, TestResultDto searchTemplate) throws AqualityException {

if (results.size() > 0) {
if (!results.isEmpty()) {
int projectId = results.get(0).getProject_id();
List<FinalResultDto> finalResults = finalResultController.get(new FinalResultDto());
IssueDto issueDto = new IssueDto();
issueDto.setProject_id(projectId);
List<IssueDto> issues = issueController.get(issueDto);

TestDto testTemplate = new TestDto();
testTemplate.setProject_id(projectId);
List<TestDto> tests = testController.get(testTemplate);

TestResultAttachmentDto testResultAttachmentTemplate = new TestResultAttachmentDto();
testResultAttachmentTemplate.setProject_id(projectId);
testResultAttachmentTemplate.setTest_run_id(searchTemplate.getTest_run_id());
testResultAttachmentTemplate.setTest_id(searchTemplate.getTest_id());
testResultAttachmentTemplate.setTest_result_id(searchTemplate.getId());

List<TestResultAttachmentDto> testResultAttachments = testResultAttachmentController
.get(testResultAttachmentTemplate);

Expand All @@ -163,7 +213,7 @@ private List<TestResultDto> fillResults(List<TestResultDto> results) throws Aqua
}

private void fillResult(TestResultDto result, List<FinalResultDto> finalResults, List<TestDto> tests,
List<IssueDto> issues, List<TestResultAttachmentDto> attachments, boolean isStepsEnabled)
List<IssueDto> issues, List<TestResultAttachmentDto> attachments, boolean isStepsEnabled)
throws AqualityException {
if (isStepsEnabled) {
fillResultSteps(result);
Expand All @@ -187,35 +237,9 @@ private void fillResultSteps(TestResultDto result) throws AqualityException {
result.setSteps(stepResultController.get(stepResultTemplate));
}

public Map<String, Integer> matchIssues(Integer testResultId) throws AqualityException {
TestResultDto testResultTemplate = new TestResultDto();
testResultTemplate.setId(testResultId);
List<TestResultDto> testResults = this.getOnlyFailedResults(testResultTemplate);
if (testResults.isEmpty()) {
throw new AqualityParametersException("No test result found to update. Wrong ID might be provided.");
}
IssueDto issueTemplate = new IssueDto();
issueTemplate.setProject_id(testResults.get(0).getProject_id());
List<IssueDto> issues = issueController.get(issueTemplate);
Integer count = assignIssuesToResults(issues, testResults);
Map<String, Integer> results = new HashMap<>();
results.put("Issues assigned", count);
return results;
}

public Integer assignIssuesToResults(List<IssueDto> issues, List<TestResultDto> testResults)
throws AqualityException {
Integer count = 0;
for (TestResultDto testResult : testResults) {
for (IssueDto issue : issues) {
if (issue.getExpression() != null
&& RegexpUtil.match(testResult.getFail_reason(), issue.getExpression())) {
testResult.setIssue_id(issue.getId());
this.create(testResult);
count++;
}
}
private void checkReadPermissions(Integer projectId) throws AqualityException {
if (!(baseUser.isFromGlobalManagement() || baseUser.getProjectUser(projectId).isViewer())) {
throw new AqualityPermissionsException("Account is not allowed to view Test Results", baseUser);
}
return count;
}
}
Loading