Further simplify integration tests for zipkin-stream

It's not really necessary to use rabbit, but the existing tests
weren't really using the stream components at all because
zipkin spans were being collected by spring-cloud-sleuth-zipkin.
This commit is contained in:
Dave Syer
2016-01-13 13:22:46 +00:00
parent 5580064fbc
commit 687ef45e6d
11 changed files with 168 additions and 140 deletions

View File

@@ -1,49 +0,0 @@
package integration;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.amqp.RabbitAutoConfiguration;
import org.springframework.cloud.sleuth.TraceManager;
import org.springframework.cloud.sleuth.trace.TraceContextHolder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Random;
/**
* @author Marcin Grzejszczak
*/
@RestController
@Slf4j
public class SampleApp {
@Autowired
private TraceManager traceManager;
@SneakyThrows
@RequestMapping("/hi2")
public String hi2() {
log.info("I'm in the sample app");
final Random random = new Random();
int millis = random.nextInt(1000);
Thread.sleep(millis);
this.traceManager.addAnnotation("random-sleep-millis", String.valueOf(millis));
log.info("Current span is [{}]", TraceContextHolder.getCurrentSpan());
return "hi2";
}
@Configuration
@EnableAutoConfiguration(exclude = RabbitAutoConfiguration.class)
@Slf4j
public static class Config {
@Bean SampleApp sampleApp() {
return new SampleApp();
}
}
}

View File

@@ -15,41 +15,71 @@
*/
package integration;
import example.ZipkinStreamServerApplication;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import java.util.Arrays;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.boot.test.WebIntegrationTest;
import org.springframework.cloud.sleuth.MilliSpan;
import org.springframework.cloud.sleuth.Span;
import org.springframework.cloud.sleuth.stream.Host;
import org.springframework.cloud.sleuth.stream.SleuthSink;
import org.springframework.cloud.sleuth.stream.Spans;
import org.springframework.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.messaging.MessageChannel;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.JdkIdGenerator;
import example.ZipkinStreamServerApplication;
import lombok.SneakyThrows;
import tools.AbstractIntegrationTest;
@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = { SampleApp.Config.class,
AbstractIntegrationTest.WaitUntilZipkinIsUpConfig.class,
TestSupportBinderAutoConfiguration.class,
@SpringApplicationConfiguration(classes = { TestSupportBinderAutoConfiguration.class,
ZipkinStreamServerApplication.class })
@WebIntegrationTest
@Slf4j
@WebIntegrationTest({ "server.port=0", "management.health.rabbit.enabled=false" })
@ActiveProfiles("test")
public class ZipkinStreamTests extends AbstractIntegrationTest {
private static int port = 9411;
private static String sampleAppUrl = "http://localhost:" + port;
@Value("${local.server.port}")
private int zipkinServerPort = 9411;
@Autowired
@Qualifier(SleuthSink.INPUT)
private MessageChannel input;
@Test
@SneakyThrows
public void should_propagate_spans_to_zipkin() {
await().until(zipkinServerIsUp());
String traceId = new JdkIdGenerator().generateId().toString();
await().until(httpMessageWithTraceIdInHeadersIsSuccessfullySent(sampleAppUrl + "/hi2", traceId));
await().until(zipkinServerIsUp());
String traceId = new JdkIdGenerator().generateId().toString();
Span span = MilliSpan.builder().traceId(traceId).spanId(traceId).name("test")
.build();
span.tag(getRequiredBinaryAnnotationName(), "10131");
this.input.send(MessageBuilder.withPayload(
new Spans(new Host(getAppName(), "127.0.0.1", 8080), Arrays.asList(span)))
.build());
await().until(allSpansWereRegisteredInZipkinWithTraceIdEqualTo(traceId));
}
@Override
protected int getZipkinServerPort() {
return this.zipkinServerPort;
}
@Override
protected String getAppName() {
return "local";
}
}