Skip to content

Commit

Permalink
Make dummy objects thread safe
Browse files Browse the repository at this point in the history
This is an attempt to enable DummyGroup objects to participate
in multi-threaded tests.
  • Loading branch information
mederly committed May 3, 2021
1 parent 9d82b6f commit 729d699
Showing 1 changed file with 12 additions and 8 deletions.
Expand Up @@ -12,12 +12,12 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;

import org.apache.commons.lang.StringUtils;

Expand All @@ -34,14 +34,14 @@ public abstract class DummyObject implements DebugDumpable {
private String id;
// private int internalId = -1;
private String name;
private Map<String,Set<Object>> attributes = new HashMap<>();
private final Map<String,Set<Object>> attributes = new ConcurrentHashMap<>();
private Boolean enabled = true;
private Date validFrom = null;
private Date validTo = null;
private String lastModifier;
protected DummyResource resource;

private final Set<String> auxiliaryObjectClassNames = new HashSet<>();
private final Set<String> auxiliaryObjectClassNames = ConcurrentHashMap.newKeySet();

private BreakMode modifyBreakMode = null;

Expand Down Expand Up @@ -160,7 +160,7 @@ public void replaceAttributeValues(String name, Collection<Object> values) throw
delayOperation();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
currentValues = new HashSet<>();
currentValues = createNewSet();
attributes.put(name, currentValues);
} else {
currentValues.clear();
Expand All @@ -170,12 +170,16 @@ public void replaceAttributeValues(String name, Collection<Object> values) throw
recordModify(name, null, null, values);
}

private Set<Object> createNewSet() {
return ConcurrentHashMap.newKeySet();
}

public void replaceAttributeValues(String name, Object... values) throws SchemaViolationException, ConnectException, FileNotFoundException, SchemaViolationException, ConflictException, InterruptedException {
checkModifyBreak();
delayOperation();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
currentValues = new HashSet<>();
currentValues = createNewSet();
attributes.put(name, currentValues);
} else {
currentValues.clear();
Expand All @@ -200,7 +204,7 @@ public <T> void addAttributeValues(String name, Collection<T> valuesToAdd) throw
delayOperation();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
currentValues = new HashSet<>();
currentValues = createNewSet();
attributes.put(name, currentValues);
}
for(T valueToAdd: valuesToAdd) {
Expand All @@ -214,7 +218,7 @@ public void addAttributeValues(String name, String... valuesToAdd) throws Schema
delayOperation();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
currentValues = new HashSet<>();
currentValues = createNewSet();
attributes.put(name, currentValues);
}
for (Object valueToAdd: valuesToAdd) {
Expand Down Expand Up @@ -268,7 +272,7 @@ public <T> void removeAttributeValues(String name, Collection<T> values) throws
delayOperation();
Set<Object> currentValues = attributes.get(name);
if (currentValues == null) {
currentValues = new HashSet<>();
currentValues = createNewSet();
attributes.put(name, currentValues);
}

Expand Down

0 comments on commit 729d699

Please sign in to comment.