Fixed wrong merging

This commit is contained in:
Marcin Grzejszczak
2016-01-14 14:20:56 +01:00
parent 779b32b363
commit bf191d7cba
6 changed files with 44 additions and 82 deletions

View File

@@ -15,8 +15,9 @@
*/
package integration;
import com.github.kristofa.brave.LoggingSpanCollector;
import com.twitter.zipkin.gen.Span;
import io.zipkin.Span;
import lombok.extern.apachecommons.CommonsLog;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import java.util.Collections;
import java.util.LinkedList;
@@ -27,13 +28,14 @@ import java.util.List;
*
* @author Marcin Grzejszczak
*/
public class IntegrationTestSpanCollector extends LoggingSpanCollector {
@CommonsLog
public class IntegrationTestZipkinSpanReporter implements ZipkinSpanReporter {
public List<Span> hashedSpans = Collections.<Span>synchronizedList(new LinkedList<Span>());
public List<Span> hashedSpans = Collections.synchronizedList(new LinkedList<>());
@Override
public void collect(Span span) {
super.collect(span);
public void report(Span span) {
log.info(span);
hashedSpans.add(span);
}

View File

@@ -15,31 +15,26 @@
*/
package integration;
import static org.assertj.core.api.BDDAssertions.then;
import java.util.Collection;
import integration.MessagingApplicationTests.IntegrationSpanCollectorConfig;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.JdkIdGenerator;
import org.springframework.util.StringUtils;
import com.github.kristofa.brave.SpanCollector;
import com.twitter.zipkin.gen.BinaryAnnotation;
import com.twitter.zipkin.gen.Span;
import integration.MessagingApplicationTests.IntegrationSpanCollectorConfig;
import sample.SampleMessagingApplication;
import tools.AbstractIntegrationTest;
import java.util.Collection;
import static org.assertj.core.api.BDDAssertions.then;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { IntegrationSpanCollectorConfig.class, SampleMessagingApplication.class })
@WebIntegrationTest
@@ -48,7 +43,7 @@ public class MessagingApplicationTests extends AbstractIntegrationTest {
private static int port = 3381;
private static String sampleAppUrl = "http://localhost:" + port;
@Autowired IntegrationTestSpanCollector integrationTestSpanCollector;
@Autowired IntegrationTestZipkinSpanReporter integrationTestSpanCollector;
@After
public void cleanup() {
@@ -79,21 +74,21 @@ public class MessagingApplicationTests extends AbstractIntegrationTest {
}
private void thenThereIsAtLeastOneBinaryAnnotationWithKey(String binaryAnnotationKey) {
then(reporter.hashedSpans.stream()
then(integrationTestSpanCollector.hashedSpans.stream()
.map(s -> s.binaryAnnotations)
.flatMap(Collection::stream)
.anyMatch(b -> b.key.equals(binaryAnnotationKey))).isTrue();
}
private void thenAllSpansHaveTraceIdEqualTo(String traceId) {
then(this.integrationTestSpanCollector.hashedSpans.stream().allMatch(span -> span.getTrace_id() == zipkinHashedTraceId(traceId))).isTrue();
then(integrationTestSpanCollector.hashedSpans.stream().allMatch(span -> span.traceId == zipkinHashedTraceId(traceId))).isTrue();
}
@Configuration
public static class IntegrationSpanCollectorConfig {
@Bean
SpanCollector integrationTestSpanCollector() {
return new IntegrationTestSpanCollector();
ZipkinSpanReporter integrationTestZipkinSpanReporter() {
return new IntegrationTestZipkinSpanReporter();
}
}

View File

@@ -86,6 +86,11 @@
<groupId>io.zipkin</groupId>
<artifactId>zipkin-java-server</artifactId>
</dependency>
<dependency>
<groupId>com.github.kristofa</groupId>
<artifactId>brave-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>

View File

@@ -16,24 +16,25 @@
package sample;
import io.zipkin.Span;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.cloud.sleuth.Sampler;
import org.springframework.cloud.sleuth.sampler.AlwaysSampler;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
import org.springframework.scheduling.annotation.EnableAsync;
import com.github.kristofa.brave.LoggingSpanCollector;
import com.github.kristofa.brave.SpanCollector;
/**
* @author Spencer Gibb
*/
@SpringBootApplication
@EnableAspectJAutoProxy(proxyTargetClass = true)
@EnableAsync
@Slf4j
public class SampleZipkinApplication {
public static final String CLIENT_NAME = "testApp";
@@ -50,8 +51,13 @@ public class SampleZipkinApplication {
// Use this for debugging (or if there is no Zipkin server running on port 9411)
@Bean
@ConditionalOnProperty(value="sample.zipkin.enabled", havingValue="false")
public SpanCollector spanCollector() {
return new LoggingSpanCollector();
public ZipkinSpanReporter spanCollector() {
return new ZipkinSpanReporter() {
@Override
public void report(Span span) {
log.info("Reporting span [{}]", span);
}
};
}
}

View File

@@ -1,40 +0,0 @@
/*
* Copyright 2013-2015 the original author or authors.
*
* Licensed 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 integration;
import com.github.kristofa.brave.LoggingSpanCollector;
import com.twitter.zipkin.gen.Span;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
/**
* Span Collector that logs spans and adds Spans to a list
*
* @author Marcin Grzejszczak
*/
public class IntegrationTestSpanCollector extends LoggingSpanCollector {
public List<Span> hashedSpans = Collections.<Span>synchronizedList(new LinkedList<Span>());
@Override
public void collect(Span span) {
super.collect(span);
hashedSpans.add(span);
}
}

View File

@@ -15,27 +15,23 @@
*/
package integration;
import integration.ZipkinTests.WaitUntilZipkinIsUpConfig;
import io.zipkin.server.ZipkinServer;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.cloud.sleuth.zipkin.HttpZipkinSpanReporter;
import org.springframework.cloud.sleuth.zipkin.ZipkinProperties;
import org.springframework.cloud.sleuth.zipkin.ZipkinSpanReporter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.JdkIdGenerator;
import com.github.kristofa.brave.EmptySpanCollectorMetricsHandler;
import com.github.kristofa.brave.HttpSpanCollector;
import com.github.kristofa.brave.SpanCollector;
import com.github.kristofa.brave.SpanCollectorMetricsHandler;
import integration.ZipkinTests.WaitUntilZipkinIsUpConfig;
import io.zipkin.server.ZipkinServer;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import sample.SampleZipkinApplication;
import tools.AbstractIntegrationTest;
@@ -77,7 +73,7 @@ public class ZipkinTests extends AbstractIntegrationTest {
public static class WaitUntilZipkinIsUpConfig {
@Bean
@SneakyThrows
public SpanCollector spanCollector(final ZipkinProperties zipkin) {
public ZipkinSpanReporter spanCollector(final ZipkinProperties zipkin) {
await().until(new Runnable() {
@Override
public void run() {
@@ -94,11 +90,9 @@ public class ZipkinTests extends AbstractIntegrationTest {
return getSpanCollector(zipkin);
}
private SpanCollector getSpanCollector(ZipkinProperties zipkin) {
private ZipkinSpanReporter getSpanCollector(ZipkinProperties zipkin) {
String url = "http://localhost:" + zipkin.getPort();
// TODO: parameterize this
SpanCollectorMetricsHandler metrics = new EmptySpanCollectorMetricsHandler();
return HttpSpanCollector.create(url, zipkin.getHttpConfig(), metrics);
return new HttpZipkinSpanReporter(url, zipkin.getFlushInterval());
}
}
}