Skip to content

Commit 0b1ef44

Browse files
- Add support for java11.
- Add support for java11 testing pipeline. - Fix the dev pipeline.
1 parent 568a219 commit 0b1ef44

File tree

17 files changed

+596
-178
lines changed

17 files changed

+596
-178
lines changed

azure-pipelines.yml

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ steps:
1111
checkLatest: true
1212
- pwsh: |
1313
Get-Command mvn
14-
displayName: 'Installing Maven'
14+
displayName: 'Check Maven is installed'
1515
- pwsh: |
1616
$buildNumber = 0
1717
if($env:APPVEYOR_REPO_TAG -eq "true") {
@@ -32,10 +32,10 @@ steps:
3232
CleanTargetFolder: true
3333
displayName: 'Copying files for artifacts'
3434
- pwsh: |
35-
.\setup-tests.ps1
35+
.\setup-tests-pipeline.ps1
3636
displayName: 'Setting tests'
3737
- pwsh: |
38-
.\run-tests.ps1
38+
.\build-run-tests-pipeline.ps1
3939
env:
4040
AzureWebJobsStorage: $(AzureWebJobsStorage)
4141
AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString)
@@ -47,8 +47,25 @@ steps:
4747
SBTopicSubName: $(SBTopicSubName)
4848
CosmosDBDatabaseName: $(CosmosDBDatabaseName)
4949
SBQueueName: $(SBQueueName)
50-
displayName: 'running tests'
51-
continueOnError: true
50+
displayName: 'Build & Run tests for java 8'
51+
continueOnError: false
52+
- pwsh: |
53+
.\build-run-tests-pipeline.ps1
54+
env:
55+
JAVA_HOME: 'C:\Program Files\Java\zulu-11-azure-jdk_11.33.15-11.0.4-win_x64'
56+
AzureWebJobsStorage: $(AzureWebJobsStorage)
57+
AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString)
58+
AzureWebJobsServiceBus: $(AzureWebJobsServiceBus)
59+
AzureWebJobsEventHubSender_2: $(AzureWebJobsEventHubSender_2)
60+
AzureWebJobsEventHubReceiver: $(AzureWebJobsEventHubReceiver)
61+
AzureWebJobsEventHubSender: $(AzureWebJobsEventHubSender)
62+
AzureWebJobsEventHubPath: $(AzureWebJobsEventHubPath)
63+
SBTopicName: $(SBTopicName)
64+
SBTopicSubName: $(SBTopicSubName)
65+
CosmosDBDatabaseName: $(CosmosDBDatabaseName)
66+
SBQueueName: $(SBQueueName)
67+
displayName: 'Build & Run tests for java 11'
68+
continueOnError: false
5269
- task: CopyFiles@2
5370
inputs:
5471
SourceFolder: '$(System.DefaultWorkingDirectory)/testResults'

build-run-tests-pipeline.ps1

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# A function that checks exit codes and fails script if an error is found
2+
function StopOnFailedExecution {
3+
if ($LastExitCode)
4+
{
5+
exit $LastExitCode
6+
}
7+
}
8+
9+
function RunTest([string] $project, [string] $description,[bool] $skipBuild = $false, $filter = $null) {
10+
Write-Host "Running test: $description" -ForegroundColor DarkCyan
11+
Write-Host "-----------------------------------------------------------------------------" -ForegroundColor DarkCyan
12+
Write-Host
13+
14+
$cmdargs = "test", "$project", "-v", "q", "-l", "trx", "-r",".\testResults"
15+
16+
if ($filter) {
17+
$cmdargs += "--filter", "$filter"
18+
}
19+
20+
& dotnet $cmdargs | Out-Host
21+
$r = $?
22+
23+
Write-Host
24+
Write-Host "-----------------------------------------------------------------------------" -ForegroundColor DarkCyan
25+
Write-Host
26+
27+
return $r
28+
}
29+
30+
$currDir = Get-Location
31+
32+
Write-Host "Building endtoendtests...."
33+
$Env:Path = $Env:Path+";$currDir\Azure.Functions.Cli"
34+
Push-Location -Path "./endtoendtests" -StackName javaWorkerDir
35+
Write-Host "Building azure-functions-maven-com.microsoft.azure.functions.endtoendtests"
36+
cmd.exe /c '.\..\mvnBuildSkipTests.bat'
37+
StopOnFailedExecution
38+
Pop-Location -StackName "javaWorkerDir"
39+
40+
$tests = @(
41+
@{project ="endtoendtests\Azure.Functions.Java.Tests.E2E\Azure.Functions.Java.Tests.E2E\Azure.Functions.Java.Tests.E2E.csproj"; description="E2E integration tests"}
42+
)
43+
44+
$success = $true
45+
$testRunSucceeded = $true
46+
47+
foreach ($test in $tests){
48+
$testRunSucceeded = RunTest $test.project $test.description $testRunSucceeded $test.filter
49+
$success = $testRunSucceeded -and $success
50+
}
51+
52+
if (-not $success) { exit 1 }
53+

