-
Notifications
You must be signed in to change notification settings - Fork 3.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Code Coverage additions for Extensions
- Loading branch information
Ashwin Tumma
committed
Dec 30, 2024
1 parent
b79382f
commit 55ee5d7
Showing
9 changed files
with
428 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...s-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQTaskListTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* 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 org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.function.Executable; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
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() | ||
{ | ||
List<String> taskIds = Arrays.asList("task1", "task2"); | ||
MSQTaskList msqTaskList = new MSQTaskList(taskIds); | ||
assertEquals("MSQTaskList{taskIds=[task1, task2]}", msqTaskList.toString()); | ||
} | ||
|
||
@Test | ||
public void testJsonSerialization() throws Exception | ||
{ | ||
List<String> taskIds = Arrays.asList("task1", "task2"); | ||
MSQTaskList msqTaskList = new MSQTaskList(taskIds); | ||
ObjectMapper mapper = new ObjectMapper(); | ||
String json = mapper.writeValueAsString(msqTaskList); | ||
MSQTaskList deserialized = mapper.readValue(json, MSQTaskList.class); | ||
assertEquals(msqTaskList, deserialized); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
...re/simple-client-sslcontext/src/test/java/org/apache/druid/https/SSLClientConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
setField(sslClientConfig, "protocol", expectedProtocol); | ||
setField(sslClientConfig, "trustStoreType", expectedTrustStoreType); | ||
setField(sslClientConfig, "trustStorePath", expectedTrustStorePath); | ||
setField(sslClientConfig, "trustStoreAlgorithm", expectedTrustStoreAlgorithm); | ||
setField(sslClientConfig, "trustStorePasswordProvider", expectedTrustStorePasswordProvider); | ||
setField(sslClientConfig, "keyStorePath", expectedKeyStorePath); | ||
setField(sslClientConfig, "keyStoreType", expectedKeyStoreType); | ||
setField(sslClientConfig, "certAlias", expectedCertAlias); | ||
setField(sslClientConfig, "keyStorePasswordProvider", expectedKeyStorePasswordProvider); | ||
setField(sslClientConfig, "keyManagerPasswordProvider", expectedKeyManagerPasswordProvider); | ||
setField(sslClientConfig, "keyManagerFactoryAlgorithm", expectedKeyManagerFactoryAlgorithm); | ||
setField(sslClientConfig, "validateHostnames", expectedValidateHostnames); | ||
|
||
assertEquals(expectedProtocol, sslClientConfig.getProtocol()); | ||
assertEquals(expectedTrustStoreType, sslClientConfig.getTrustStoreType()); | ||
assertEquals(expectedProtocol, sslClientConfig.getProtocol()); | ||
assertEquals(expectedTrustStoreType, sslClientConfig.getTrustStoreType()); | ||
assertEquals(expectedTrustStorePath, sslClientConfig.getTrustStorePath()); | ||
assertEquals(expectedTrustStoreAlgorithm, sslClientConfig.getTrustStoreAlgorithm()); | ||
assertEquals(expectedTrustStorePasswordProvider, sslClientConfig.getTrustStorePasswordProvider()); | ||
assertEquals(expectedKeyStorePath, sslClientConfig.getKeyStorePath()); | ||
assertEquals(expectedKeyStoreType, sslClientConfig.getKeyStoreType()); | ||
assertEquals(expectedCertAlias, sslClientConfig.getCertAlias()); | ||
assertEquals(expectedKeyStorePasswordProvider, sslClientConfig.getKeyStorePasswordProvider()); | ||
assertEquals(expectedKeyManagerPasswordProvider, sslClientConfig.getKeyManagerPasswordProvider()); | ||
assertEquals(expectedKeyManagerFactoryAlgorithm, sslClientConfig.getKeyManagerFactoryAlgorithm()); | ||
assertEquals(expectedValidateHostnames, sslClientConfig.getValidateHostnames()); | ||
assertEquals("SSLClientConfig{protocol='TLS', trustStoreType='JKS', trustStorePath='/path/to/truststore', trustStoreAlgorithm='SunX509', keyStorePath='/path/to/keystore', keyStoreType='JKS', certAlias='alias', keyManagerFactoryAlgorithm='SunX509', validateHostnames='true'}", sslClientConfig.toString()); | ||
} | ||
|
||
private void setField(Object object, String fieldName, Object value) throws NoSuchFieldException, IllegalAccessException | ||
{ | ||
Field field = object.getClass().getDeclaredField(fieldName); | ||
field.setAccessible(true); | ||
field.set(object, value); | ||
} | ||
} |
Oops, something went wrong.