Skip to content

Commit

Permalink
Fix unit test testSharedInstance fail (apache#13908)
Browse files Browse the repository at this point in the history
  • Loading branch information
shibd authored Jan 24, 2022
1 parent 1ceab68 commit b208ab0
Showing 1 changed file with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.NavigableMap;
Expand Down Expand Up @@ -64,6 +65,9 @@ private static class Value {

private static final Map<String, NavigableMap<String, Value>> STATIC_MAPS = new MapMaker()
.weakValues().makeMap();
// Manage all instances to facilitate registration to the same listener
private static final Map<String, Set<AbstractMetadataStore>> STATIC_INSTANCE = new MapMaker()
.weakValues().makeMap();
private static final Map<String, AtomicLong> STATIC_ID_GEN_MAP = new MapMaker()
.weakValues().makeMap();

Expand All @@ -84,6 +88,17 @@ public LocalMemoryMetadataStore(String metadataURL, MetadataStoreConfig metadata
// Use a reference from a shared data set
String name = uri.getHost();
map = STATIC_MAPS.computeIfAbsent(name, __ -> new TreeMap<>());
STATIC_INSTANCE.compute(name, (key, value) -> {
if (value == null) {
value = new HashSet<>();
}
value.forEach(v -> {
registerListener(v);
v.registerListener(this);
});
value.add(this);
return value;
});
sequentialIdGenerator = STATIC_ID_GEN_MAP.computeIfAbsent(name, __ -> new AtomicLong());
log.info("Created LocalMemoryDataStore for '{}'", name);
}
Expand Down

0 comments on commit b208ab0

Please sign in to comment.