From f28821baff32dd1c8ff1b61d5317e3a53c86d62e Mon Sep 17 00:00:00 2001 From: Maddy Koripalli Date: Wed, 12 Apr 2023 12:41:16 -0700 Subject: [PATCH 1/6] enable the TriggerWithException test --- test-outofproc/TriggerWithException.cs | 6 ++-- .../SqlTriggerBindingIntegrationTests.cs | 8 +++-- .../com/function/TriggerWithException.java | 31 +++++++++++++++++++ 3 files changed, 40 insertions(+), 5 deletions(-) create mode 100644 test/Integration/test-java/src/main/java/com/function/TriggerWithException.java diff --git a/test-outofproc/TriggerWithException.cs b/test-outofproc/TriggerWithException.cs index 928bcd5d3..ce5ad11f0 100644 --- a/test-outofproc/TriggerWithException.cs +++ b/test-outofproc/TriggerWithException.cs @@ -14,6 +14,7 @@ public static class TriggerWithException { public const string ExceptionMessage = "TriggerWithException test exception"; private static bool threwException = false; + private static readonly Action _loggerMessage = LoggerMessage.Define(LogLevel.Information, eventId: new EventId(0, "INFO"), formatString: "{Message}"); /// /// Used in verification that exceptions thrown by functions cause the trigger to retry calling the function @@ -23,14 +24,15 @@ public static class TriggerWithException public static void Run( [SqlTrigger("[dbo].[Products]", "SqlConnectionString")] IReadOnlyList> changes, - ILogger logger) + FunctionContext context) { if (!threwException) { threwException = true; throw new InvalidOperationException(ExceptionMessage); } - logger.LogInformation("SQL Changes: " + Utils.JsonSerializeObject(changes)); + _loggerMessage(context.GetLogger("TriggerWithException"), "SQL Changes: " + Utils.JsonSerializeObject(changes), null); + } } } diff --git a/test/Integration/SqlTriggerBindingIntegrationTests.cs b/test/Integration/SqlTriggerBindingIntegrationTests.cs index 431af210f..715c87c98 100644 --- a/test/Integration/SqlTriggerBindingIntegrationTests.cs +++ b/test/Integration/SqlTriggerBindingIntegrationTests.cs @@ -588,11 +588,13 @@ public void UnsupportedDatabaseThrows(SupportedLanguages lang) /// /// Tests that when a user function throws an exception we'll retry executing that function once the lease timeout expires /// - [Fact] - public async Task FunctionExceptionsCauseRetry() + [Theory] + [SqlInlineData()] + [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.CSharpscript)] //Static state threwException is only valid for C# and Java. + public async Task FunctionExceptionsCauseRetry(SupportedLanguages lang) { this.SetChangeTrackingForTable("Products"); - this.StartFunctionHost(nameof(TriggerWithException), SupportedLanguages.CSharp, true); + this.StartFunctionHost(nameof(TriggerWithException), lang, true); TaskCompletionSource taskCompletionSource = new(); void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e) { diff --git a/test/Integration/test-java/src/main/java/com/function/TriggerWithException.java b/test/Integration/test-java/src/main/java/com/function/TriggerWithException.java new file mode 100644 index 000000000..6fc784270 --- /dev/null +++ b/test/Integration/test-java/src/main/java/com/function/TriggerWithException.java @@ -0,0 +1,31 @@ +/** + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for + * license information. + */ + +package com.function; + +import com.microsoft.azure.functions.ExecutionContext; +import com.microsoft.azure.functions.annotation.FunctionName; +import com.microsoft.azure.functions.sql.annotation.SQLTrigger; +import com.function.Common.SqlChangeProduct; +import com.google.gson.Gson; +import java.util.logging.Level; + +public class TriggerWithException { + public final String ExceptionMessage = "TriggerWithException test exception"; + private static Boolean threwException = false; + + @FunctionName("TriggerWithException") + public void run( + @SQLTrigger(name = "changes", tableName = "[dbo].[Products]", connectionStringSetting = "SqlConnectionString") SqlChangeProduct[] changes, + ExecutionContext context) throws Exception { + + if (!threwException) { + threwException = true; + throw new Exception(ExceptionMessage); + } + context.getLogger().log(Level.INFO, "SQL Changes: " + new Gson().toJson(changes)); + } +} From e3d08c29387a0d947ea70935d54c1203fb31bf93 Mon Sep 17 00:00:00 2001 From: Maddy Koripalli Date: Fri, 14 Apr 2023 11:35:18 -0700 Subject: [PATCH 2/6] update comment --- test/Integration/SqlTriggerBindingIntegrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Integration/SqlTriggerBindingIntegrationTests.cs b/test/Integration/SqlTriggerBindingIntegrationTests.cs index 715c87c98..535b2e1f9 100644 --- a/test/Integration/SqlTriggerBindingIntegrationTests.cs +++ b/test/Integration/SqlTriggerBindingIntegrationTests.cs @@ -590,7 +590,7 @@ public void UnsupportedDatabaseThrows(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.CSharpscript)] //Static state threwException is only valid for C# and Java. + [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.CSharpscript)] // Keeping static state for threwException across calls is only valid for C# and Java. public async Task FunctionExceptionsCauseRetry(SupportedLanguages lang) { this.SetChangeTrackingForTable("Products"); From 7ee8edabf91e08ab1f39f83e733ffa75e583f1a8 Mon Sep 17 00:00:00 2001 From: Maddy Koripalli Date: Tue, 18 Apr 2023 10:34:48 -0700 Subject: [PATCH 3/6] remove logger delegate --- test-outofproc/TriggerWithException.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test-outofproc/TriggerWithException.cs b/test-outofproc/TriggerWithException.cs index ce5ad11f0..6f4560ad2 100644 --- a/test-outofproc/TriggerWithException.cs +++ b/test-outofproc/TriggerWithException.cs @@ -14,7 +14,6 @@ public static class TriggerWithException { public const string ExceptionMessage = "TriggerWithException test exception"; private static bool threwException = false; - private static readonly Action _loggerMessage = LoggerMessage.Define(LogLevel.Information, eventId: new EventId(0, "INFO"), formatString: "{Message}"); /// /// Used in verification that exceptions thrown by functions cause the trigger to retry calling the function @@ -26,12 +25,13 @@ public static void Run( IReadOnlyList> changes, FunctionContext context) { + ILogger logger = context.GetLogger("TriggerWithException"); if (!threwException) { threwException = true; throw new InvalidOperationException(ExceptionMessage); } - _loggerMessage(context.GetLogger("TriggerWithException"), "SQL Changes: " + Utils.JsonSerializeObject(changes), null); + logger.LogInformation("SQL Changes: " + Utils.JsonSerializeObject(changes)); } } From 0b6466b19d9470659f0f3926cd2bb194c6a046e5 Mon Sep 17 00:00:00 2001 From: maddydev Date: Fri, 28 Apr 2023 14:34:58 -0700 Subject: [PATCH 4/6] fix error --- test/Integration/SqlTriggerBindingIntegrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Integration/SqlTriggerBindingIntegrationTests.cs b/test/Integration/SqlTriggerBindingIntegrationTests.cs index acba20db5..773e99ef5 100644 --- a/test/Integration/SqlTriggerBindingIntegrationTests.cs +++ b/test/Integration/SqlTriggerBindingIntegrationTests.cs @@ -579,7 +579,7 @@ public void UnsupportedDatabaseThrows(SupportedLanguages lang) /// [Theory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.CSharpscript)] // Keeping static state for threwException across calls is only valid for C# and Java. + [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.Csx)] // Keeping static state for threwException across calls is only valid for C# and Java. public async Task FunctionExceptionsCauseRetry(SupportedLanguages lang) { this.SetChangeTrackingForTable("Products"); From cd1c857fa2196ec2fe17093e4671288f08e42624 Mon Sep 17 00:00:00 2001 From: Maddy Koripalli Date: Thu, 4 May 2023 15:54:48 -0700 Subject: [PATCH 5/6] add retry --- test/Integration/SqlTriggerBindingIntegrationTests.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/Integration/SqlTriggerBindingIntegrationTests.cs b/test/Integration/SqlTriggerBindingIntegrationTests.cs index 19a929f92..3a0453e1c 100644 --- a/test/Integration/SqlTriggerBindingIntegrationTests.cs +++ b/test/Integration/SqlTriggerBindingIntegrationTests.cs @@ -578,13 +578,13 @@ public void UnsupportedDatabaseThrows(SupportedLanguages lang) /// /// Tests that when a user function throws an exception we'll retry executing that function once the lease timeout expires /// - [Theory] + [RetryTheory] [SqlInlineData()] [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.Csx)] // Keeping static state for threwException across calls is only valid for C# and Java. public async Task FunctionExceptionsCauseRetry(SupportedLanguages lang) { this.SetChangeTrackingForTable("Products"); - this.StartFunctionHost(nameof(TriggerWithException), lang, true); + this.StartFunctionHost(nameof(TriggerWithException), lang, useTestFolder: true); TaskCompletionSource taskCompletionSource = new(); void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e) { @@ -607,7 +607,7 @@ void TestExceptionMessageSeen(object sender, DataReceivedEventArgs e) (SqlTableChangeMonitor.LeaseIntervalInSeconds * 1000) + batchProcessingTimeout); // First wait for the exception message to show up - await taskCompletionSource.Task.TimeoutAfter(TimeSpan.FromMilliseconds(this.GetBatchProcessingTimeout(1, 30)), "Timed out waiting for exception message"); + await taskCompletionSource.Task.TimeoutAfter(TimeSpan.FromMilliseconds(batchProcessingTimeout), "Timed out waiting for exception message"); // Now wait for the retry to occur and successfully pass await changesTask; From 7ca0cd54a18407c5305c440c6aff15b5abff1801 Mon Sep 17 00:00:00 2001 From: Maddy Koripalli Date: Wed, 10 May 2023 11:02:36 -0700 Subject: [PATCH 6/6] remove Java test and try --- test/Integration/SqlTriggerBindingIntegrationTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Integration/SqlTriggerBindingIntegrationTests.cs b/test/Integration/SqlTriggerBindingIntegrationTests.cs index 3a0453e1c..4d735b409 100644 --- a/test/Integration/SqlTriggerBindingIntegrationTests.cs +++ b/test/Integration/SqlTriggerBindingIntegrationTests.cs @@ -580,7 +580,7 @@ public void UnsupportedDatabaseThrows(SupportedLanguages lang) /// [RetryTheory] [SqlInlineData()] - [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.Csx)] // Keeping static state for threwException across calls is only valid for C# and Java. + [UnsupportedLanguages(SupportedLanguages.JavaScript, SupportedLanguages.Python, SupportedLanguages.PowerShell, SupportedLanguages.Csx, SupportedLanguages.Java)] // Keeping static state for threwException across calls is only valid for C# and Java. public async Task FunctionExceptionsCauseRetry(SupportedLanguages lang) { this.SetChangeTrackingForTable("Products");