-
Notifications
You must be signed in to change notification settings - Fork 3.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Code Coverage additions for Extensions #17596
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
{ | ||
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); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import nl.jqno.equalsverifier.EqualsVerifier; | ||
import org.apache.druid.indexer.partitions.PartitionsSpec; | ||
import org.apache.druid.segment.IndexSpec; | ||
import org.apache.druid.segment.TestHelper; | ||
import org.apache.druid.segment.column.StringEncodingStrategy; | ||
|
@@ -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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we really need to test the |
||
{ | ||
MSQTuningConfig msqTuningConfig = new MSQTuningConfig(1, 100000, 5000, 10, IndexSpec.builder().build()); | ||
String toStringResult = msqTuningConfig.toString(); | ||
Assert.assertNotNull(toStringResult); | ||
Assert.assertTrue(toStringResult.contains("maxNumWorkers=1")); | ||
Assert.assertTrue(toStringResult.contains("maxRowsInMemory=100000")); | ||
Assert.assertTrue(toStringResult.contains("rowsPerSegment=5000")); | ||
Assert.assertTrue(toStringResult.contains("maxNumSegments=10")); | ||
Assert.assertTrue(toStringResult.contains("indexSpec=IndexSpec{bitmapSerdeFactory=RoaringBitmapSerdeFactory{}, dimensionCompression=lz4, stringDictionaryEncoding=Utf8{}, metricCompression=lz4, longEncoding=longs, complexMetricCompression=null, jsonCompression=null, segmentLoader=null}")); | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please don't use reflection for this.
|
||
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); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not needed.