2828import software .amazon .cloudwatchlogs .emf .model .Unit ;
2929
3030import java .lang .reflect .Field ;
31+ import java .time .Duration ;
3132import java .util .Arrays ;
3233import java .util .Collections ;
3334import java .util .List ;
@@ -60,7 +61,7 @@ class EMFLoggingMeterRegistryTest {
6061 private final MockClock clock = new MockClock ();
6162 private final EMFLoggingMeterRegistry registry = spy (
6263 new EMFLoggingMeterRegistry (
63- EMFLoggingRegistryConfig . DEFAULT , new EnvironmentProvider ().resolveEnvironment ().join (), clock )
64+ k -> null , new EnvironmentProvider ().resolveEnvironment ().join (), clock )
6465 );
6566 private final EMFLoggingMeterRegistry .Snapshot registrySnapshot = registry .new Snapshot ();
6667
@@ -218,7 +219,7 @@ void snapshotFunctionCounterDataValid() {
218219 void snapshotFunctionCounterDataShouldClampInfiniteValues () {
219220 FunctionCounter functionCounter = FunctionCounter
220221 .builder ("my.positive.infinity" , Double .POSITIVE_INFINITY , Number ::doubleValue ).register (registry );
221- clock .add (EMFLoggingRegistryConfig . DEFAULT . step ( ));
222+ clock .add (Duration . ofMinutes ( 1 ));
222223 final List <EMFLoggingMeterRegistry .MetricDataPoint > metricDataPoints1 = registrySnapshot
223224 .functionCounterData (functionCounter )
224225 .collect (Collectors .toList ());
@@ -227,7 +228,7 @@ void snapshotFunctionCounterDataShouldClampInfiniteValues() {
227228
228229 functionCounter = FunctionCounter
229230 .builder ("my.negative.infinity" , Double .NEGATIVE_INFINITY , Number ::doubleValue ).register (registry );
230- clock .add (EMFLoggingRegistryConfig . DEFAULT . step ( ));
231+ clock .add (Duration . ofMinutes ( 1 ));
231232 final List <EMFLoggingMeterRegistry .MetricDataPoint > metricDataPoints2 = registrySnapshot
232233 .functionCounterData (functionCounter )
233234 .collect (Collectors .toList ());
@@ -270,7 +271,7 @@ void snapshotShouldNotAddFunctionTimerDataWhenSumIsNaN() {
270271 final FunctionTimer functionTimer = FunctionTimer
271272 .builder ("my.function.timer" , Double .NaN , Number ::longValue , Number ::doubleValue , TimeUnit .MILLISECONDS )
272273 .register (registry );
273- clock .add (EMFLoggingRegistryConfig . DEFAULT . step ( ));
274+ clock .add (Duration . ofMinutes ( 1 ));
274275 final List <EMFLoggingMeterRegistry .MetricDataPoint > metricDataPoints = registrySnapshot
275276 .functionTimerData (functionTimer )
276277 .collect (Collectors .toList ());
@@ -358,7 +359,12 @@ private MetricsContext reflectivelyGetMetricsContext(final MetricsLogger metrics
358359
359360 @ Test
360361 void testAdditionalPropertiesAreAddedToMetricsLogger () {
361- final Map <String , String > additionalProperties = Map .of ("key1" , "value1" , "key2" , "value2" );
362+ final String randomKey1 = "testKey_" + System .currentTimeMillis ();
363+ final String randomValue1 = "testValue_" + Math .random ();
364+ final String randomKey2 = "anotherKey_" + System .nanoTime ();
365+ final String randomValue2 = "anotherValue_" + Math .random ();
366+
367+ final Map <String , String > additionalProperties = Map .of (randomKey1 , randomValue1 , randomKey2 , randomValue2 );
362368 final EMFLoggingRegistryConfig config = new EMFLoggingRegistryConfig () {
363369 @ Override
364370 public String get (String key ) {
@@ -378,8 +384,17 @@ public Map<String, String> additionalProperties() {
378384 final List <MetricsLogger > metricsLoggers = registryWithProperties .metricsLoggers ();
379385
380386 assertThat (metricsLoggers .size (), equalTo (1 ));
381- // Note: We can't directly verify putProperty calls without mocking the MetricsLogger
382- // This test verifies the registry can be created with additional properties config
387+
388+ final MetricsLogger metricsLogger = metricsLoggers .get (0 );
389+ final MetricsContext context = reflectivelyGetMetricsContext (metricsLogger );
390+
391+ // Verify properties exist
392+ assertThat (context .getProperty (randomKey1 ), equalTo (randomValue1 ));
393+ assertThat (context .getProperty (randomKey2 ), equalTo (randomValue2 ));
394+
395+ // Verify properties are not dimensions
396+ assertThat (hasDimension (context , randomKey1 ), is (false ));
397+ assertThat (hasDimension (context , randomKey2 ), is (false ));
383398 }
384399
385400 private boolean hasDimension (final MetricsContext context , final String key ) {
0 commit comments