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
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,71 @@ public void testEmitterConfigWithBadExtraLabels()
Assert.assertTrue(actualMessage.contains(expectedMessage));
}

@Test
public void testDefaultConstructor()
{
PrometheusEmitterConfig config = new PrometheusEmitterConfig(null, null, null, null, null, false, false, null, null, null, null);
Assert.assertEquals(PrometheusEmitterConfig.Strategy.exporter, config.getStrategy());
Assert.assertEquals("druid", config.getNamespace());
Assert.assertNull(config.getDimensionMapPath());
}

@Test
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());

Assert.assertThrows(IllegalArgumentException.class, () -> {
new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.exporter, null, null, null, null, false, false, null, null, null, null);
});
}

@Test
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.assertEquals(Integer.valueOf(30), config.getFlushPeriod());
Assert.assertFalse(config.isAddHostAsLabel());

Assert.assertThrows(IllegalArgumentException.class, () -> {
new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, null, null, null, null, false, false, null, null, null, null);
});
}

@Test
public void testInvalidFlushPeriod()
{
IllegalArgumentException illegalArgumentException = Assert.assertThrows(IllegalArgumentException.class, () -> {
new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, null, null, null, "localhost:9091", false, false, 0, null, null, null);
});
Assert.assertTrue(illegalArgumentException.getMessage().equals("flushPeriod must be greater than 0."));
}

@Test
public void testInvalidExtraLabelName()
{
DruidException druidException = 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);
});
Assert.assertTrue(druidException.getMessage().equals("Invalid metric label name [invalid label]. Label names must conform to the pattern [[a-zA-Z_:][a-zA-Z0-9_:]*]."));
}

@Test
public void testNegativeWaitForShutdownDelay()
{
DruidException druidException = Assert.assertThrows(DruidException.class, () -> {
new PrometheusEmitterConfig(null, null, null, null, null, false, false, null, null, null, -1L);
});
Assert.assertTrue(druidException.getMessage().equals("Invalid value for waitForShutdownDelay[-1] specified, waitForShutdownDelay must be >= 0."));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.google.common.collect.ImmutableMap;
import io.prometheus.client.Collector;
import io.prometheus.client.CollectorRegistry;
import io.prometheus.client.exporter.HTTPServer;
import io.prometheus.client.exporter.PushGateway;
import org.apache.druid.java.util.emitter.core.Emitter;
import org.apache.druid.java.util.emitter.service.ServiceMetricEvent;
Expand Down Expand Up @@ -229,11 +230,15 @@ public void testEmitterStart()
PrometheusEmitter exportEmitter = new PrometheusEmitter(exportEmitterConfig);
exportEmitter.start();
Assert.assertNotNull(exportEmitter.getServer());
Assert.assertTrue(exportEmitter.getServer() instanceof HTTPServer);
exportEmitter.close();

PrometheusEmitterConfig pushEmitterConfig = new PrometheusEmitterConfig(PrometheusEmitterConfig.Strategy.pushgateway, "namespace2", null, 0, "pushgateway", true, true, 60, null, false, null);
PrometheusEmitter pushEmitter = new PrometheusEmitter(pushEmitterConfig);
pushEmitter.start();
Assert.assertNotNull(pushEmitter.getPushGateway());
Assert.assertTrue(pushEmitter.getPushGateway() instanceof PushGateway);
pushEmitter.close();
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* 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 nl.jqno.equalsverifier.EqualsVerifier;
import org.junit.jupiter.api.Test;
import java.util.Arrays;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MSQTaskListTest
{
@Test
public void testEqualsAndHashCode()
{
EqualsVerifier.simple()
.forClass(MSQTaskList.class)
.usingGetClass()
.withNonnullFields("taskIds")
.verify();
}

@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
Expand Up @@ -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;
Expand Down Expand Up @@ -76,4 +77,26 @@ 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());
}
}
Loading