Skip to content

Commit

Permalink
Update unit tests (#12)
Browse files Browse the repository at this point in the history
updated tests
  • Loading branch information
DC2-DanielKrueger authored Dec 1, 2020
1 parent 93888f4 commit 53ca407
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;

import static com.hivemq.extensions.dns.metrics.DnsDiscoveryMetrics.DNS_DISCOVERY_EXTENSION;
import static com.hivemq.extensions.dns.metrics.DnsDiscoveryMetrics.HIVEMQ_PREFIX;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;

Expand All @@ -47,7 +49,7 @@ void setUp(final @NotNull @TempDir Path extensionTempPath) throws IOException {
testDnsServer.start();

FileUtils.copyDirectory(new File("build/hivemq-extension-test"), extensionTempPath.toFile());
final Path extensionDir = extensionTempPath.resolve("hivemq-dns-cluster-discovery-extension");
final Path extensionDir = extensionTempPath.resolve("hivemq-dns-cluster-discovery");

final String dnsConfigPath = "src/integrationTest/resources/dnsdiscovery.properties";

Expand Down Expand Up @@ -116,6 +118,11 @@ private enum MetricType {
"com_hivemq_dns_cluster_discovery_extension_query_failed_count",
"com_hivemq_dns_cluster_discovery_extension_resolved_addresses"));

final String successMetricName = HIVEMQ_PREFIX + "." + DNS_DISCOVERY_EXTENSION + "." + "query.success.count";
final String failedMetricName = HIVEMQ_PREFIX + "." + DNS_DISCOVERY_EXTENSION + "." + "query.failed.count";



if (type == MetricType.SUCCESS_METRIC) {
return metricsWithValues.get("com_hivemq_dns_cluster_discovery_extension_query_success_count");
} else if (type == MetricType.FAILURE_METRIC) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
*/
public class DnsDiscoveryMetrics {

private final static @NotNull String DNS_DISCOVERY_EXTENSION = "dns-cluster-discovery-extension";
private final static @NotNull String HIVEMQ_PREFIX = "com.hivemq";
public final static @NotNull String DNS_DISCOVERY_EXTENSION = "dns-cluster-discovery-extension";
public final static @NotNull String HIVEMQ_PREFIX = "com.hivemq";

private final @NotNull MetricRegistry metricRegistry;
private final @NotNull Counter connectCounter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import java.util.List;
import java.util.concurrent.atomic.AtomicInteger;

import static com.hivemq.extensions.dns.metrics.DnsDiscoveryMetrics.DNS_DISCOVERY_EXTENSION;
import static com.hivemq.extensions.dns.metrics.DnsDiscoveryMetrics.HIVEMQ_PREFIX;
import static org.junit.jupiter.api.Assertions.assertEquals;

class DnsDiscoveryMetricsTest {
Expand All @@ -26,21 +28,17 @@ public void before() {
public void test_resolutionRequestCounter() {
final Counter counter = metrics.getResolutionRequestCounter();
counter.inc();

final Counter counterFromRegistry = metricRegistry.counter("com.hivemq.dns-cluster-discovery-extension.resolution-request-success.count");


String name = HIVEMQ_PREFIX + "." + DNS_DISCOVERY_EXTENSION + "." + "query.success.count";
final Counter counterFromRegistry = metricRegistry.counter(name);
assertEquals(counter.getCount(), counterFromRegistry.getCount());
}

@Test
public void test_resolutionRequestCounterFailed() {
final Counter counter = metrics.getResolutionRequestFailedCounter();
counter.inc();

final Counter counterFromRegistry = metricRegistry.counter("com.hivemq.dns-cluster-discovery-extension.resolution-request-failed.count");


String name = HIVEMQ_PREFIX + "." + DNS_DISCOVERY_EXTENSION + "." + "query.failed.count";
final Counter counterFromRegistry = metricRegistry.counter(name);
assertEquals(counter.getCount(), counterFromRegistry.getCount());
}

Expand All @@ -54,7 +52,8 @@ public void test_subscribed_message_duration_histogram() {

metrics.registerAddressCountGauge(addressesCount::get);

final Gauge<Integer> gauge = metricRegistry.getGauges().get("com.hivemq.dns-cluster-discovery-extension.resolved-addresses.gauge");
String name = HIVEMQ_PREFIX + "." + DNS_DISCOVERY_EXTENSION + "." + "resolved-addresses";
final Gauge<Integer> gauge = metricRegistry.getGauges().get(name);

assertEquals(addresses.size(), gauge.getValue());

Expand Down

0 comments on commit 53ca407

Please sign in to comment.