Skip to content

Commit

Permalink
fix(test): replace HashMap with ConcurrentHashMap to avoid Concurrent…
Browse files Browse the repository at this point in the history
…Modificatio… (googleapis#883)

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
oshai and gcf-owl-bot[bot] authored Apr 11, 2022
1 parent 0d0f40d commit d2fe2a0
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.annotation.concurrent.NotThreadSafe;

/**
Expand Down Expand Up @@ -77,11 +77,11 @@ class FakeStorageRpc extends StorageRpcTestBase {
new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX");

// fullname -> metadata
Map<String, StorageObject> metadata = new HashMap<>();
Map<String, StorageObject> metadata = new ConcurrentHashMap<>();
// fullname -> contents
Map<String, byte[]> contents = new HashMap<>();
Map<String, byte[]> contents = new ConcurrentHashMap<>();
// fullname -> future contents that will be visible on close.
Map<String, byte[]> futureContents = new HashMap<>();
Map<String, byte[]> futureContents = new ConcurrentHashMap<>();

private final boolean throwIfOption;

Expand All @@ -92,8 +92,8 @@ public FakeStorageRpc(boolean throwIfOption) {

// remove all files
void reset() {
metadata = new HashMap<>();
contents = new HashMap<>();
metadata = new ConcurrentHashMap<>();
contents = new ConcurrentHashMap<>();
}

@Override
Expand Down Expand Up @@ -149,7 +149,7 @@ public Tuple<String, Iterable<StorageObject>> list(String bucket, Map<Option, ?>
final String prefix = preprefix;

List<StorageObject> values = new ArrayList<>();
Map<String, StorageObject> folders = new HashMap<>();
Map<String, StorageObject> folders = new ConcurrentHashMap<>();
for (StorageObject so : metadata.values()) {
if (!so.getBucket().equals(bucket) || !so.getName().startsWith(prefix)) {
continue;
Expand Down

0 comments on commit d2fe2a0

Please sign in to comment.