-
Notifications
You must be signed in to change notification settings - Fork 97
/
TraceRequestResponseTest.java
78 lines (64 loc) · 2.24 KB
/
TraceRequestResponseTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/*
* Copyright 2016 Palantir Technologies, Inc. All rights reserved.
*/
package com.palantir.remoting.http;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import com.google.common.base.Optional;
import com.palantir.remoting.http.server.TraceEnrichingFilter;
import com.palantir.tracing.TraceState;
import com.palantir.tracing.Traces;
import io.dropwizard.Application;
import io.dropwizard.Configuration;
import io.dropwizard.setup.Environment;
import io.dropwizard.testing.junit.DropwizardAppRule;
import javax.net.ssl.SSLSocketFactory;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.Test;
public final class TraceRequestResponseTest {
@ClassRule
public static final DropwizardAppRule<Configuration> APP = new DropwizardAppRule<>(TracingTestServer.class,
"src/test/resources/test-server.yml");
private TracingTestService service;
@Before
public void before() {
String endpointUri = "http://localhost:" + APP.getLocalPort();
service = FeignClients.standard().createProxy(
Optional.<SSLSocketFactory>absent(),
endpointUri,
TracingTestService.class);
}
@Test
public void testTraceResponseDecoder_decoderPopsMatchingSpan() {
Optional<TraceState> before = Traces.getTrace();
service.get();
assertThat(Traces.getTrace(), is(before));
}
public static class TracingTestServer extends Application<Configuration> {
@Override
public final void run(Configuration config, final Environment env) throws Exception {
env.jersey().register(new TraceEnrichingFilter());
env.jersey().register(new TracingTestResource());
}
}
public static final class TracingTestResource implements TracingTestService {
@Override
public Object get() {
return "{}";
}
}
@Path("/")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public interface TracingTestService {
@GET
@Path("/trace")
Object get();
}
}