kfaraz commented on code in PR #17596: URL: https://github.com/apache/druid/pull/17596#discussion_r1903662579
########## extensions-core/simple-client-sslcontext/src/test/java/org/apache/druid/https/SSLClientConfigTest.java: ########## @@ -0,0 +1,86 @@ +/* + * 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.https; + +import org.apache.druid.metadata.PasswordProvider; +import org.junit.Test; + +import java.lang.reflect.Field; + +import static org.junit.Assert.assertEquals; + +public class SSLClientConfigTest +{ + @Test + public void testGetters() throws NoSuchFieldException, IllegalAccessException + { + SSLClientConfig sslClientConfig = new SSLClientConfig(); + + String expectedProtocol = "TLS"; + String expectedTrustStoreType = "JKS"; + String expectedTrustStorePath = "/path/to/truststore"; + String expectedTrustStoreAlgorithm = "SunX509"; + PasswordProvider expectedTrustStorePasswordProvider = () -> "trustStorePassword"; + String expectedKeyStorePath = "/path/to/keystore"; + String expectedKeyStoreType = "JKS"; + String expectedCertAlias = "alias"; + PasswordProvider expectedKeyStorePasswordProvider = () -> "keyStorePassword"; + PasswordProvider expectedKeyManagerPasswordProvider = () -> "keyManagerPassword"; + String expectedKeyManagerFactoryAlgorithm = "SunX509"; + Boolean expectedValidateHostnames = true; + + // Use reflection to set the private fields Review Comment: Please don't use reflection for this. Either - add a constructor - OR, override the getters to return the expected values - OR, deserialize the object from a json string ########## extensions-core/simple-client-sslcontext/src/test/java/org/apache/druid/https/SSLContextProviderTest.java: ########## @@ -0,0 +1,97 @@ +/* + * 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.https; + +import org.apache.druid.server.security.TLSCertificateChecker; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.net.ssl.SSLContext; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +@ExtendWith(MockitoExtension.class) +public class SSLContextProviderTest +{ + @Mock + private SSLClientConfig mockConfig; Review Comment: Why not create a concrete object instead of using a mock? ########## extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQTaskListTest.java: ########## @@ -0,0 +1,102 @@ +/* + * 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.msq.indexing; + +import com.fasterxml.jackson.databind.ObjectMapper; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.function.Executable; +import java.util.Arrays; +import java.util.List; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; + +public class MSQTaskListTest +{ + @Test + public void testGetTaskIds() + { + List<String> taskIds = Arrays.asList("task1", "task2", "task3"); + MSQTaskList msqTaskList = new MSQTaskList(taskIds); + assertEquals(taskIds, msqTaskList.getTaskIds()); + } + + @Test + public void testConstructorWithNullTaskIds() + { + Executable executable = () -> new MSQTaskList(null); + assertThrows(NullPointerException.class, executable); + } + + @Test + public void testEquals() + { + List<String> taskIds1 = Arrays.asList("task1", "task2"); + List<String> taskIds2 = Arrays.asList("task1", "task2"); + MSQTaskList msqTaskList1 = new MSQTaskList(taskIds1); + MSQTaskList msqTaskList2 = new MSQTaskList(taskIds2); + assertEquals(msqTaskList1, msqTaskList2); + assertTrue(msqTaskList1.equals(msqTaskList1)); + assertFalse(msqTaskList1.equals(null)); + } + + @Test + public void testNotEquals() + { + List<String> taskIds1 = Arrays.asList("task1", "task2"); + List<String> taskIds2 = Arrays.asList("task3", "task4"); + MSQTaskList msqTaskList1 = new MSQTaskList(taskIds1); + MSQTaskList msqTaskList2 = new MSQTaskList(taskIds2); + assertNotEquals(msqTaskList1, msqTaskList2); + assertFalse(msqTaskList1.equals(msqTaskList2)); + assertFalse(msqTaskList1.equals(new Object())); + } + + @Test + public void testHashCode() + { + List<String> taskIds1 = Arrays.asList("task1", "task2"); + MSQTaskList msqTaskList1 = new MSQTaskList(taskIds1); + MSQTaskList msqTaskList2 = new MSQTaskList(taskIds1); + assertEquals(msqTaskList1.hashCode(), msqTaskList2.hashCode()); + } + + @Test + public void testToString() Review Comment: Probably not needed. ########## extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQTuningConfigTest.java: ########## @@ -76,4 +77,39 @@ public void testEquals() .usingGetClass() .verify(); } + + @Test + public void testDefaultValuesForElements() + { + MSQTuningConfig msqTuningConfig = new MSQTuningConfig(null, null, null, null, null); + Assert.assertEquals(1, msqTuningConfig.getMaxNumWorkers()); + Assert.assertEquals(100000, msqTuningConfig.getMaxRowsInMemory()); + Assert.assertEquals(PartitionsSpec.DEFAULT_MAX_ROWS_PER_SEGMENT, msqTuningConfig.getRowsPerSegment()); + Assert.assertEquals(null, msqTuningConfig.getMaxNumSegments()); + Assert.assertEquals(IndexSpec.DEFAULT, msqTuningConfig.getIndexSpec()); + } + + @Test + public void testCustomValuesForElements() + { + MSQTuningConfig msqTuningConfig = new MSQTuningConfig(5, 200000, 5000, 10, IndexSpec.builder().build()); + Assert.assertEquals(5, msqTuningConfig.getMaxNumWorkers()); + Assert.assertEquals(200000, msqTuningConfig.getMaxRowsInMemory()); + Assert.assertEquals(5000, msqTuningConfig.getRowsPerSegment()); + Assert.assertEquals(Integer.valueOf(10), msqTuningConfig.getMaxNumSegments()); + Assert.assertEquals(IndexSpec.builder().build(), msqTuningConfig.getIndexSpec()); + } + + @Test + public void testToString() Review Comment: Do we really need to test the `toString` method? AFAICT, the `toString` of this class is used only for debug logging. -- 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: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
