diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Constants.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Constants.cs index 4a0ecb63..552d8cc1 100644 --- a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Constants.cs +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Constants.cs @@ -96,5 +96,8 @@ public static class Constants // SQL Binding tests public static string SqlConnectionStringSetting = Environment.GetEnvironmentVariable("AzureWebJobsSqlConnectionString"); + + // MySql tests + public static string MySqlConnectionStringSetting = Environment.GetEnvironmentVariable("AzureWebJobsMySqlConnectionString"); } } diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/MySqlEndToEndTests.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/MySqlEndToEndTests.cs new file mode 100644 index 00000000..c84f1180 --- /dev/null +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/MySqlEndToEndTests.cs @@ -0,0 +1,44 @@ +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Net; +using System.Threading; +using System.Threading.Tasks; +using Xunit; + +namespace Azure.Functions.Java.Tests.E2E +{ + [Collection(Constants.FunctionAppCollectionName)] + public class MySqlEndToEndTests + { + private readonly FunctionAppFixture _fixture; + + public MySqlEndToEndTests(FunctionAppFixture fixture) + { + this._fixture = fixture; + } + + [Fact] + public async Task MySqlInput_Output_Succeeds() + { + TimeSpan t = DateTime.UtcNow - new DateTime(1970, 1, 1); + int id = (int) t.TotalSeconds; + var product = new Dictionary() + { + { "ProductId", id }, + { "Name", "test" }, + { "Cost", 100 } + }; + + var productString = JsonConvert.SerializeObject(product); + // Insert a row into Products table using MySqlOutput + Assert.True(await Utilities.InvokeHttpTriggerPost("AddProduct", productString, HttpStatusCode.OK)); + + // Read row from Products table using MySqlInput + Assert.True(await Utilities.InvokeHttpTrigger("GetProducts", "/" + id.ToString(), HttpStatusCode.OK, productString)); + } + } +} \ No newline at end of file diff --git a/endtoendtests/local.settings.json b/endtoendtests/local.settings.json index 5d4d5201..757e47eb 100644 --- a/endtoendtests/local.settings.json +++ b/endtoendtests/local.settings.json @@ -18,6 +18,7 @@ "AzureWebJobsEventGridOutputBindingTopicUriString": "", "AzureWebJobsEventGridOutputBindingTopicKeyString": "", "AzureWebJobsSqlConnectionString": "", + "AzureWebJobsMySqlConnectionString": "", "FUNCTIONS_WORKER_RUNTIME": "java" } } diff --git a/endtoendtests/pom.xml b/endtoendtests/pom.xml index fce74258..acc00b0f 100644 --- a/endtoendtests/pom.xml +++ b/endtoendtests/pom.xml @@ -24,6 +24,7 @@ 1.18.0 3.1.0 2.1.0 + 1.0.2 1.0.0-beta.1 azure-functions-java-endtoendtests westus @@ -69,6 +70,11 @@ com.microsoft.azure.functions azure-functions-java-library-sql ${azure.functions.java.library.sql.version} + + + com.microsoft.azure.functions + azure-functions-java-library-mysql + ${azure.functions.java.library.mysql.version} com.microsoft diff --git a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/MySqlTriggerTests.java b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/MySqlTriggerTests.java new file mode 100644 index 00000000..7335d2ae --- /dev/null +++ b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/MySqlTriggerTests.java @@ -0,0 +1,62 @@ +package com.microsoft.azure.functions.endtoend; + +import com.microsoft.azure.functions.annotation.*; +import com.google.gson.Gson; +import com.microsoft.azure.functions.*; +import com.microsoft.azure.functions.HttpMethod; +import com.microsoft.azure.functions.mysql.annotation.CommandType; +import com.microsoft.azure.functions.mysql.annotation.MySqlInput; +import com.microsoft.azure.functions.mysql.annotation.MySqlOutput; +import com.microsoft.azure.functions.mysql.annotation.MySqlTrigger; + +import java.io.IOException; +import java.lang.reflect.Array; +import java.util.*; + +/** + * Azure Functions with Azure MySql Database. + */ +public class MySqlTriggerTests { + + @FunctionName("GetProducts") + public HttpResponseMessage GetProducts(@HttpTrigger(name = "req", methods = { HttpMethod.GET, + HttpMethod.POST }, route = "getproducts/{productid}", authLevel = AuthorizationLevel.ANONYMOUS) + HttpRequestMessage> request, + @MySqlInput(name = "products", commandText = "SELECT TOP 1 * FROM Products WHERE ProductId = @ProductId", + commandType = CommandType.Text, parameters = "@ProductId={productid}", + connectionStringSetting = "AzureWebJobsMySqlConnectionString") Product[] products, + final ExecutionContext context) { + + context.getLogger().info("Java HTTP trigger processed a MySql Input Binding request."); + + if (products.length != 0) { + return request.createResponseBuilder(HttpStatus.OK).body(products[0].toString()).build(); + } else { + return request.createResponseBuilder(HttpStatus.INTERNAL_SERVER_ERROR) + .body("Did not find expected product in table Products").build(); + } + } + + @FunctionName("AddProduct") + public HttpResponseMessage AddProduct(@HttpTrigger(name = "req", methods = { HttpMethod.GET, + HttpMethod.POST }, authLevel = AuthorizationLevel.ANONYMOUS) HttpRequestMessage> request, + @MySqlOutput(name = "product", commandText = "Products", connectionStringSetting = "AzureWebJobsMySqlConnectionString") OutputBinding product, + final ExecutionContext context) { + context.getLogger().info("Java HTTP trigger processed a MySql Output Binding request."); + + String json = request.getBody().get(); + product.setValue(new Gson().fromJson(json, Product.class)); + + return request.createResponseBuilder(HttpStatus.OK).body(product).build(); + } + + public class Product { + public int ProductId; + public String Name; + public int Cost; + + public String toString() { + return "{\"ProductId\":" + ProductId + ",\"Name\":\"" + Name + "\",\"Cost\":" + Cost + "}"; + } + } +} diff --git a/eng/ci/code-mirror.yml b/eng/ci/code-mirror.yml index 8ad6641e..278110d0 100644 --- a/eng/ci/code-mirror.yml +++ b/eng/ci/code-mirror.yml @@ -3,7 +3,7 @@ trigger: include: - dev - release/* # azure-functions-java-worker github repo restricts creation of release/* branches, so using a pattern is safe here. - + - heenagupta/mysqlextensiontests resources: repositories: - repository: eng diff --git a/eng/ci/templates/official/jobs/run-e2e-tests-linux.yml b/eng/ci/templates/official/jobs/run-e2e-tests-linux.yml index 368007c9..936999c8 100644 --- a/eng/ci/templates/official/jobs/run-e2e-tests-linux.yml +++ b/eng/ci/templates/official/jobs/run-e2e-tests-linux.yml @@ -109,6 +109,7 @@ jobs: AzureWebJobsStorage: $(AzureWebJobsStorage) AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString) AzureWebJobsSqlConnectionString: $(AzureWebJobsSqlConnectionString) + AzureWebJobsMySqlConnectionString: $(AzureWebJobsMySqlConnectionString) AzureWebJobsServiceBus: $(AzureWebJobsServiceBus) AzureWebJobsEventHubReceiver: $(AzureWebJobsEventHubReceiver) AzureWebJobsEventHubSender_2: $(AzureWebJobsEventHubSender_2) diff --git a/eng/ci/templates/official/jobs/run-e2e-tests-windows.yml b/eng/ci/templates/official/jobs/run-e2e-tests-windows.yml index df27ff58..0c130319 100644 --- a/eng/ci/templates/official/jobs/run-e2e-tests-windows.yml +++ b/eng/ci/templates/official/jobs/run-e2e-tests-windows.yml @@ -94,6 +94,7 @@ jobs: AzureWebJobsStorage: $(AzureWebJobsStorage) AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString) AzureWebJobsSqlConnectionString: $(AzureWebJobsSqlConnectionString) + AzureWebJobsMySqlConnectionString: $(AzureWebJobsMySqlConnectionString) AzureWebJobsServiceBus: $(AzureWebJobsServiceBus) AzureWebJobsEventHubReceiver: $(AzureWebJobsEventHubReceiver) AzureWebJobsEventHubSender_2: $(AzureWebJobsEventHubSender_2)