Skip to content

Commit a1dbec7

Browse files
fix(test): replace HashMap with ConcurrentHashMap to avoid ConcurrentModificatio… (#883)
Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
1 parent 3676886 commit a1dbec7

File tree

1 file changed

+7
-7
lines changed
  • java-storage-nio/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing

1 file changed

+7
-7
lines changed

java-storage-nio/google-cloud-nio/src/main/java/com/google/cloud/storage/contrib/nio/testing/FakeStorageRpc.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
import java.util.ArrayList;
3535
import java.util.Arrays;
3636
import java.util.Date;
37-
import java.util.HashMap;
3837
import java.util.List;
3938
import java.util.Map;
39+
import java.util.concurrent.ConcurrentHashMap;
4040
import javax.annotation.concurrent.NotThreadSafe;
4141

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

7979
// fullname -> metadata
80-
Map<String, StorageObject> metadata = new HashMap<>();
80+
Map<String, StorageObject> metadata = new ConcurrentHashMap<>();
8181
// fullname -> contents
82-
Map<String, byte[]> contents = new HashMap<>();
82+
Map<String, byte[]> contents = new ConcurrentHashMap<>();
8383
// fullname -> future contents that will be visible on close.
84-
Map<String, byte[]> futureContents = new HashMap<>();
84+
Map<String, byte[]> futureContents = new ConcurrentHashMap<>();
8585

8686
private final boolean throwIfOption;
8787

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

9393
// remove all files
9494
void reset() {
95-
metadata = new HashMap<>();
96-
contents = new HashMap<>();
95+
metadata = new ConcurrentHashMap<>();
96+
contents = new ConcurrentHashMap<>();
9797
}
9898

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

151151
List<StorageObject> values = new ArrayList<>();
152-
Map<String, StorageObject> folders = new HashMap<>();
152+
Map<String, StorageObject> folders = new ConcurrentHashMap<>();
153153
for (StorageObject so : metadata.values()) {
154154
if (!so.getBucket().equals(bucket) || !so.getName().startsWith(prefix)) {
155155
continue;

0 commit comments

Comments
 (0)