Skip to content

Commit b3045ad

Browse files
authored
fix: typed declaration works correctly with http trigger (#212)
* Configure typed function conformance test * fix: typed function signature should be compatible with 'http' signature type * apply google-java-format fixes
1 parent e30ace5 commit b3045ad

File tree

4 files changed

+54
-10
lines changed

4 files changed

+54
-10
lines changed

.github/workflows/conformance.yaml

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,39 +51,52 @@ jobs:
5151
- name: Build invoker with Maven
5252
run: (cd invoker/ && mvn install)
5353

54+
- name: Build invoker Maven Plugin
55+
run: (cd function-maven-plugin/ && mvn install)
56+
5457
- name: Run HTTP conformance tests
55-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
58+
uses: GoogleCloudPlatform/functions-framework-conformance/action@2f5f319c06a3531be7f75dc5acf6bd00417ff76e # v1.8.2
5659
with:
57-
version: 'v1.6.0'
60+
version: 'v1.8.2'
5861
functionType: 'http'
5962
useBuildpacks: false
6063
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.HttpConformanceFunction'"
6164
startDelay: 10
6265

66+
- name: Run Typed conformance tests
67+
uses: GoogleCloudPlatform/functions-framework-conformance/action@2f5f319c06a3531be7f75dc5acf6bd00417ff76e # v1.8.2
68+
with:
69+
version: 'v1.8.2'
70+
functionType: 'http'
71+
declarativeType: 'typed'
72+
useBuildpacks: false
73+
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.TypedConformanceFunction'"
74+
startDelay: 10
75+
6376
- name: Run background event conformance tests
64-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
77+
uses: GoogleCloudPlatform/functions-framework-conformance/action@2f5f319c06a3531be7f75dc5acf6bd00417ff76e # v1.8.2
6578
with:
66-
version: 'v1.6.0'
79+
version: 'v1.8.2'
6780
functionType: 'legacyevent'
6881
useBuildpacks: false
6982
validateMapping: true
7083
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.BackgroundEventConformanceFunction'"
7184
startDelay: 10
7285

7386
- name: Run cloudevent conformance tests
74-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
87+
uses: GoogleCloudPlatform/functions-framework-conformance/action@2f5f319c06a3531be7f75dc5acf6bd00417ff76e # v1.8.2
7588
with:
76-
version: 'v1.6.0'
89+
version: 'v1.8.2'
7790
functionType: 'cloudevent'
7891
useBuildpacks: false
7992
validateMapping: true
8093
cmd: "'mvn -f invoker/conformance/pom.xml function:run -Drun.functionTarget=com.google.cloud.functions.conformance.CloudEventsConformanceFunction'"
8194
startDelay: 10
8295

8396
- name: Run HTTP concurrency conformance tests
84-
uses: GoogleCloudPlatform/functions-framework-conformance/action@1975792fb34ebbfa058d690666186d669d3a5977 # v1.8.0
97+
uses: GoogleCloudPlatform/functions-framework-conformance/action@2f5f319c06a3531be7f75dc5acf6bd00417ff76e # v1.8.2
8598
with:
86-
version: 'v1.6.0'
99+
version: 'v1.8.2'
87100
functionType: 'http'
88101
useBuildpacks: false
89102
validateConcurrency: true

invoker/conformance/pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
<dependency>
2929
<groupId>com.google.cloud.functions</groupId>
3030
<artifactId>functions-framework-api</artifactId>
31+
<version>1.1.1-SNAPSHOT</version>
3132
</dependency>
3233
<dependency>
3334
<groupId>com.google.code.gson</groupId>
@@ -52,7 +53,7 @@
5253
<plugin>
5354
<groupId>com.google.cloud.functions</groupId>
5455
<artifactId>function-maven-plugin</artifactId>
55-
<version>0.10.1</version>
56+
<version>0.11.1-SNAPSHOT</version>
5657
</plugin>
5758
</plugins>
5859
</pluginManagement>
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.google.cloud.functions.conformance;
2+
3+
import com.google.cloud.functions.TypedFunction;
4+
import com.google.gson.annotations.SerializedName;
5+
6+
public class TypedConformanceFunction
7+
implements TypedFunction<ConformanceRequest, ConformanceResponse> {
8+
@Override
9+
public ConformanceResponse apply(ConformanceRequest req) throws Exception {
10+
return new ConformanceResponse(req);
11+
}
12+
}
13+
14+
class ConformanceRequest {
15+
@SerializedName("message")
16+
public String message;
17+
}
18+
19+
class ConformanceResponse {
20+
@SerializedName("payload")
21+
public ConformanceRequest payload = null;
22+
23+
ConformanceResponse(ConformanceRequest payload) {
24+
this.payload = payload;
25+
}
26+
}

invoker/core/src/main/java/com/google/cloud/functions/invoker/runner/Invoker.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ private void startServer(boolean join) throws Exception {
299299
} else {
300300
switch (functionSignatureType) {
301301
case "http":
302-
servlet = HttpFunctionExecutor.forClass(functionClass);
302+
if (TypedFunction.class.isAssignableFrom(functionClass)) {
303+
servlet = TypedFunctionExecutor.forClass(functionClass);
304+
} else {
305+
servlet = HttpFunctionExecutor.forClass(functionClass);
306+
}
303307
break;
304308
case "event":
305309
case "cloudevent":

0 commit comments

Comments
 (0)