Skip to content

Commit

Permalink
Merge pull request #56 from willarmiros/travis
Browse files Browse the repository at this point in the history
replaced travis with GH actions
  • Loading branch information
willarmiros authored Sep 1, 2020
2 parents bda6b3f + 0078bfd commit b8d6f26
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 34 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/continuous_build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Continuous Build
on: [push, pull_request]

jobs:
build:
name: Build Java ${{ matrix.java }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os:
- macos-latest
- ubuntu-latest
java:
- 8
- 11
steps:
- name: Checkout Repository
uses: actions/checkout@v1
- name: Setup java
uses: actions/setup-java@v1
with:
java-version: ${{ matrix.java }}
- name: Cache Gradle Modules
uses: actions/cache@v1
with:
path: ~/.gradle/caches
key: gradle-caches-${{ hashFiles('**/*.gradle.kts') }}
- name: Cache Gradle Wrapper
uses: actions/cache@v1
with:
path: ~/.gradle/wrapper
key: gradle-wrapper-${{ hashFiles('gradle/wrapper/gradle-wrapper.properties') }}
- name: Execute Gradle build
run: ./gradlew build --stacktrace
shell: bash
18 changes: 0 additions & 18 deletions .travis.yml

This file was deleted.

12 changes: 10 additions & 2 deletions aws-xray-agent-plugin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
`java`
`maven-publish`
Expand Down Expand Up @@ -33,6 +35,7 @@ dependencies {

testImplementation("org.powermock:powermock-api-mockito2:2.0.7")
testImplementation("org.powermock:powermock-module-junit4:2.0.7")
testImplementation("com.github.tomakehurst:wiremock-jre8:2.27.0")

testImplementation("com.amazonaws:aws-xray-recorder-sdk-core")
testImplementation("com.amazonaws:aws-xray-recorder-sdk-sql")
Expand Down Expand Up @@ -135,10 +138,15 @@ tasks {

// The only tests that run in this module are integration tests, so configure them as the standard test task
test {
// Explicitly remove all runtime dependencies and disco plugins from the classpath since a customer's
// Explicitly remove all disco plugins from the classpath since a customer's
// application (which the integ tests simulate) should not be aware of any of those JARs
classpath = classpath.minus(configurations.runtimeClasspath.get())
classpath = classpath.filter {
!(it.name.contains("disco-java-agent")
|| it.name.contains("aws-xray-recorder-sdk-aws-sdk")
|| it.name.contains("aws-xray-agent"))
}

// Integration tests run on Windows and Unix in GitHub actions
jvmArgs("-javaagent:$buildDir/libs/disco/disco-java-agent.jar=pluginPath=$buildDir/libs/disco/disco-plugins",
"-Dcom.amazonaws.xray.strategy.tracingName=IntegTest")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,8 @@
import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.MethodSorters;
import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
Expand Down Expand Up @@ -40,22 +38,16 @@
import java.util.Map;
import java.util.concurrent.CompletableFuture;

@FixMethodOrder(MethodSorters.JVM)
import static org.mockito.ArgumentMatchers.any;

@RunWith(MockitoJUnitRunner.class)
public class AWSV2HandlerIntegTest {

@Before
public void setup() {
TransactionContext.create();
Emitter blankEmitter = Mockito.mock(Emitter.class);
Mockito.doReturn(true).when(blankEmitter).sendSegment(Mockito.anyObject());
// Mockito.doReturn(true).when(blankEmitter).sendSubsegment(Mockito.anyObject());

// AWSXRay.setGlobalRecorder(
// AWSXRayRecorderBuilder.standard()
// .withEmitter(blankEmitter)
// .build()
// );
Mockito.doReturn(true).when(blankEmitter).sendSegment(any());
AWSXRay.getGlobalRecorder().setEmitter(blankEmitter);
AWSXRay.clearTraceEntity();
AWSXRay.beginSegment("test");
Expand All @@ -75,7 +67,7 @@ private SdkHttpClient mockSdkHttpClient(SdkHttpResponse response, String body) t
ExecutableHttpRequest abortableCallable = Mockito.mock(ExecutableHttpRequest.class);
SdkHttpClient mockClient = Mockito.mock(SdkHttpClient.class);

Mockito.when(mockClient.prepareRequest(Mockito.any())).thenReturn(abortableCallable);
Mockito.when(mockClient.prepareRequest(any())).thenReturn(abortableCallable);
Mockito.when(abortableCallable.call()).thenReturn(HttpExecuteResponse.builder()
.response(response)
.responseBody(AbortableInputStream.create(
Expand All @@ -88,7 +80,7 @@ private SdkHttpClient mockSdkHttpClient(SdkHttpResponse response, String body) t

private SdkAsyncHttpClient mockSdkAsyncHttpClient(SdkHttpResponse response) {
SdkAsyncHttpClient mockClient = Mockito.mock(SdkAsyncHttpClient.class);
Mockito.when(mockClient.execute(Mockito.any(AsyncExecuteRequest.class))).thenAnswer((Answer<CompletableFuture<Void>>) invocationOnMock -> {
Mockito.when(mockClient.execute(any(AsyncExecuteRequest.class))).thenAnswer((Answer<CompletableFuture<Void>>) invocationOnMock -> {
SdkAsyncHttpResponseHandler handler = invocationOnMock.getArgument(0, AsyncExecuteRequest.class).responseHandler();
handler.onHeaders(response);
handler.onStream(new EmptyPublisher<>());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.amazonaws.xray.entities.Subsegment;
import com.amazonaws.xray.entities.TraceHeader;
import com.amazonaws.xray.entities.TraceHeader.SampleDecision;
import com.github.tomakehurst.wiremock.junit.WireMockRule;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
Expand All @@ -14,22 +15,30 @@
import org.apache.http.impl.client.HttpClients;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;

import java.net.URI;
import java.util.Map;

import static com.github.tomakehurst.wiremock.client.WireMock.anyUrl;
import static com.github.tomakehurst.wiremock.client.WireMock.get;
import static com.github.tomakehurst.wiremock.client.WireMock.ok;
import static com.github.tomakehurst.wiremock.client.WireMock.stubFor;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

public class HttpClientHandlerIntegTest {
private static final String TRACE_HEADER_KEY = TraceHeader.HEADER_KEY;
private static final int PORT = 2000;
private static final int PORT = 8089;
private static final String ENDPOINT = "http://127.0.0.1:" + PORT;
private Segment currentSegment;

@Rule
public WireMockRule wireMockRule = new WireMockRule(PORT);

@Before
public void setup() {
// Generate the segment that would be normally made by the upstream instrumentor
Expand Down Expand Up @@ -164,6 +173,11 @@ public void testInvalidTargetHost() throws Exception {

@Test
public void testIgnoreSamplingCalls() throws Exception {
stubFor(get(anyUrl()).willReturn(ok()));

// Remove subsegment created by WireMock
AWSXRay.getCurrentSegment().removeSubsegment(AWSXRay.getCurrentSegment().getSubsegments().get(0));

URI targetsUri = new URI(ENDPOINT + "/SamplingTargets");
URI rulesUri = new URI(ENDPOINT + "/GetSamplingRules");

Expand Down

0 comments on commit b8d6f26

Please sign in to comment.