Akshat-Jain commented on code in PR #17622: URL: https://github.com/apache/druid/pull/17622#discussion_r1921105216
########## processing/src/test/java/org/apache/druid/java/util/metrics/HttpPostEmitterMonitorTest.java: ########## @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.java.util.metrics; + +import com.google.common.collect.ImmutableMap; +import org.apache.druid.java.util.emitter.core.ConcurrentTimeCounter; +import org.apache.druid.java.util.emitter.core.HttpPostEmitter; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.atMost; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class HttpPostEmitterMonitorTest +{ + private HttpPostEmitter mockHttpPostEmitter; + private ServiceEmitter mockServiceEmitter; + private ImmutableMap<String, String> mockExtraDimensions; Review Comment: `mockExtraDimensions` is only used in `setUp()`, hence can be moved there as a local variable. Also, since it's used just at one place, you could also consider removing the variable in favour of directly doing: ```java monitor = new HttpPostEmitterMonitor( "testFeed", mockHttpPostEmitter, ImmutableMap.of("dimensionKey", "dimensionValue") ); ``` ########## processing/src/test/java/org/apache/druid/java/util/metrics/HttpPostEmitterMonitorTest.java: ########## @@ -0,0 +1,154 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.druid.java.util.metrics; + +import com.google.common.collect.ImmutableMap; +import org.apache.druid.java.util.emitter.core.ConcurrentTimeCounter; +import org.apache.druid.java.util.emitter.core.HttpPostEmitter; +import org.apache.druid.java.util.emitter.service.ServiceEmitter; +import org.apache.druid.java.util.emitter.service.ServiceMetricEvent; +import org.junit.Assert; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.ArgumentCaptor; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.atMost; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +public class HttpPostEmitterMonitorTest +{ + private HttpPostEmitter mockHttpPostEmitter; + private ServiceEmitter mockServiceEmitter; + private ImmutableMap<String, String> mockExtraDimensions; + private HttpPostEmitterMonitor monitor; + + @BeforeEach + public void setUp() + { + mockHttpPostEmitter = mock(HttpPostEmitter.class); + mockServiceEmitter = mock(ServiceEmitter.class); + mockExtraDimensions = ImmutableMap.of("dimensionKey", "dimensionValue"); + + monitor = new HttpPostEmitterMonitor("testFeed", mockHttpPostEmitter, mockExtraDimensions); + } + + @Test + public void testDoMonitor() Review Comment: I think we can have a single test `testDoMonitor()` as `doMonitor()` already calls all the other methods. Would suggest making the following changes for `testDoMonitor`: 1. Instead of using `mockServiceEmitter` as a mock, you can instead use `StubServiceEmitter`. The reason it helps is that it records the metrics it has emitted, hence we can get the relevant info about the emitted metrics we need, and do the assertions. 2. You can do something like the following to extract the emitted metrics, where `serviceEmitter` is a `StubServiceEmitter`: ```java monitor.doMonitor(serviceEmitter); Map<String, List<StubServiceEmitter.ServiceMetricEventSnapshot>> metricEvents = serviceEmitter.getMetricEvents(); ``` With the above changes, the single test would be validating all the methods, and you would be able to extract and validate the emitter metrics. Hence you can then remove all the other tests of this file. Let me know if you have any questions on this, happy to help! ########## processing/src/test/java/org/apache/druid/js/JavaScriptConfigTest.java: ########## @@ -60,4 +60,46 @@ public void testSerdeWithDefaults() throws Exception Assert.assertFalse(config.isEnabled()); } + + @Test + public void testEquals() Review Comment: `testEquals()` and `testHashCode()` can be replaced with a single test using `EqualsVerifier`: ```java @Test public void testEqualsAndHashcode() { EqualsVerifier.simple() .forClass(JavaScriptConfig.class) .usingGetClass() .withNonnullFields("enabled") .verify(); } ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org