Skip to content

Commit 924e542

Browse files
authored
Move integration tests to DTS Emulator (#230)
Signed-off-by: Hal Spang <[email protected]>
1 parent 140f934 commit 924e542

File tree

7 files changed

+110
-94
lines changed

7 files changed

+110
-94
lines changed

.github/workflows/build-validation.yml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,11 @@ jobs:
7373
if: env.UNIT_TEST_FAILED == 'true'
7474
run: exit 1
7575

76-
# TODO: Move the sidecar into a central image repository
77-
- name: Initialize Durable Task Sidecar
78-
run: docker run --name durabletask-sidecar -p 4001:4001 --env 'DURABLETASK_SIDECAR_LOGLEVEL=Debug' -d peterstone2019/durabletask-sidecar:latest start --backend Emulator
76+
- name: Initialize Durable Task Emulator
77+
run: docker run --name durabletask-emulator -p 4001:8080 -d mcr.microsoft.com/dts/dts-emulator:latest
7978

80-
- name: Display Durable Task Sidecar Logs
81-
run: nohup docker logs --since=0 durabletask-sidecar > durabletask-sidecar.log 2>&1 &
79+
- name: Display Durable Task Emulator Logs
80+
run: nohup docker logs --since=0 durabletask-emulator > durabletask-emulator.log 2>&1 &
8281

8382
# wait for 10 seconds, so sidecar container can be fully up, this will avoid intermittent failing issues for integration tests causing by failed to connect to sidecar
8483
- name: Wait for 10 seconds
@@ -88,14 +87,14 @@ jobs:
8887
run: ./gradlew integrationTest || echo "TEST_FAILED=true" >> $GITHUB_ENV
8988
continue-on-error: true
9089

91-
- name: Kill Durable Task Sidecar
92-
run: docker kill durabletask-sidecar
90+
- name: Kill Durable Task Emulator
91+
run: docker kill durabletask-emulator
9392

94-
- name: Upload Durable Task Sidecar Logs
93+
- name: Upload Durable Task Emulator Logs
9594
uses: actions/upload-artifact@v4
9695
with:
97-
name: Durable Task Sidecar Logs
98-
path: durabletask-sidecar.log
96+
name: Durable Task Emulator Logs
97+
path: durabletask-emulator.log
9998

10099
- name: Archive test report
101100
uses: actions/upload-artifact@v4

azuremanaged/src/main/java/com/microsoft/durabletask/azuremanaged/DurableTaskSchedulerClientExtensions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public static DurableTaskGrpcClientBuilder createClientBuilder(
9191
return createBuilderFromOptions(new DurableTaskSchedulerClientOptions()
9292
.setEndpointAddress(endpoint)
9393
.setTaskHubName(taskHubName)
94-
.setCredential(tokenCredential));
94+
.setCredential(tokenCredential)
95+
.setAllowInsecureCredentials(tokenCredential == null));
9596
}
9697

9798
// Private helper methods to reduce code duplication

azuremanaged/src/main/java/com/microsoft/durabletask/azuremanaged/DurableTaskSchedulerWorkerExtensions.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ public static DurableTaskGrpcWorkerBuilder createWorkerBuilder(
9191
return createBuilderFromOptions(new DurableTaskSchedulerWorkerOptions()
9292
.setEndpointAddress(endpoint)
9393
.setTaskHubName(taskHubName)
94-
.setCredential(tokenCredential));
94+
.setCredential(tokenCredential)
95+
.setAllowInsecureCredentials(tokenCredential == null));
9596
}
9697

9798
// Private helper methods to reduce code duplication

client/build.gradle

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ def grpcVersion = '1.59.0'
1717
def protocVersion = '3.12.0'
1818
def jacksonVersion = '2.15.3'
1919
def openTelemetryVersion = '1.25.0'
20+
def azureCoreVersion = '1.45.0'
21+
def azureIdentityVersion = '1.11.1'
2022
// When build on local, you need to set this value to your local jdk11 directory.
2123
// Java11 is used to compile and run all the tests.
2224
// Example for Windows: C:/Program Files/Java/openjdk-11.0.12_7/
@@ -36,12 +38,14 @@ dependencies {
3638
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
3739
implementation "com.fasterxml.jackson.core:jackson-annotations:${jacksonVersion}"
3840
implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:${jacksonVersion}"
39-
4041
implementation "io.opentelemetry:opentelemetry-api:${openTelemetryVersion}"
4142
implementation "io.opentelemetry:opentelemetry-context:${openTelemetryVersion}"
4243

4344
testImplementation(platform('org.junit:junit-bom:5.7.2'))
4445
testImplementation('org.junit.jupiter:junit-jupiter')
46+
testImplementation project(':azuremanaged')
47+
testImplementation "com.azure:azure-core:${azureCoreVersion}"
48+
testImplementation "com.azure:azure-identity:${azureIdentityVersion}"
4549
}
4650

