Skip to content
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

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

ashwintumma23
Copy link
Contributor

@ashwintumma23 ashwintumma23 commented Dec 30, 2024

Description

  • Contributes to code coverage for a few class in the extensions-core and extensions-contrib directories

Release note


Key changed/added classes in this PR
  • Prometheus Emitter
    • extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/PrometheusEmitterConfigTest.java
    • extensions-contrib/prometheus-emitter/src/test/java/org/apache/druid/emitter/prometheus/PrometheusEmitterTest.java
  • Multi-Stage Query
    • New: extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQTaskListTest.java
    • extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/indexing/MSQTuningConfigTest.java
  • Simple Client SSLContext
    • New: extensions-core/simple-client-sslcontext/pom.xml
    • New: extensions-core/simple-client-sslcontext/src/test/java/org/apache/druid/https/SSLClientConfigTest.java

This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

@github-actions github-actions bot added Area - Batch Ingestion Area - Metrics/Event Emitting Area - Dependencies Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262 labels Dec 30, 2024
Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left some suggestions.

@ashwintumma23 ashwintumma23 force-pushed the codeCoverageExtensions branch from af7daca to 84435fb Compare January 13, 2025 20:54
Copy link
Contributor

@kfaraz kfaraz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for contributing to Druid, @ashwintumma23 !

I have left some suggestions. Let me know what you think.

As a general principle, while verifying getters, equals and hashCode of POJOs does help with code coverage, it doesn't always add a lot of value by itself. Moreover, these code paths tend to get covered anyway through functional tests where these POJOs are used.

So, I would advise focusing more on functionality when writing future tests.
I look forward to more contributions from you 🙂 .

public class SSLClientConfigTest
{
@Test
public void testGetters()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test serves any purpose.
The test is verifying values which the test had itself configured the mock object to return.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Removing the tests in the next commit.

Comment on lines 80 to 98
public void testPushgatewayStrategy()
{
PrometheusEmitterConfig config = new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, "druid", null, null, "localhost:9091", false, false, 30, null, true, 5000L);
Assert.assertEquals(PrometheusEmitterConfig.Strategy.pushgateway, config.getStrategy());
Assert.assertEquals("druid", config.getNamespace());
Assert.assertEquals("localhost:9091", config.getPushGatewayAddress());
Assert.assertFalse(config.isAddHostAsLabel());
}

@Test
public void testPushGatewayStrategyWithoutAddress()
{
Assert.assertThrows(IllegalArgumentException.class, () -> {
new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, null, null, null, null, false, false, null, null, null, null);
});
}

@Test
public void testDefaultFlushPeriodForPushgateway()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 can be merged into a single test. They don't seem to add a lot of value by themselves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. Combined the three tests into one test for PushGatewayStrategy. Pushing in the next commit.

Comment on lines 105 to 123
public void testInvalidFlushPeriod()
{
Assert.assertThrows(IllegalArgumentException.class, () -> {
new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, null, null, null, "localhost:9091", false, false, 0, null, null, null);
});
}

@Test
public void testInvalidExtraLabelName()
{
Assert.assertThrows(DruidException.class, () -> {
Map<String, String> extraLabels = new HashMap<>();
extraLabels.put("invalid label", "value");
new PrometheusEmitterConfig(null, null, null, null, null, false, false, null, extraLabels, null, null);
});
}

@Test
public void testNegativeWaitForShutdownDelay()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the invalid cases, maybe try to verify the exception message as well. You may use AssertionMatcher or DruidExceptionMatcher etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, verified the exception message as well. Pushed in the commit.

Comment on lines 35 to 48
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);
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These two tests don't add much value.

Copy link
Contributor Author

@ashwintumma23 ashwintumma23 Jan 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Removing the tests in the next commit.

Comment on lines 61 to 77
public void testExporterStrategy()
{
PrometheusEmitterConfig config = new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.exporter, "druid", null, 8080, null, true, true, null, null, null, null);
Assert.assertEquals(PrometheusEmitterConfig.Strategy.exporter, config.getStrategy());
Assert.assertEquals("druid", config.getNamespace());
Assert.assertEquals(8080, config.getPort());
Assert.assertTrue(config.isAddHostAsLabel());
Assert.assertTrue(config.isAddHostAsLabel());
}

@Test
public void testExporterStrategyWithoutPort()
{
Assert.assertThrows(IllegalArgumentException.class, () -> {
new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.exporter, null, null, null, null, false, false, null, null, null, null);
});
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also combined these two tests into one, so that both ExporterStrategy and PushGatewayStrategy will have one test each.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area - Batch Ingestion Area - Dependencies Area - Metrics/Event Emitting Area - MSQ For multi stage queries - https://github.com/apache/druid/issues/12262
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants