Skip to content

Commit

Permalink
Replace HashMap with ConcurrentHashMap in TestCasesRegistry
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyBrenko committed Aug 6, 2024
1 parent 980cefe commit 428cc88
Showing 1 changed file with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
package com.zebrunner.agent.core.registrar;

import com.zebrunner.agent.core.annotation.TestCaseStatusOnFail;
import com.zebrunner.agent.core.annotation.TestCaseStatusOnPass;
import com.zebrunner.agent.core.annotation.TestCaseStatusOnSkip;
import com.zebrunner.agent.core.config.ConfigurationHolder;
import com.zebrunner.agent.core.registrar.descriptor.TestDescriptor;
import com.zebrunner.agent.core.registrar.domain.TcmType;
import com.zebrunner.agent.core.registrar.domain.TestCaseResult;
import lombok.extern.slf4j.Slf4j;

import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.EnumMap;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.function.Supplier;

import com.zebrunner.agent.core.annotation.TestCaseStatusOnFail;
import com.zebrunner.agent.core.annotation.TestCaseStatusOnPass;
import com.zebrunner.agent.core.annotation.TestCaseStatusOnSkip;
import com.zebrunner.agent.core.config.ConfigurationHolder;
import com.zebrunner.agent.core.registrar.descriptor.TestDescriptor;
import com.zebrunner.agent.core.registrar.domain.TcmType;
import com.zebrunner.agent.core.registrar.domain.TestCaseResult;

@Slf4j
class TestCasesRegistry {

Expand All @@ -45,7 +46,7 @@ static TestCasesRegistry getInstance() {
}

private final ZebrunnerApiClient zebrunnerApiClient = ClientRegistrar.getClient();
private final Map<Long, Map<TcmType, Map<String, String>>> testIdToTcmTypeToTestCaseIdToStatus = new HashMap<>();
private final Map<Long, Map<TcmType, Map<String, String>>> testIdToTcmTypeToTestCaseIdToStatus = new ConcurrentHashMap<>();

void addTestCasesToCurrentTest(TcmType tcmType, Collection<String> testCaseIds) {
RunContext.getCurrentTest()
Expand Down Expand Up @@ -74,8 +75,8 @@ void setCurrentTestTestCaseStatus(TcmType tcmType, String testCaseId, String sta
}

private Map<String, String> getTestCaseIdToStatus(Long testId, TcmType tcmType) {
return testIdToTcmTypeToTestCaseIdToStatus.computeIfAbsent(testId, $ -> new HashMap<>())
.computeIfAbsent(tcmType, $ -> new HashMap<>());
return testIdToTcmTypeToTestCaseIdToStatus.computeIfAbsent(testId, $ -> new ConcurrentHashMap<>())
.computeIfAbsent(tcmType, $ -> new ConcurrentHashMap<>());
}

void setExplicitStatusesOnCurrentTestPass() {
Expand Down Expand Up @@ -116,7 +117,7 @@ void setExplicitStatusesOnCurrentTestSkip() {

private void setCaseStatusesIfThereIsNoExplicit(Long testId, String status) {
List<TestCaseResult> results = new ArrayList<>();
testIdToTcmTypeToTestCaseIdToStatus.computeIfAbsent(testId, $ -> new HashMap<>())
testIdToTcmTypeToTestCaseIdToStatus.computeIfAbsent(testId, $ -> new ConcurrentHashMap<>())
.forEach((tcmType, testCaseIdToStatus) ->
testCaseIdToStatus.forEach((testCaseId, explicitStatus) -> {
if (explicitStatus == null) {
Expand Down

0 comments on commit 428cc88

Please sign in to comment.