zipkin-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From adrianc...@apache.org
Subject [incubator-zipkin] 02/04: Saves time by quarantining only the dirtiest tests
Date Mon, 06 May 2019 13:18:34 GMT
This is an automated email from the ASF dual-hosted git repository.

adriancole pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-zipkin.git

commit 4f0978b8649d052136bc3f1448b9054be6256f8e
Author: Adrian Cole <acole@pivotal.io>
AuthorDate: Mon May 6 17:36:38 2019 +0800

    Saves time by quarantining only the dirtiest tests
---
 .../server/internal/ITZipkinMetricsHealth.java     |  47 --------
 .../internal/ITZipkinMetricsHealthDirty.java       | 131 +++++++++++++++++++++
 2 files changed, 131 insertions(+), 47 deletions(-)

diff --git a/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinMetricsHealth.java
b/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinMetricsHealth.java
index bd060b0..ab92295 100644
--- a/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinMetricsHealth.java
+++ b/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinMetricsHealth.java
@@ -33,7 +33,6 @@ import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.test.context.SpringBootTest;
-import org.springframework.test.annotation.DirtiesContext;
 import org.springframework.test.context.junit4.SpringRunner;
 import zipkin.server.ZipkinServer;
 import zipkin2.Span;
@@ -42,7 +41,6 @@ import zipkin2.storage.InMemoryStorage;
 
 import static java.util.Arrays.asList;
 import static org.assertj.core.api.Assertions.assertThat;
-import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD;
 import static zipkin2.TestObjects.LOTS_OF_SPANS;
 import static zipkin2.server.internal.ITZipkinServer.url;
 
@@ -52,7 +50,6 @@ import static zipkin2.server.internal.ITZipkinServer.url;
   properties = "spring.config.name=zipkin-server"
 )
 @RunWith(SpringRunner.class)
-@DirtiesContext(classMode = BEFORE_EACH_TEST_METHOD)
 public class ITZipkinMetricsHealth {
 
   @Autowired InMemoryStorage storage;
@@ -177,46 +174,6 @@ public class ITZipkinMetricsHealth {
           + httpCount);
   }
 
-  @Test public void writeSpans_updatesMetrics() throws Exception {
-    List<Span> spans = asList(LOTS_OF_SPANS[0], LOTS_OF_SPANS[1], LOTS_OF_SPANS[2]);
-    byte[] body = SpanBytesEncoder.JSON_V2.encodeList(spans);
-    double messagesCount =
-      registry.counter("zipkin_collector.messages", "transport", "http").count();
-    double bytesCount = registry.counter("zipkin_collector.bytes", "transport", "http").count();
-    double spansCount = registry.counter("zipkin_collector.spans", "transport", "http").count();
-    post("/api/v2/spans", body);
-    post("/api/v2/spans", body);
-
-    String json = getAsString("/metrics");
-
-    assertThat(readDouble(json, "$.['counter.zipkin_collector.messages.http']"))
-      .isEqualTo(messagesCount + 2.0);
-    assertThat(readDouble(json, "$.['counter.zipkin_collector.bytes.http']"))
-      .isEqualTo(bytesCount + (body.length * 2));
-    assertThat(readDouble(json, "$.['gauge.zipkin_collector.message_bytes.http']"))
-      .isEqualTo(body.length);
-    assertThat(readDouble(json, "$.['counter.zipkin_collector.spans.http']"))
-      .isEqualTo(spansCount + (spans.size() * 2));
-    assertThat(readDouble(json, "$.['gauge.zipkin_collector.message_spans.http']"))
-      .isEqualTo(spans.size());
-  }
-
-  @Test public void writeSpans_malformedUpdatesMetrics() throws Exception {
-    byte[] body = {'h', 'e', 'l', 'l', 'o'};
-    Double messagesCount =
-      registry.counter("zipkin_collector.messages", "transport", "http").count();
-    Double messagesDroppedCount =
-      registry.counter("zipkin_collector.messages_dropped", "transport", "http").count();
-    post("/api/v2/spans", body);
-
-    String json = getAsString("/metrics");
-
-    assertThat(readDouble(json, "$.['counter.zipkin_collector.messages.http']"))
-      .isEqualTo(messagesCount + 1);
-    assertThat(readDouble(json, "$.['counter.zipkin_collector.messages_dropped.http']"))
-      .isEqualTo(messagesDroppedCount + 1);
-  }
-
   @Test public void readsHealth() throws Exception {
     String json = getAsString("/health");
     assertThat(readString(json, "$.status"))
@@ -267,10 +224,6 @@ public class ITZipkinMetricsHealth {
       .build()).execute();
   }
 
-  static Double readDouble(String json, String jsonPath) {
-    return JsonPath.compile(jsonPath).read(json);
-  }
-
   static String readString(String json, String jsonPath) {
     return JsonPath.compile(jsonPath).read(json);
   }
