Skip to content

Tests for MySql Extensions #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 12 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
Original file line number Diff line number Diff line change
@@ -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<string, object>()
{
{ "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));
}
}
}
1 change: 1 addition & 0 deletions endtoendtests/local.settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"AzureWebJobsEventGridOutputBindingTopicUriString": "",
"AzureWebJobsEventGridOutputBindingTopicKeyString": "",
"AzureWebJobsSqlConnectionString": "",
"AzureWebJobsMySqlConnectionString": "",
"FUNCTIONS_WORKER_RUNTIME": "java"
}
}
6 changes: 6 additions & 0 deletions endtoendtests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
<azure.functions.maven.plugin.version>1.18.0</azure.functions.maven.plugin.version>
<azure.functions.java.library.version>3.1.0</azure.functions.java.library.version>
<azure.functions.java.library.sql.version>2.1.0</azure.functions.java.library.sql.version>
<azure.functions.java.library.mysql.version>1.0.2</azure.functions.java.library.mysql.version>
<durabletask.azure.functions>1.0.0-beta.1</durabletask.azure.functions>
<functionAppName>azure-functions-java-endtoendtests</functionAppName>
<functionAppRegion>westus</functionAppRegion>
Expand Down Expand Up @@ -69,6 +70,11 @@
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library-sql</artifactId>
<version>${azure.functions.java.library.sql.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library-mysql</artifactId>
<version>${azure.functions.java.library.mysql.version}</version>
</dependency>
<dependency>
<groupId>com.microsoft</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Optional<String>> 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<Optional<String>> request,
@MySqlOutput(name = "product", commandText = "Products", connectionStringSetting = "AzureWebJobsMySqlConnectionString") OutputBinding<Product> 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 + "}";
}
}
}
2 changes: 1 addition & 1 deletion eng/ci/code-mirror.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Contributor

@manvkaur manvkaur Apr 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't be checked-in

resources:
repositories:
- repository: eng
Expand Down
1 change: 1 addition & 0 deletions eng/ci/templates/official/jobs/run-e2e-tests-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ jobs:
AzureWebJobsStorage: $(AzureWebJobsStorage)
AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString)
AzureWebJobsSqlConnectionString: $(AzureWebJobsSqlConnectionString)
AzureWebJobsMySqlConnectionString: $(AzureWebJobsMySqlConnectionString)
AzureWebJobsServiceBus: $(AzureWebJobsServiceBus)
AzureWebJobsEventHubReceiver: $(AzureWebJobsEventHubReceiver)
AzureWebJobsEventHubSender_2: $(AzureWebJobsEventHubSender_2)
Expand Down
1 change: 1 addition & 0 deletions eng/ci/templates/official/jobs/run-e2e-tests-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ jobs:
AzureWebJobsStorage: $(AzureWebJobsStorage)
AzureWebJobsCosmosDBConnectionString: $(AzureWebJobsCosmosDBConnectionString)
AzureWebJobsSqlConnectionString: $(AzureWebJobsSqlConnectionString)
AzureWebJobsMySqlConnectionString: $(AzureWebJobsMySqlConnectionString)
AzureWebJobsServiceBus: $(AzureWebJobsServiceBus)
AzureWebJobsEventHubReceiver: $(AzureWebJobsEventHubReceiver)
AzureWebJobsEventHubSender_2: $(AzureWebJobsEventHubSender_2)
Expand Down
Loading