4751
compileJava {

client/src/test/java/com/microsoft/durabletask/ErrorHandlingIntegrationTests.java

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
import java.util.concurrent.atomic.AtomicBoolean;
1414
import java.util.concurrent.atomic.AtomicInteger;
1515

16-
import org.junit.jupiter.api.BeforeEach;
1716
import static org.junit.jupiter.api.Assertions.*;
1817

1918
/**
@@ -26,13 +25,6 @@
2625
@Tag("integration")
2726
public class ErrorHandlingIntegrationTests extends IntegrationTestBase {
2827

29-
@BeforeEach
30-
private void startUp() {
31-
try(DurableTaskClient client = new DurableTaskGrpcClientBuilder().build()) {
32-
client.deleteTaskHub();
33-
}
34-
}
35-
3628
@Test
3729
void orchestratorException() throws TimeoutException {
3830
final String orchestratorName = "OrchestratorWithException";
@@ -44,7 +36,7 @@ void orchestratorException() throws TimeoutException {
4436
})
4537
.buildAndStart();
4638

47-
DurableTaskClient client = new DurableTaskGrpcClientBuilder().build();
39+
DurableTaskClient client = this.createClientBuilder().build();
4840
try (worker; client) {
4941
String instanceId = client.scheduleNewOrchestrationInstance(orchestratorName, 0);
5042
OrchestrationMetadata instance = client.waitForInstanceCompletion(instanceId, defaultTimeout, true);
@@ -83,7 +75,7 @@ void activityException(boolean handleException) throws TimeoutException {
8375
})
8476
.buildAndStart();
8577

86-
DurableTaskClient client = new DurableTaskGrpcClientBuilder().build();
78+
DurableTaskClient client = this.createClientBuilder().build();
8779
try (worker; client) {
8880
String instanceId = client.scheduleNewOrchestrationInstance(orchestratorName, "");
8981
OrchestrationMetadata instance = client.waitForInstanceCompletion(instanceId, defaultTimeout, true);
@@ -166,7 +158,7 @@ void subOrchestrationException(boolean handleException) throws TimeoutException
166158
throw new RuntimeException(errorMessage);
167159
})
168160
.buildAndStart();
169-
DurableTaskClient client = new DurableTaskGrpcClientBuilder().build();
161+
DurableTaskClient client = this.createClientBuilder().build();
170162
try (worker; client) {
171163
String instanceId = client.scheduleNewOrchestrationInstance(orchestratorName, 1);
172164
OrchestrationMetadata instance = client.waitForInstanceCompletion(instanceId, defaultTimeout, true);
@@ -284,7 +276,7 @@ private FailureDetails retryOnFailuresCoreTest(
284276
})
285277
.buildAndStart();
286278

287-
DurableTaskClient client = new DurableTaskGrpcClientBuilder().build();
279+
DurableTaskClient client = this.createClientBuilder().build();
288280
try (worker; client) {
289281
String instanceId = client.scheduleNewOrchestrationInstance(orchestratorName, "");
290282
OrchestrationMetadata instance = client.waitForInstanceCompletion(instanceId, defaultTimeout, true);

client/src/test/java/com/microsoft/durabletask/IntegrationTestBase.java

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,62 @@
77

88
import java.time.Duration;
99

10+
import com.microsoft.durabletask.azuremanaged.DurableTaskSchedulerClientOptions;
11+
import com.microsoft.durabletask.azuremanaged.DurableTaskSchedulerWorkerExtensions;
12+
import com.microsoft.durabletask.azuremanaged.DurableTaskSchedulerWorkerOptions;
13+
14+
import io.grpc.Channel;
15+
import io.grpc.ManagedChannel;
1016
public class IntegrationTestBase {
1117
protected static final Duration defaultTimeout = Duration.ofSeconds(10);
1218

1319
// All tests that create a server should save it to this variable for proper shutdown
14-
private DurableTaskGrpcWorker server;
20+
private DurableTaskGrpcWorker server; // All tests that create a client are responsible for closing their own gRPC channel
21+
private ManagedChannel workerChannel;
22+
private ManagedChannel clientChannel;
1523

1624
@AfterEach
1725
private void shutdown() {
1826
if (this.server != null) {
1927
this.server.stop();
28+
this.server = null;
29+
}
30+
31+
if (this.workerChannel != null) {
32+
this.workerChannel.shutdownNow();
33+
this.workerChannel = null;
34+
}
35+
36+
if (this.clientChannel != null) {
37+
this.clientChannel.shutdownNow();
38+
this.clientChannel = null;
2039
}
2140
}
2241

2342
protected TestDurableTaskWorkerBuilder createWorkerBuilder() {
24-
return new TestDurableTaskWorkerBuilder();
43+
DurableTaskSchedulerWorkerOptions options = new DurableTaskSchedulerWorkerOptions()
44+
.setEndpointAddress("http://localhost:4001")
45+
.setTaskHubName("default")
46+
.setCredential(null)
47+
.setAllowInsecureCredentials(true);
48+
Channel grpcChannel = options.createGrpcChannel();
49+
this.workerChannel = (ManagedChannel) grpcChannel;
50+
return new TestDurableTaskWorkerBuilder(
51+
new DurableTaskGrpcWorkerBuilder()
52+
.grpcChannel(grpcChannel));
53+
}
54+
55+
protected DurableTaskGrpcClientBuilder createClientBuilder() {
56+
DurableTaskSchedulerClientOptions options = new DurableTaskSchedulerClientOptions()
57+
.setEndpointAddress("http://localhost:4001")
58+
.setTaskHubName("default")
59+
.setCredential(null)
60+
.setAllowInsecureCredentials(true);
61+
Channel grpcChannel = options.createGrpcChannel();
62+
// The channel returned is actually a ManagedChannel, so we can safely cast it
63+
this.clientChannel = (ManagedChannel) grpcChannel;
64+
return new DurableTaskGrpcClientBuilder()
65+
.grpcChannel(grpcChannel);
2566
}
2667

2768
public class TestDurableTaskWorkerBuilder {
@@ -31,6 +72,10 @@ private TestDurableTaskWorkerBuilder() {
3172
this.innerBuilder = new DurableTaskGrpcWorkerBuilder();
3273
}
3374

75+
private TestDurableTaskWorkerBuilder(DurableTaskGrpcWorkerBuilder innerBuilder) {
76+
this.innerBuilder = innerBuilder;
77+
}
78+
3479
public DurableTaskGrpcWorker buildAndStart() {
3580
DurableTaskGrpcWorker server = this.innerBuilder.build();
3681
IntegrationTestBase.this.server = server;

0 commit comments

Comments
 (0)