endtoendtests/pom.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,34 @@
6767
<groupId>com.microsoft.azure.functions</groupId>
6868
<artifactId>azure-functions-java-library</artifactId>
6969
</dependency>
70+
<dependency>
71+
<groupId>org.apache.httpcomponents</groupId>
72+
<artifactId>httpclient</artifactId>
73+
<version>4.5.9</version>
74+
</dependency>
75+
<dependency>
76+
<groupId>com.google.guava</groupId>
77+
<artifactId>guava</artifactId>
78+
<version>28.1-jre</version>
79+
</dependency>
80+
<dependency>
81+
<groupId>com.h2database</groupId>
82+
<artifactId>h2</artifactId>
83+
<version>1.4.199</version>
84+
<scope>runtime</scope>
85+
</dependency>
86+
<dependency>
87+
<groupId>com.google.code.gson</groupId>
88+
<artifactId>gson</artifactId>
89+
<version>2.8.6</version>
90+
</dependency>
91+
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 -->
92+
<dependency>
93+
<groupId>org.apache.commons</groupId>
94+
<artifactId>commons-lang3</artifactId>
95+
<version>3.10</version>
96+
</dependency>
97+
7098
</dependencies>
7199

72100
<build>
Lines changed: 111 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,68 +1,111 @@
1-
package com.microsoft.azure.functions.endtoend;
2-
3-
import com.microsoft.azure.functions.annotation.*;
4-
import com.microsoft.azure.functions.*;
5-
import java.util.*;
6-
7-
/**
8-
* Azure Functions with HTTP trigger.
9-
*/
10-
public class HttpTriggerTests {
11-
/**
12-
* This function will listen at HTTP endpoint "/api/HttpTrigger".
13-
*/
14-
@FunctionName("HttpTriggerJava")
15-
public HttpResponseMessage HttpTriggerJava(
16-
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
17-
final ExecutionContext context
18-
) {
19-
context.getLogger().info("Java HTTP trigger processed a request.");
20-
21-
// Parse query parameters
22-
String query = request.getQueryParameters().get("name");
23-
String name = request.getBody().orElse(query);
24-
String readEnv = System.getenv("AzureWebJobsStorage");
25-
26-
if (name == null ) {
27-
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
28-
}
29-
if (readEnv == null ) {
30-
return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).body("AzureWebJobsStorage is empty").build();
31-
}
32-
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
33-
}
34-
35-
@FunctionName("HttpTriggerJavaThrows")
36-
public HttpResponseMessage HttpTriggerThrows(
37-
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
38-
final ExecutionContext context) throws Exception{
39-
context.getLogger().info("Java HTTP trigger processed a request.");
40-
throw new Exception("Test Exception");
41-
}
42-
43-
@FunctionName("HttpTriggerJavaMetadata")
44-
public static String HttpTriggerJavaMetadata(
45-
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
46-
@BindingName("firstName") String queryValue1, @BindingName("lastName") String queryValue2
47-
) {
48-
return queryValue1+queryValue2;
49-
}
50-
51-
@FunctionName("HttpTriggerCustomCode")
52-
public HttpResponseMessage HttpTriggerCustomCode(
53-
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
54-
final ExecutionContext context
55-
) {
56-
context.getLogger().info("Java HTTP trigger processed a request.");
57-
58-
// Parse query parameters
59-
String query = request.getQueryParameters().get("name");
60-
String name = request.getBody().orElse(query);
61-
62-
if (name == null) {
63-
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
64-
} else {
65-
return request.createResponseBuilder(HttpStatusType.custom(209)).body("Hello, " + name).build();
66-
}
67-
}
68-
}
1+
package com.microsoft.azure.functions.endtoend;
2+
3+
import com.microsoft.azure.functions.annotation.*;
4+
import com.microsoft.azure.functions.*;
5+
import java.util.*;
6+
7+
import com.google.gson.Gson;
8+
import org.apache.http.HttpResponse;
9+
import org.apache.http.client.methods.HttpGet;
10+
import org.apache.http.impl.client.CloseableHttpClient;
11+
import org.apache.http.impl.client.HttpClients;
12+
13+
import java.sql.Connection;
14+
import java.sql.DriverManager;
15+
import java.sql.Statement;
16+
17+
import java.io.InputStream;
18+
import com.google.common.io.CharStreams;
19+
import java.io.IOException;
20+
import java.io.InputStreamReader;
21+
22+
import org.apache.commons.lang3.SystemUtils;
23+
24+
/**
25+
* Azure Functions with HTTP trigger.
26+
*/
27+
public class HttpTriggerTests {
28+
/**
29+
* This function will listen at HTTP endpoint "/api/HttpTrigger".
30+
*/
31+
@FunctionName("HttpTriggerJava")
32+
public HttpResponseMessage HttpTriggerJava(
33+
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
34+
final ExecutionContext context
35+
) throws Exception {
36+
context.getLogger().info("Java HTTP trigger processed a request.");
37+
38+
// Parse query parameters
39+
String query = request.getQueryParameters().get("name");
40+
String name = request.getBody().orElse(query);
41+
String readEnv = System.getenv("AzureWebJobsStorage");
42+
43+
try (Connection connection = DriverManager.getConnection("jdbc:h2:mem:test")) {
44+
try (Statement statement = connection.createStatement()) {
45+
statement.execute("select 1");
46+
}
47+
}
48+
49+
Gson a = new Gson();
50+
51+
// if(!SystemUtils.IS_JAVA_15) {
52+
// context.getLogger().info("Java version not 15");
53+
// }
54+
55+
get("https://httpstat.us/200");
56+
57+
if (name == null ) {
58+
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
59+
}
60+
if (readEnv == null ) {
61+
return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR).body("AzureWebJobsStorage is empty").build();
62+
}
63+
return request.createResponseBuilder(HttpStatus.OK).body("Hello, " + name).build();
64+
}
65+
66+
private static String get(String url) throws IOException {
67+
CloseableHttpClient httpClient = HttpClients.createDefault();
68+
HttpGet httpGet = new HttpGet(url);
69+
httpGet.setHeader("Accept", "application/json");
70+
HttpResponse response = httpClient.execute(httpGet);
71+
InputStream content = response.getEntity().getContent();
72+
String body = CharStreams.toString(new InputStreamReader(content));
73+
content.close();
74+
httpClient.close();
75+
return "Response from " + url + " was: " + body;
76+
}
77+
78+
@FunctionName("HttpTriggerJavaThrows")
79+
public HttpResponseMessage HttpTriggerThrows(
80+
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
81+
final ExecutionContext context) throws Exception{
82+
context.getLogger().info("Java HTTP trigger processed a request.");
83+
throw new Exception("Test Exception");
84+
}
85+
86+
@FunctionName("HttpTriggerJavaMetadata")
87+
public static String HttpTriggerJavaMetadata(
88+
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
89+
@BindingName("firstName") String queryValue1, @BindingName("lastName") String queryValue2
90+
) {
91+
return queryValue1+queryValue2;
92+
}
93+
94+
@FunctionName("HttpTriggerCustomCode")
95+
public HttpResponseMessage HttpTriggerCustomCode(
96+
@HttpTrigger(name = "req", methods = {HttpMethod.GET, HttpMethod.POST}, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage<Optional<String>> request,
97+
final ExecutionContext context
98+
) {
99+
context.getLogger().info("Java HTTP trigger processed a request.");
100+
101+
// Parse query parameters
102+
String query = request.getQueryParameters().get("name");
103+
String name = request.getBody().orElse(query);
104+
105+
if (name == null) {
106+
return request.createResponseBuilder(HttpStatus.BAD_REQUEST).body("Please pass a name on the query string or in the request body").build();
107+
} else {
108+
return request.createResponseBuilder(HttpStatusType.custom(209)).body("Hello, " + name).build();
109+
}
110+
}
111+
}

