Skip to content
This repository was archived by the owner on Sep 9, 2024. It is now read-only.

Commit fa9d179

Browse files
committed
feat: Get verification working
1 parent f8ce25d commit fa9d179

27 files changed

Lines changed: 707 additions & 291 deletions

build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,20 @@ repositories {
1717

1818
def caseCoreVersion = "0.15.6"
1919
def caseBoundaryVersion = "0.11.0"
20-
def grpcVersion = "1.60.1"
20+
def grpcVersion = "1.62.2"
2121

2222
dependencies {
2323
api "io.contract-testing.contractcase:case_example_mock_types:${caseCoreVersion}"
2424
api "io.contract-testing.contractcase:test-equivalence-matchers:${caseCoreVersion}"
2525
implementation "io.contract-testing.contractcase:case_boundary:${caseBoundaryVersion}"
2626
implementation 'com.diogonunes:JColor:5.5.1'
27-
implementation 'com.google.protobuf:protobuf-java:3.25.1'
28-
implementation 'com.google.protobuf:protobuf-java-util:3.25.1'
29-
implementation 'com.google.protobuf:protoc:3.25.1'
27+
implementation 'com.google.protobuf:protobuf-java:3.25.3'
28+
implementation 'com.google.protobuf:protobuf-java-util:3.25.3'
29+
implementation 'com.google.protobuf:protoc:3.25.3'
3030
implementation "io.grpc:protoc-gen-grpc-java:${grpcVersion}"
3131
implementation "io.grpc:grpc-core:${grpcVersion}"
3232
implementation "io.grpc:grpc-stub:${grpcVersion}"
33-
implementation "io.grpc:grpc-okhttp:${grpcVersion}"
33+
implementation "io.grpc:grpc-netty-shaded:${grpcVersion}"
3434
implementation "io.grpc:grpc-protobuf:${grpcVersion}"
3535
implementation 'com.fasterxml.jackson.core:jackson-databind:2.16.1'
3636
implementation 'org.jetbrains:annotations:23.0.0'

src/main/java/io/contract_testing/contractcase/BoundaryExceptionMapper.java

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,16 @@ static String stackTraceToString(Throwable e) {
1414
}
1515

1616
static BoundaryFailure map(Throwable e) {
17-
return new BoundaryFailure(e.getClass().getName(), e.getMessage(), stackTraceToString(e));
17+
var failure = new BoundaryFailure(
18+
e.getClass().getName(),
19+
e.getMessage(),
20+
stackTraceToString(e)
21+
);
22+
if (failure.getResultType() == null) {
23+
throw new ContractCaseCoreError(
24+
"Missing a result type - this is almost certainly a threading issue in the Java DSL (both grpc and jsii are not thread safe)");
25+
}
26+
return failure;
1827
}
1928

2029
static BoundaryFailure mapAsTriggerFailure(Throwable e) {

src/main/java/io/contract_testing/contractcase/ContractDefiner.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public ContractDefiner(final @NotNull ContractCaseConfig config) {
1818
definer = new InternalDefinerClient(
1919
BoundaryConfigMapper.map(config, TEST_RUN_ID),
2020
logPrinter,
21-
logPrinter,
2221
new BoundaryVersionGenerator().getVersions()
2322
);
2423
} catch (Throwable e) {

src/main/java/io/contract_testing/contractcase/ContractVerifier.java

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
package io.contract_testing.contractcase;
22

3-
import io.contract_testing.contractcase.case_boundary.BoundaryResult;
4-
import io.contract_testing.contractcase.case_boundary.IInvokeCoreTest;
5-
import io.contract_testing.contractcase.case_boundary.IRunTestCallback;
3+
import io.contract_testing.contractcase.case_boundary.BoundaryCrashMessage;
64
import io.contract_testing.contractcase.client.InternalVerifierClient;
75
import io.contract_testing.contractcase.client.MaintainerLog;
6+
import io.contract_testing.contractcase.edge.ConnectorExceptionMapper;
7+
import io.contract_testing.contractcase.edge.ConnectorFailure;
8+
import io.contract_testing.contractcase.edge.ConnectorFailureKindConstants;
9+
import io.contract_testing.contractcase.edge.ConnectorResult;
10+
import io.contract_testing.contractcase.edge.ConnectorResultTypeConstants;
11+
import io.contract_testing.contractcase.edge.InvokeCoreTest;
12+
import io.contract_testing.contractcase.edge.RunTestCallback;
13+
import java.util.ArrayList;
814
import java.util.List;
915
import org.jetbrains.annotations.NotNull;
1016

1117
public class ContractVerifier {
1218

1319
private final InternalVerifierClient verifier;
1420

21+
private final List<ConnectorFailure> failures = new ArrayList<>();
22+
1523
public ContractVerifier(ContractCaseConfig config) {
1624
LogPrinter logPrinter = new LogPrinter();
1725

@@ -20,22 +28,51 @@ public ContractVerifier(ContractCaseConfig config) {
2028
verification = new InternalVerifierClient(
2129
BoundaryConfigMapper.map(config, "VERIFICATION"),
2230
// TODO: Move the runTestCallback into the internals, maybe?
23-
new IRunTestCallback() {
31+
new RunTestCallback() {
2432
@Override
25-
public @NotNull BoundaryResult runTest(@NotNull String testName,
26-
@NotNull IInvokeCoreTest invoker) {
33+
public @NotNull ConnectorResult runTest(@NotNull String testName,
34+
@NotNull InvokeCoreTest invoker) {
2735
// TODO replace this with something that knows about JUnit
2836
try {
29-
MaintainerLog.log("Invoking verifier");
37+
MaintainerLog.log("Invoking verifier for: " + testName);
3038
var result = invoker.verify();
31-
MaintainerLog.log("Verifier result was: " + result);
39+
40+
// TODO: Replace this with something that knows what to do with these results
41+
if (result.getResultType().equals(ConnectorResultTypeConstants.RESULT_SUCCESS)) {
42+
MaintainerLog.log("");
43+
MaintainerLog.log("[SUCCESS] " + testName);
44+
MaintainerLog.log("");
45+
46+
} else {
47+
var failure = ((ConnectorFailure) result);
48+
failures.add(failure);
49+
var kind = failure.getKind();
50+
if (kind.equals(ConnectorFailureKindConstants.CASE_CORE_ERROR)) {
51+
System.err.println(
52+
BoundaryCrashMessage.CRASH_MESSAGE_START
53+
+ "\n\n"
54+
+ failure.getMessage()
55+
+ "\n"
56+
+ failure.getLocation()
57+
+ "\n\n"
58+
+ BoundaryCrashMessage.CRASH_MESSAGE_END);
59+
} else if (kind.equals(ConnectorFailureKindConstants.CASE_CONFIGURATION_ERROR)) {
60+
MaintainerLog.log("");
61+
MaintainerLog.log("[CONFIGURATION ERROR] " + failure.getMessage());
62+
MaintainerLog.log("");
63+
} else {
64+
MaintainerLog.log("");
65+
MaintainerLog.log("[OTHER ERROR] " + failure.getMessage());
66+
MaintainerLog.log("");
67+
}
68+
}
3269
return result;
3370
} catch (Exception e) {
34-
return BoundaryExceptionMapper.map(e);
71+
return ConnectorExceptionMapper.map(e);
3572
}
3673
}
3774

38-
}, logPrinter, logPrinter, new BoundaryVersionGenerator().getVersions()
75+
}, logPrinter, new BoundaryVersionGenerator().getVersions()
3976
);
4077
} catch (Throwable e) {
4178
BoundaryCrashReporter.handleAndRethrow(e);
@@ -60,5 +97,13 @@ public void runVerification(ContractCaseConfig configOverrides) {
6097
} catch (Throwable e) {
6198
BoundaryCrashReporter.handleAndRethrow(e);
6299
}
100+
if (!failures.isEmpty()) {
101+
try {
102+
BoundaryResultMapper.mapVoid(ConnectorResult.toBoundaryResult(failures.get(0)));
103+
} catch (Throwable e) {
104+
BoundaryCrashReporter.handleAndRethrow(e);
105+
}
106+
107+
}
63108
}
64109
}

0 commit comments

Comments
 (0)