Skip to content

Commit

Permalink
Speed up tests a little (#260)
Browse files Browse the repository at this point in the history
by caching JSON schema in MockReporter
  • Loading branch information
felixbarny authored Oct 29, 2018
1 parent 7da2e91 commit 5a76939
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions apm-agent-core/src/test/java/co/elastic/apm/MockReporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,31 +48,34 @@
import static org.mockito.Mockito.mock;

public class MockReporter implements Reporter {
private static final JsonSchema transactionSchema;
private static final JsonSchema errorSchema;
private static final JsonSchema spanSchema;
private static final DslJsonSerializer dslJsonSerializer;
private final List<Transaction> transactions = new ArrayList<>();
private final List<Span> spans = new ArrayList<>();
private final List<ErrorCapture> errors = new ArrayList<>();
private final JsonSchema transactionSchema;
private final JsonSchema errorSchema;
private final JsonSchema spanSchema;
private final DslJsonSerializer dslJsonSerializer;
private final ObjectMapper objectMapper;
private final boolean verifyJsonSchema;

static {
transactionSchema = getSchema("/schema/transactions/transaction.json");
spanSchema = getSchema("/schema/transactions/span.json");
errorSchema = getSchema("/schema/errors/error.json");
dslJsonSerializer = new DslJsonSerializer(mock(StacktraceConfiguration.class));
}

public MockReporter() {
this(true);
}

public MockReporter(boolean verifyJsonSchema) {
this.verifyJsonSchema = verifyJsonSchema;
transactionSchema = getSchema("/schema/transactions/transaction.json");
spanSchema = getSchema("/schema/transactions/span.json");
errorSchema = getSchema("/schema/errors/error.json");
dslJsonSerializer = new DslJsonSerializer(mock(StacktraceConfiguration.class));
objectMapper = new ObjectMapper();
}

private JsonSchema getSchema(String resource) {
return JsonSchemaFactory.getInstance().getSchema(getClass().getResourceAsStream(resource));
private static JsonSchema getSchema(String resource) {
return JsonSchemaFactory.getInstance().getSchema(MockReporter.class.getResourceAsStream(resource));
}

@Override
Expand Down

0 comments on commit 5a76939

Please sign in to comment.