setup-tests-pipeline.ps1

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
Write-Host "$args[0]"
2+
Write-Host $args[0]
3+
4+
$skipCliDownload = $false
5+
if($args[0])
6+
{
7+
$skipCliDownload = $args[0]
8+
}
9+
Write-Host $skipCliDownload
10+
11+
$currDir = Get-Location
12+
if(!$skipCliDownload)
13+
{
14+
Write-Host "Deleting Functions Core Tools if exists...."
15+
Remove-Item -Force ./Azure.Functions.Cli.zip -ErrorAction Ignore
16+
Remove-Item -Recurse -Force ./Azure.Functions.Cli -ErrorAction Ignore
17+
18+
Write-Host "Downloading Functions Core Tools...."
19+
Invoke-RestMethod -Uri 'https://functionsclibuilds.blob.core.windows.net/builds/3/latest/version.txt' -OutFile version.txt
20+
Write-Host "Using Functions Core Tools version: $(Get-Content -Raw version.txt)"
21+
$version = "$(Get-Content -Raw version.txt)"
22+
Remove-Item version.txt
23+
24+
if ($version -and $version.trim())
25+
{
26+
$env:CORE_TOOLS_URL = "https://functionsclibuilds.blob.core.windows.net/builds/3/latest/Azure.Functions.Cli.win-x86.zip"
27+
}
28+
Write-Host "CORE_TOOLS_URL: $env:CORE_TOOLS_URL"
29+
$output = "$currDir\Azure.Functions.Cli.zip"
30+
$wc = New-Object System.Net.WebClient
31+
$wc.DownloadFile($env:CORE_TOOLS_URL, $output)
32+
33+
Write-Host "Extracting Functions Core Tools...."
34+
Expand-Archive ".\Azure.Functions.Cli.zip" -DestinationPath ".\Azure.Functions.Cli"
35+
}
36+
Write-Host "Copying azure-functions-java-worker to Functions Host workers directory...."
37+
Get-ChildItem -Path .\target\* -Include 'azure*' -Exclude '*shaded.jar','*tests.jar' | %{ Copy-Item $_.FullName ".\Azure.Functions.Cli\workers\java\azure-functions-java-worker.jar" }
38+
Copy-Item ".\worker.config.json" ".\Azure.Functions.Cli\workers\java"
39+

0 commit comments

Comments
 (0)