Skip to content

Commit

Permalink
Remove concurrent hash map in our logging metadata implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
halprin committed Nov 3, 2023
1 parent dd397a0 commit 94a8b98
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import gov.hhs.cdc.trustedintermediary.wrappers.Logger;
import gov.hhs.cdc.trustedintermediary.wrappers.MetricMetaData;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import javax.inject.Inject;

/**
Expand All @@ -15,27 +14,27 @@
public class LoggingMetricMetaData implements MetricMetaData {
private static final LoggingMetricMetaData INSTANCE = new LoggingMetricMetaData();

@Inject Logger logger;

public static LoggingMetricMetaData getInstance() {
return INSTANCE;
}

@Inject Logger logger;

private LoggingMetricMetaData() {}

private static final Map<String, Object> metadataMap = new ConcurrentHashMap<>();

@Override
public void put(String bundleId, MetaDataStep step) {
MetaDataEntry entry = extractMetricsFromBundle(bundleId, step);
metadataMap.put("BundleId", entry.bundleId());
metadataMap.put("Entry Time", entry.entryTime());
metadataMap.put("Entry Step", entry.entryStep());
logger.logMap("MetaData Event Occured:", metadataMap);
}

public Map<String, Object> getMetaDataMap() {
return metadataMap;
var metadataMap =
Map.of(
"BundleId",
entry.bundleId(),
"Entry Time",
entry.entryTime(),
"Entry Step",
entry.entryStep());

logger.logMap("MetaData Event Occurred:", metadataMap);
}

private MetaDataEntry extractMetricsFromBundle(String bundleId, MetaDataStep step) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package gov.hhs.cdc.trustedintermediary.external.inmemory

import gov.hhs.cdc.trustedintermediary.context.TestApplicationContext
import gov.hhs.cdc.trustedintermediary.metadata.MetaDataStep
import gov.hhs.cdc.trustedintermediary.wrappers.Logger
import gov.hhs.cdc.trustedintermediary.wrappers.MetricMetaData
import spock.lang.Specification

Expand All @@ -14,12 +15,20 @@ class LoggingMetricMetaDataTest extends Specification {
TestApplicationContext.injectRegisteredImplementations()
}

def "meta data map is populated"() {
def "meta data is correctly logged out"() {
given:
var logger = Mock(Logger)
TestApplicationContext.register(Logger, logger)
TestApplicationContext.injectRegisteredImplementations()

when:
LoggingMetricMetaData.getInstance().put("Key", _ as MetaDataStep)

then:
LoggingMetricMetaData.getInstance().getMetaDataMap().containsKey("BundleId")
1 * logger.logMap(_ as String, _ as Map) >> { String message, Map keyValue ->
assert keyValue.containsKey("BundleId")
assert keyValue.containsKey("Entry Time")
assert keyValue.containsKey("Entry Step")
}
}
}

0 comments on commit 94a8b98

Please sign in to comment.