Skip to content

Commit f209422

Browse files
authored
Add getSuspendPostUri and getResumePostUri getters to HttpManagementPayload (#264)
1 parent ffc240b commit f209422

File tree

4 files changed

+111
-2
lines changed

4 files changed

+111
-2
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## Unreleased
2+
* Add getSuspendPostUri and getResumePostUri getters to HttpManagementPayload ([#264](https://github.com/microsoft/durabletask-java/pull/264))
23

34
## v1.8.0
45
* Adding rewind client API ([#253](https://github.com/microsoft/durabletask-java/pull/253)). Note: orchestration processing for rewind is supported with Azure Functions but not with the standalone `GrpcDurableTaskWorker`.

azurefunctions/build.gradle

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ dependencies {
2222
implementation group: 'com.microsoft.azure.functions', name: 'azure-functions-java-library', version: '3.2.3'
2323
implementation "com.google.protobuf:protobuf-java:${protocVersion}"
2424
compileOnly "com.microsoft.azure.functions:azure-functions-java-spi:1.1.0"
25+
testImplementation platform('org.junit:junit-bom:5.14.2')
26+
testImplementation 'org.junit.jupiter:junit-jupiter'
27+
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
28+
}
29+
30+
test {
31+
useJUnitPlatform()
2532
}
2633

2734
sourceCompatibility = JavaVersion.VERSION_1_8

azurefunctions/src/main/java/com/microsoft/durabletask/azurefunctions/HttpManagementPayload.java

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,25 @@ public String getPurgeHistoryDeleteUri() {
9393
* @return The HTTP URL for posting instance restart commands.
9494
*/
9595
public String getRestartPostUri() {
96-
return restartPostUri;
96+
return this.restartPostUri;
97+
}
98+
99+
/**
100+
* Gets the HTTP POST instance suspend endpoint.
101+
*
102+
* @return The HTTP URL for posting instance suspend commands.
103+
*/
104+
public String getSuspendPostUri() {
105+
return this.suspendPostUri;
106+
}
107+
108+
/**
109+
* Gets the HTTP POST instance resume endpoint.
110+
*
111+
* @return The HTTP URL for posting instance resume commands.
112+
*/
113+
public String getResumePostUri() {
114+
return this.resumePostUri;
97115
}
98116

99117
/**
@@ -102,7 +120,7 @@ public String getRestartPostUri() {
102120
* @return The HTTP URL for posting instance rewind commands.
103121
*/
104122
public String getRewindPostUri() {
105-
return rewindPostUri;
123+
return this.rewindPostUri;
106124
}
107125

108126
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.microsoft.durabletask.azurefunctions;
2+
3+
import org.junit.jupiter.api.DisplayName;
4+
import org.junit.jupiter.api.Test;
5+
6+
import static org.junit.jupiter.api.Assertions.*;
7+
8+
/**
9+
* Unit tests for {@link HttpManagementPayload}.
10+
*/
11+
public class HttpManagementPayloadTest {
12+
13+
private static final String INSTANCE_ID = "test-instance-id";
14+
private static final String INSTANCE_STATUS_URL = "http://localhost:7071/runtime/webhooks/durabletask/instances/test-instance-id";
15+
private static final String QUERY_STRING = "code=abc123";
16+
17+
private HttpManagementPayload createPayload() {
18+
return new HttpManagementPayload(INSTANCE_ID, INSTANCE_STATUS_URL, QUERY_STRING);
19+
}
20+
21+
@Test
22+
@DisplayName("getId should return the instance ID")
23+
public void getId_ReturnsInstanceId() {
24+
HttpManagementPayload payload = createPayload();
25+
assertEquals(INSTANCE_ID, payload.getId());
26+
}
27+
28+
@Test
29+
@DisplayName("getStatusQueryGetUri should return correct URL")
30+
public void getStatusQueryGetUri_ReturnsCorrectUrl() {
31+
HttpManagementPayload payload = createPayload();
32+
assertEquals(INSTANCE_STATUS_URL + "?" + QUERY_STRING, payload.getStatusQueryGetUri());
33+
}
34+
35+
@Test
36+
@DisplayName("getSendEventPostUri should return correct URL")
37+
public void getSendEventPostUri_ReturnsCorrectUrl() {
38+
HttpManagementPayload payload = createPayload();
39+
assertEquals(INSTANCE_STATUS_URL + "/raiseEvent/{eventName}?" + QUERY_STRING, payload.getSendEventPostUri());
40+
}
41+
42+
@Test
43+
@DisplayName("getTerminatePostUri should return correct URL")
44+
public void getTerminatePostUri_ReturnsCorrectUrl() {
45+
HttpManagementPayload payload = createPayload();
46+
assertEquals(INSTANCE_STATUS_URL + "/terminate?reason={text}&" + QUERY_STRING, payload.getTerminatePostUri());
47+
}
48+
49+
@Test
50+
@DisplayName("getPurgeHistoryDeleteUri should return correct URL")
51+
public void getPurgeHistoryDeleteUri_ReturnsCorrectUrl() {
52+
HttpManagementPayload payload = createPayload();
53+
assertEquals(INSTANCE_STATUS_URL + "?" + QUERY_STRING, payload.getPurgeHistoryDeleteUri());
54+
}
55+
56+
@Test
57+
@DisplayName("getRestartPostUri should return correct URL")
58+
public void getRestartPostUri_ReturnsCorrectUrl() {
59+
HttpManagementPayload payload = createPayload();
60+
assertEquals(INSTANCE_STATUS_URL + "/restart?" + QUERY_STRING, payload.getRestartPostUri());
61+
}
62+
63+
@Test
64+
@DisplayName("getSuspendPostUri should return correct URL")
65+
public void getSuspendPostUri_ReturnsCorrectUrl() {
66+
HttpManagementPayload payload = createPayload();
67+
assertEquals(INSTANCE_STATUS_URL + "/suspend?reason={text}&" + QUERY_STRING, payload.getSuspendPostUri());
68+
}
69+
70+
@Test
71+
@DisplayName("getResumePostUri should return correct URL")
72+
public void getResumePostUri_ReturnsCorrectUrl() {
73+
HttpManagementPayload payload = createPayload();
74+
assertEquals(INSTANCE_STATUS_URL + "/resume?reason={text}&" + QUERY_STRING, payload.getResumePostUri());
75+
}
76+
77+
@Test
78+
@DisplayName("getRewindPostUri should return correct URL")
79+
public void getRewindPostUri_ReturnsCorrectUrl() {
80+
HttpManagementPayload payload = createPayload();
81+
assertEquals(INSTANCE_STATUS_URL + "/rewind?reason={text}&" + QUERY_STRING, payload.getRewindPostUri());
82+
}
83+
}

0 commit comments

Comments
 (0)