diff --git a/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinMetricsHealthDirty.java
b/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinMetricsHealthDirty.java
new file mode 100644
index 0000000..3888342
--- /dev/null
+++ b/zipkin-server/src/test/java/zipkin2/server/internal/ITZipkinMetricsHealthDirty.java
@@ -0,0 +1,131 @@
+/*
+ * 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 zipkin2.server.internal;
+
+import com.jayway.jsonpath.JsonPath;
+import com.linecorp.armeria.server.Server;
+import io.micrometer.prometheus.PrometheusMeterRegistry;
+import java.io.IOException;
+import java.util.List;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.RequestBody;
+import okhttp3.Response;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.test.context.SpringBootTest;
+import org.springframework.test.annotation.DirtiesContext;
+import org.springframework.test.context.junit4.SpringRunner;
+import zipkin.server.ZipkinServer;
+import zipkin2.Span;
+import zipkin2.codec.SpanBytesEncoder;
+import zipkin2.storage.InMemoryStorage;
+
+import static java.util.Arrays.asList;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_EACH_TEST_METHOD;
+import static zipkin2.TestObjects.LOTS_OF_SPANS;
+import static zipkin2.server.internal.ITZipkinServer.url;
+
+/**
+ * We cannot clear the micrometer registry easily, so we have recreate the spring context.
This is
+ * extremely slow, so please only add tests that require isolation here.
+ */
+@SpringBootTest(
+  classes = ZipkinServer.class,
+  webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
+  properties = "spring.config.name=zipkin-server"
+)
+@RunWith(SpringRunner.class)
+@DirtiesContext(classMode = BEFORE_EACH_TEST_METHOD)
+public class ITZipkinMetricsHealthDirty {
+
+  @Autowired InMemoryStorage storage;
+  @Autowired PrometheusMeterRegistry registry;
+  @Autowired Server server;
+
+  OkHttpClient client = new OkHttpClient.Builder().followRedirects(true).build();
+
+  @Before public void init() {
+    storage.clear();
+  }
+
+  @Test public void writeSpans_updatesMetrics() throws Exception {
+    List<Span> spans = asList(LOTS_OF_SPANS[0], LOTS_OF_SPANS[1], LOTS_OF_SPANS[2]);
+    byte[] body = SpanBytesEncoder.JSON_V2.encodeList(spans);
+    double messagesCount =
+      registry.counter("zipkin_collector.messages", "transport", "http").count();
+    double bytesCount = registry.counter("zipkin_collector.bytes", "transport", "http").count();
+    double spansCount = registry.counter("zipkin_collector.spans", "transport", "http").count();
+    post("/api/v2/spans", body);
+    post("/api/v2/spans", body);
+
+    String json = getAsString("/metrics");
+
+    assertThat(readDouble(json, "$.['counter.zipkin_collector.messages.http']"))
+      .isEqualTo(messagesCount + 2.0);
+    assertThat(readDouble(json, "$.['counter.zipkin_collector.bytes.http']"))
+      .isEqualTo(bytesCount + (body.length * 2));
+    assertThat(readDouble(json, "$.['gauge.zipkin_collector.message_bytes.http']"))
+      .isEqualTo(body.length);
+    assertThat(readDouble(json, "$.['counter.zipkin_collector.spans.http']"))
+      .isEqualTo(spansCount + (spans.size() * 2));
+    assertThat(readDouble(json, "$.['gauge.zipkin_collector.message_spans.http']"))
+      .isEqualTo(spans.size());
+  }
+
+  @Test public void writeSpans_malformedUpdatesMetrics() throws Exception {
+    byte[] body = {'h', 'e', 'l', 'l', 'o'};
+    Double messagesCount =
+      registry.counter("zipkin_collector.messages", "transport", "http").count();
+    Double messagesDroppedCount =
+      registry.counter("zipkin_collector.messages_dropped", "transport", "http").count();
+    post("/api/v2/spans", body);
+
+    String json = getAsString("/metrics");
+
+    assertThat(readDouble(json, "$.['counter.zipkin_collector.messages.http']"))
+      .isEqualTo(messagesCount + 1);
+    assertThat(readDouble(json, "$.['counter.zipkin_collector.messages_dropped.http']"))
+      .isEqualTo(messagesDroppedCount + 1);
+  }
+
+  private String getAsString(String path) throws IOException {
+    Response response = get(path);
+    assertThat(response.isSuccessful())
+      .withFailMessage(response.toString())
+      .isTrue();
+    return response.body().string();
+  }
+
+  private Response get(String path) throws IOException {
+    return client.newCall(new Request.Builder().url(url(server, path)).build()).execute();
+  }
+
+  private Response post(String path, byte[] body) throws IOException {
+    return client.newCall(new Request.Builder()
+      .url(url(server, path))
+      .post(RequestBody.create(null, body))
+      .build()).execute();
+  }
+
+  static Double readDouble(String json, String jsonPath) {
+    return JsonPath.compile(jsonPath).read(json);
+  }
+}


Mime
View raw message