You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flink.apache.org by ch...@apache.org on 2018/02/20 15:48:51 UTC
[3/4] flink git commit: [hotfix][prometheus][tests] Add utility for
generating port ranges
[hotfix][prometheus][tests] Add utility for generating port ranges
Project: http://git-wip-us.apache.org/repos/asf/flink/repo
Commit: http://git-wip-us.apache.org/repos/asf/flink/commit/527faf63
Tree: http://git-wip-us.apache.org/repos/asf/flink/tree/527faf63
Diff: http://git-wip-us.apache.org/repos/asf/flink/diff/527faf63
Branch: refs/heads/release-1.4
Commit: 527faf63e21eaeedd3ab471ec7d2556985422734
Parents: d88f43b
Author: zentol <ch...@apache.org>
Authored: Tue Feb 13 10:33:31 2018 +0100
Committer: zentol <ch...@apache.org>
Committed: Tue Feb 20 16:48:42 2018 +0100
----------------------------------------------------------------------
.../prometheus/PrometheusReporterTest.java | 41 ++++++++++++++++++--
1 file changed, 37 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flink/blob/527faf63/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
----------------------------------------------------------------------
diff --git a/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java b/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
index 1a70865..8b4d286 100644
--- a/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
+++ b/flink-metrics/flink-metrics-prometheus/src/test/java/org/apache/flink/metrics/prometheus/PrometheusReporterTest.java
@@ -45,6 +45,8 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import java.util.Arrays;
+import java.util.Iterator;
+import java.util.NoSuchElementException;
import static org.apache.flink.metrics.prometheus.PrometheusReporter.ARG_PORT;
import static org.hamcrest.Matchers.containsString;
@@ -66,6 +68,8 @@ public class PrometheusReporterTest extends TestLogger {
private static final String DEFAULT_LABELS = "{" + DIMENSIONS + ",}";
private static final String SCOPE_PREFIX = "flink_taskmanager_";
+ private static final PortRangeProvider portRangeProvider = new PortRangeProvider();
+
@Rule
public ExpectedException thrown = ExpectedException.none();
@@ -75,7 +79,7 @@ public class PrometheusReporterTest extends TestLogger {
@Before
public void setupReporter() {
- registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", "9400-9500")));
+ registry = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", portRangeProvider.next())));
metricGroup = new FrontMetricGroup<>(0, new TaskManagerMetricGroup(registry, HOST_NAME, TASK_MANAGER));
reporter = (PrometheusReporter) registry.getReporters().get(0);
}
@@ -235,7 +239,7 @@ public class PrometheusReporterTest extends TestLogger {
@Test
public void cannotStartTwoReportersOnSamePort() {
- final MetricRegistryImpl fixedPort1 = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", "9400-9500")));
+ final MetricRegistryImpl fixedPort1 = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", portRangeProvider.next())));
assertThat(fixedPort1.getReporters(), hasSize(1));
PrometheusReporter firstReporter = (PrometheusReporter) fixedPort1.getReporters().get(0);
@@ -249,8 +253,9 @@ public class PrometheusReporterTest extends TestLogger {
@Test
public void canStartTwoReportersWhenUsingPortRange() {
- final MetricRegistryImpl portRange1 = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", "9200-9300")));
- final MetricRegistryImpl portRange2 = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test2", "9200-9300")));
+ String portRange = portRangeProvider.next();
+ final MetricRegistryImpl portRange1 = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test1", portRange)));
+ final MetricRegistryImpl portRange2 = new MetricRegistryImpl(MetricRegistryConfiguration.fromConfiguration(createConfigWithOneReporter("test2", portRange)));
assertThat(portRange1.getReporters(), hasSize(1));
assertThat(portRange2.getReporters(), hasSize(1));
@@ -280,4 +285,32 @@ public class PrometheusReporterTest extends TestLogger {
public void closeReporterAndShutdownRegistry() {
registry.shutdown();
}
+
+ /**
+ * Utility class providing distinct port ranges.
+ */
+ private static class PortRangeProvider implements Iterator<String> {
+
+ private int base = 9000;
+
+ @Override
+ public boolean hasNext() {
+ return base < 14000; // arbitrary limit that should be sufficient for test purposes
+ }
+
+ /**
+ * Returns the next port range containing exactly 100 ports.
+ *
+ * @return next port range
+ */
+ public String next() {
+ if (!hasNext()) {
+ throw new NoSuchElementException();
+ }
+ int lowEnd = base;
+ int highEnd = base + 99;
+ base += 100;
+ return String.valueOf(lowEnd) + "-" + String.valueOf(highEnd);
+ }
+ }
}