From cfe89de367063a14f306aeac6c35dcd0ecd0895a Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Tue, 16 Jul 2019 16:53:20 -0700 Subject: [PATCH 01/14] Introduce new TypedData types - Support CollectionSting, CollectionLong, CollectionDouble, CollectionByte[] --- .../Constants.cs | 9 ++++ .../EventHubsEndToEndTests.cs | 49 +++++++++++++++++++ .../endtoend/EventHubTriggerTests.java | 23 +++++++++ .../src/proto/FunctionRpc.proto | 26 +++++++++- .../worker/binding/BindingDataStore.java | 7 ++- .../RpcCollectionByteArrayDataSource.java | 48 ++++++++++++++++++ .../RpcCollectionDoubleDataSource.java | 44 +++++++++++++++++ .../binding/RpcCollectionLongDataSource.java | 43 ++++++++++++++++ .../RpcCollectionStringDataSource.java | 38 ++++++++++++++ .../handler/WorkerInitRequestHandler.java | 1 + 10 files changed, 285 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java create mode 100644 src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java create mode 100644 src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java create mode 100644 src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java 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 a6aec7a6..75cb7ac6 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 @@ -37,10 +37,19 @@ public static class Constants // EventHubs public static string OutputEventHubQueueName = "test-eventhuboutput-java"; public static string InputEventHubName = "test-input-java"; + public static string OutputJsonEventHubQueueName = "test-eventhuboutputjson-java"; public static string InputJsonEventHubName = "test-inputjson-java"; + public static string OutputOneEventHubQueueName = "test-eventhuboutputone-java"; public static string InputCardinalityOneEventHubName = "test-inputOne-java"; + + public static string OutputBinaryOneEventHubQueueName = "test-outputone-java-cardinality-one"; + public static string InputBinaryOneEventHubQueueName = "test-inputone-java-cardinality-one"; + + public static string OutputBinaryManyEventHubQueueName = "test-outputbinary-java-cardinality-many"; + public static string InputBinaryManyEventHubQueueName = "test-inputbinary-java-cardinality-many"; + public static string EventHubsConnectionStringSetting = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender"); // Xunit Fixtures and Collections diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs index 6e1ec187..ad871a7b 100644 --- a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs @@ -87,6 +87,55 @@ public async Task EventHubTriggerCardinalityOne_Succeeds() } } + + [Fact] + public async Task EventHubTriggerAndOutputBinaryMany_Succeeds() + { + string expectedEventId = Guid.NewGuid().ToString(); + try + { + await SetupQueue(Constants.OutputBinaryManyEventHubQueueName); + + // Need to setup EventHubs: test-input-java and test-output-java + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyEventHubQueueName); + + //Verify + var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryManyEventHubQueueName); + Assert.Contains(expectedEventId, queueMessage); + } + catch (Exception ex) + { + + } + finally + { + //Clear queue + await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); + } + } + + [Fact] + public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() + { + string expectedEventId = Guid.NewGuid().ToString(); + try + { + await SetupQueue(Constants.OutputBinaryOneEventHubQueueName); + + // Need to setup EventHubs: test-input-java and test-output-java + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryOneEventHubQueueName); + + //Verify + var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryOneEventHubQueueName); + Assert.Contains(expectedEventId, queueMessage); + } + finally + { + //Clear queue + await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); + } + } + private static async Task SetupQueue(string queueName) { //Clear queue diff --git a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java index a2e9efdb..e672bc1d 100644 --- a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java +++ b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java @@ -77,6 +77,29 @@ public void TestEventHubOutputInputOne( output.setValue(message); } + @FunctionName("EventHubTriggerAndOutputBinaryCardinalityMany") + public void EventHubTriggerAndOutputBinaryCardinalityMany( + @EventHubTrigger(name = "messages", eventHubName = "test-inputbinary-java-cardinality-many", connection = "AzureWebJobsEventHubSender", dataType = "string", cardinality = Cardinality.MANY) byte[][] messages, + @EventHubOutput(name = "output", eventHubName = "test-outputbinary-java-cardinality-many", connection = "AzureWebJobsEventHubSender") OutputBinding output, + final ExecutionContext context + ) { +// context.getLogger().info("Java Event Hub trigger received " + messages.size() +" messages"); +// Byte[] test = messages.get(0); +// output.setValue(messages.get(0)); + + + } + + @FunctionName("EventHubTriggerAndOutputBinaryCardinalityOne") + public void EventHubTriggerAndOutputBinaryCardinalityOne( + @EventHubTrigger(name = "message", eventHubName = "test-inputone-java-cardinality-one", connection = "AzureWebJobsEventHubSender", dataType = "binary", cardinality = Cardinality.ONE) byte[] message, + @EventHubOutput(name = "output", eventHubName = "test-outputone-java-cardinality-one", connection = "AzureWebJobsEventHubSender", dataType = "binary") OutputBinding output, + final ExecutionContext context + ) { + context.getLogger().info("Java Event Hub trigger received message" + message); + output.setValue(message); + } + public static class SystemProperty { public String SequenceNumber; public String Offset; diff --git a/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto b/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto index 44857b8b..77a60504 100644 --- a/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto +++ b/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto @@ -278,11 +278,35 @@ message TypedData { bytes bytes = 3; bytes stream = 4; RpcHttp http = 5; - sint64 int = 6; + sint64 int = 6; double double = 7; + TypedDataCollectionBytes collection_bytes = 8; + TypedDataCollectionString collection_string = 9; + TypedDataCollectionDouble collection_double = 10; + TypedDataCollectionSInt64 collection_sint64 = 11; } } +// Used to encapsulate collection typedata string which could be a variety of types +message TypedDataCollectionString { + repeated string string = 1; +} + +// Used to encapsulate collection typedata bytes which could be a variety of types +message TypedDataCollectionBytes { + repeated bytes bytes = 1; +} + +// Used to encapsulate collection typedata double which could be a variety of types +message TypedDataCollectionDouble { + repeated double double = 1; +} + +// Used to encapsulate collection typedata sint64 which could be a variety of types +message TypedDataCollectionSInt64 { + repeated sint64 sint64 = 1; +} + // Used to describe a given binding on invocation message ParameterBinding { // Name for the binding diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/BindingDataStore.java b/src/main/java/com/microsoft/azure/functions/worker/binding/BindingDataStore.java index 5c3e8237..7539747a 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/BindingDataStore.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/BindingDataStore.java @@ -1,6 +1,5 @@ package com.microsoft.azure.functions.worker.binding; -import java.io.IOException; import java.lang.reflect.*; import java.util.*; @@ -35,7 +34,7 @@ public void addParameterSources(List parameters) { } public void addTriggerMetadataSource(Map metadata) { - for (Map.Entry entry : metadata.entrySet()) + for (Map.Entry entry : metadata.entrySet()) { DataSource inputValue = rpcSourceFromTypedData(entry.getKey(), entry.getValue()); this.metadataSources.put(entry.getKey(), inputValue); @@ -66,6 +65,10 @@ static DataSource rpcSourceFromTypedData(String name, TypedData data) { case BYTES: return new RpcByteArrayDataSource(name, data.getBytes()); case JSON: return new RpcJsonDataSource(name, data.getJson()); case HTTP: return new RpcHttpRequestDataSource(name, data.getHttp()); + case COLLECTION_STRING: return new RpcCollectionStringDataSource(name, data.getCollectionString()); + case COLLECTION_DOUBLE: return new RpcCollectionDoubleDataSource(name, data.getCollectionDouble()); + case COLLECTION_BYTES: return new RpcCollectionByteArrayDataSource(name, data.getCollectionBytes()); + case COLLECTION_SINT64: return new RpcCollectionLongDataSource(name, data.getCollectionSint64()); case DATA_NOT_SET: return new RpcEmptyDataSource(name); default: throw new UnsupportedOperationException("Input data type \"" + data.getDataCase() + "\" is not supported"); } diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java new file mode 100644 index 00000000..8f223991 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java @@ -0,0 +1,48 @@ +package com.microsoft.azure.functions.worker.binding; + +import com.google.protobuf.ByteString; +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionBytes; +import org.apache.commons.lang3.ArrayUtils; +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; + +public final class RpcCollectionByteArrayDataSource extends DataSource> { + public RpcCollectionByteArrayDataSource(String name, TypedDataCollectionBytes value) { + super(name, value.getBytesList(), COLLECTION_DATA_OPERATIONS); + } + private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); + + public static Object convertToByteList(List sourceValue, Type targetType) { + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == byte[].class) { + return sourceValue.stream().map(element -> element.toByteArray()).collect(Collectors.toCollection(ArrayList::new)); + } else if (targetActualType == Byte[].class) { + return sourceValue.stream().map(element -> (ArrayUtils.toObject(element.toByteArray()))).collect(Collectors.toList()); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + + public static Object convertToByteListDefault(List sourceValue, Type targetType) { + return sourceValue.stream().map(element -> (ArrayUtils.toObject(element.toByteArray()))).collect(Collectors.toList()); + } + + public static Object convertToBytesArray(List sourceValue, Type targetType) { + return sourceValue.stream().map(element -> element.toByteArray()).collect(Collectors.toCollection(ArrayList::new)).toArray(new byte[0][]); + } + + public static Object convertToBytesObjectArray(List sourceValue, Type targetType) { + return sourceValue.stream().map(element -> (ArrayUtils.toObject(element.toByteArray()))).collect(Collectors.toCollection(ArrayList::new)).toArray(new Byte[0][]); + } + + static { + COLLECTION_DATA_OPERATIONS.addGenericOperation(List.class, (v, t) -> convertToByteList(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(byte[][].class, (v, t) -> convertToBytesArray(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(Byte[][].class, (v, t) -> convertToBytesObjectArray(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(String.class, (v, t) -> convertToByteListDefault(v, t)); + } +} + diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java new file mode 100644 index 00000000..387b4dac --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java @@ -0,0 +1,44 @@ +package com.microsoft.azure.functions.worker.binding; + +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble; +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; + +import java.lang.reflect.Array; +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +public final class RpcCollectionDoubleDataSource extends DataSource> { + public RpcCollectionDoubleDataSource(String name, TypedDataCollectionDouble value) { + super(name, value.getDoubleList(), COLLECTION_DATA_OPERATIONS); + } + private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); + + public static Object convertToDoubleListDefault(List sourceValue, Type targetType) { + return new ArrayList<>(sourceValue); + } + + public static Object convertToDoubleList(List sourceValue, Type targetType) { + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == Double.class) { + return new ArrayList<>(sourceValue); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + + public static Object convertToDoubleObjectArray(List sourceValue, Type targetType) { + return new ArrayList<>(sourceValue).toArray(new Double[0]); + } + + public static Object convertToDoubleArray(List sourceValue, Type targetType) { + return sourceValue.stream().mapToDouble(Double::doubleValue).toArray(); + } + + static { + COLLECTION_DATA_OPERATIONS.addGenericOperation(List.class, (v, t) -> convertToDoubleList(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(Double[].class, (v, t) -> convertToDoubleObjectArray(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(double[].class, (v, t) -> convertToDoubleArray(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(String.class, (v, t) -> convertToDoubleListDefault(v, t)); + } +} + diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java new file mode 100644 index 00000000..745e3ce4 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java @@ -0,0 +1,43 @@ +package com.microsoft.azure.functions.worker.binding; + +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionSInt64; +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +public final class RpcCollectionLongDataSource extends DataSource> { + public RpcCollectionLongDataSource(String name, TypedDataCollectionSInt64 value) { + super(name, value.getSint64List(), COLLECTION_DATA_OPERATIONS); + } + private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); + + public static Object convertToLongList(List sourceValue, Type targetType) { + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == Long.class) { + return new ArrayList<>(sourceValue); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + + public static Object convertToLongListDefault(List sourceValue, Type targetType) { + return new ArrayList<>(sourceValue); + } + + public static Object convertToLongObjectArray(List sourceValue, Type targetType) { + return new ArrayList<>(sourceValue).toArray(new Long[0]); + } + + public static Object convertToLongArray(List sourceValue, Type targetType) { + return sourceValue.stream().mapToLong(Long::longValue).toArray(); + } + + static { + COLLECTION_DATA_OPERATIONS.addGenericOperation(List.class, (v, t) -> convertToLongList(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(Long[].class, (v, t) -> convertToLongObjectArray(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(long[].class, (v, t) -> convertToLongArray(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(String.class, (v, t) -> convertToLongListDefault(v, t)); + } +} + diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java new file mode 100644 index 00000000..44694ba9 --- /dev/null +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java @@ -0,0 +1,38 @@ +package com.microsoft.azure.functions.worker.binding; + +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionString; +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; + +import java.lang.reflect.Type; +import java.util.ArrayList; +import java.util.List; + +public final class RpcCollectionStringDataSource extends DataSource> { + public RpcCollectionStringDataSource(String name, TypedDataCollectionString value) { + super(name, value.getStringList(), COLLECTION_DATA_OPERATIONS); + } + private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); + + public static Object convertToStringList(List sourceValue, Type targetType) { + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == String.class) { + return new ArrayList<>(sourceValue); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + + public static Object convertToStringArray(List sourceValue, Type targetType) { + return new ArrayList<>(sourceValue).toArray(new String[0]); + } + + public static Object convertToStringListDefault(List sourceValue, Type targetType) { + return new ArrayList<>(sourceValue); + } + + static { + COLLECTION_DATA_OPERATIONS.addGenericOperation(List.class, (v, t) -> convertToStringList(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(String[].class, (v, t) -> convertToStringArray(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(String.class, (v, t) -> convertToStringListDefault(v, t)); + } +} + diff --git a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java index eb896390..7075fb55 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java +++ b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java @@ -14,6 +14,7 @@ public WorkerInitRequestHandler() { @Override String execute(WorkerInitRequest request, WorkerInitResponse.Builder response) { response.setWorkerVersion(Application.version()); + response.putCapabilities("TYPED_DATA_COLLECTION_SUPPORTED", "TRUE"); return "Worker initialized"; } } From 8e8a0c2c8005d340a7fad985b00adc9e10277ed6 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Tue, 16 Jul 2019 22:14:18 -0700 Subject: [PATCH 02/14] Add test for collectionTypeData Add tests for CollectionString, CollectionDouble, CollectionLong, CollectionByte[] --- .../endtoend/EventHubTriggerTests.java | 2 +- .../RpcCollectionByteArrayDataSource.java | 18 +- .../RpcCollectionDoubleDataSource.java | 12 +- .../binding/RpcCollectionLongDataSource.java | 12 +- .../RpcCollectionStringDataSource.java | 12 +- .../RpcCollectionByteArrayDataSourceTest.java | 167 ++++++++++++++++++ .../RpcCollectionDoubleDataSourceTest.java | 128 ++++++++++++++ .../RpcCollectionLongDataSourceTest.java | 130 ++++++++++++++ .../RpcCollectionStringDataSourceTest.java | 108 +++++++++++ .../worker/binding/tests/Utility.java | 13 ++ 10 files changed, 586 insertions(+), 16 deletions(-) create mode 100644 src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java create mode 100644 src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java create mode 100644 src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java create mode 100644 src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java create mode 100644 src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java diff --git a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java index e672bc1d..240e7aae 100644 --- a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java +++ b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java @@ -79,7 +79,7 @@ public void TestEventHubOutputInputOne( @FunctionName("EventHubTriggerAndOutputBinaryCardinalityMany") public void EventHubTriggerAndOutputBinaryCardinalityMany( - @EventHubTrigger(name = "messages", eventHubName = "test-inputbinary-java-cardinality-many", connection = "AzureWebJobsEventHubSender", dataType = "string", cardinality = Cardinality.MANY) byte[][] messages, + @EventHubTrigger(name = "messages", eventHubName = "test-inputbinary-java-cardinality-many", connection = "AzureWebJobsEventHubSender", dataType = "binary", cardinality = Cardinality.MANY) List messages, @EventHubOutput(name = "output", eventHubName = "test-outputbinary-java-cardinality-many", connection = "AzureWebJobsEventHubSender") OutputBinding output, final ExecutionContext context ) { diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java index 8f223991..350f36e2 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java @@ -17,17 +17,23 @@ public RpcCollectionByteArrayDataSource(String name, TypedDataCollectionBytes va private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); public static Object convertToByteList(List sourceValue, Type targetType) { - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; - if (targetActualType == byte[].class) { + if(targetType == List.class) { return sourceValue.stream().map(element -> element.toByteArray()).collect(Collectors.toCollection(ArrayList::new)); - } else if (targetActualType == Byte[].class) { - return sourceValue.stream().map(element -> (ArrayUtils.toObject(element.toByteArray()))).collect(Collectors.toList()); } - throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + else if(targetType instanceof ParameterizedTypeImpl){ + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == byte[].class) { + return sourceValue.stream().map(element -> element.toByteArray()).collect(Collectors.toCollection(ArrayList::new)); + } else if (targetActualType == Byte[].class) { + return sourceValue.stream().map(element -> (ArrayUtils.toObject(element.toByteArray()))).collect(Collectors.toList()); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + throw new UnsupportedOperationException("Input data type \"" + targetType + "\" is not supported"); } public static Object convertToByteListDefault(List sourceValue, Type targetType) { - return sourceValue.stream().map(element -> (ArrayUtils.toObject(element.toByteArray()))).collect(Collectors.toList()); + return sourceValue.stream().map(element -> element.toByteArray()).collect(Collectors.toCollection(ArrayList::new)); } public static Object convertToBytesArray(List sourceValue, Type targetType) { diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java index 387b4dac..9f59a582 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java @@ -19,11 +19,17 @@ public static Object convertToDoubleListDefault(List sourceValue, Type t } public static Object convertToDoubleList(List sourceValue, Type targetType) { - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; - if (targetActualType == Double.class) { + if(targetType == List.class) { return new ArrayList<>(sourceValue); } - throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + else if(targetType instanceof ParameterizedTypeImpl) { + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == Double.class) { + return new ArrayList<>(sourceValue); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + throw new UnsupportedOperationException("Input data type \"" + targetType + "\" is not supported"); } public static Object convertToDoubleObjectArray(List sourceValue, Type targetType) { diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java index 745e3ce4..e4f7627e 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java @@ -14,11 +14,17 @@ public RpcCollectionLongDataSource(String name, TypedDataCollectionSInt64 value) private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); public static Object convertToLongList(List sourceValue, Type targetType) { - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; - if (targetActualType == Long.class) { + if(targetType == List.class) { return new ArrayList<>(sourceValue); } - throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + else if(targetType instanceof ParameterizedTypeImpl) { + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == Long.class) { + return new ArrayList<>(sourceValue); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + throw new UnsupportedOperationException("Input data type \"" + targetType + "\" is not supported"); } public static Object convertToLongListDefault(List sourceValue, Type targetType) { diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java index 44694ba9..813b2587 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java @@ -14,11 +14,17 @@ public RpcCollectionStringDataSource(String name, TypedDataCollectionString valu private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); public static Object convertToStringList(List sourceValue, Type targetType) { - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; - if (targetActualType == String.class) { + if(targetType == List.class) { return new ArrayList<>(sourceValue); } - throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + else if(targetType instanceof ParameterizedTypeImpl) { + Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + if (targetActualType == String.class) { + return new ArrayList<>(sourceValue); + } + throw new UnsupportedOperationException("Input data type \"" + targetActualType + "\" is not supported"); + } + throw new UnsupportedOperationException("Input data type \"" + targetType + "\" is not supported"); } public static Object convertToStringArray(List sourceValue, Type targetType) { diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java new file mode 100644 index 00000000..997c6321 --- /dev/null +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java @@ -0,0 +1,167 @@ +package com.microsoft.azure.functions.worker.binding.tests; + +import com.google.protobuf.ByteString; +import com.microsoft.azure.functions.worker.binding.BindingData; +import com.microsoft.azure.functions.worker.binding.RpcCollectionByteArrayDataSource; +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionBytes; +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionBytes.Builder; + +import org.apache.commons.lang3.ArrayUtils; +import org.junit.Test; + +import java.lang.invoke.WrongMethodTypeException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; + +public class RpcCollectionByteArrayDataSourceTest { + @Test + public void rpcByteArrayDataSource_To_byte_Array() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + byte[] expctedStingBytes = expectedString.getBytes(); + ByteString inputByteString = ByteString.copyFrom(expctedStingBytes); + + List input = new ArrayList(); + input.add(inputByteString); + + Builder a = TypedDataCollectionBytes.newBuilder(); + a.addAllBytes(input); + + TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + + RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); + + Optional actualBindingData = stringData.computeByName(sourceKey, byte[][].class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + byte[][] actualBytes = (byte[][]) actualArg.getValue(); + String actualString = new String(actualBytes[0]); + assertEquals(actualString, expectedString); + } + + @Test + public void rpcByteArrayDataSource_To_Byte_Array() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + byte[] expctedStingBytes = expectedString.getBytes(); + ByteString inputByteString = ByteString.copyFrom(expctedStingBytes); + + List input = new ArrayList(); + input.add(inputByteString); + + Builder a = TypedDataCollectionBytes.newBuilder(); + a.addAllBytes(input); + + TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + + RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); + + Optional actualBindingData = stringData.computeByName(sourceKey, Byte[][].class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + Byte[][] actualBytes = (Byte[][]) actualArg.getValue(); + String actualString = new String(ArrayUtils.toPrimitive(actualBytes[0])); + assertEquals(actualString, expectedString); + } + + @Test + public void rpcByteArrayDataSource_default_To_List_byte() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + byte[] expctedStingBytes = expectedString.getBytes(); + ByteString inputByteString = ByteString.copyFrom(expctedStingBytes); + + List input = new ArrayList(); + input.add(inputByteString); + + Builder a = TypedDataCollectionBytes.newBuilder(); + a.addAllBytes(input); + + TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + + RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); + + Optional actualBindingData = stringData.computeByName(sourceKey, String.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualBytes = (List) actualArg.getValue(); + String actualString = new String(actualBytes.get(0)); + assertEquals(actualString, expectedString); + } + + @Test + public void rpcByteArrayDataSource_To_List_byte() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + byte[] expctedStingBytes = expectedString.getBytes(); + ByteString inputByteString = ByteString.copyFrom(expctedStingBytes); + + List input = new ArrayList(); + input.add(inputByteString); + + Builder a = TypedDataCollectionBytes.newBuilder(); + a.addAllBytes(input); + + TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + + RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); + + Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(byte[].class)); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualBytes = (List) actualArg.getValue(); + String actualString = new String(actualBytes.get(0)); + assertEquals(actualString, expectedString); + } + + @Test + public void rpcByteArrayDataSource_To_List_Byte() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + byte[] expctedStingBytes = expectedString.getBytes(); + ByteString inputByteString = ByteString.copyFrom(expctedStingBytes); + + List input = new ArrayList(); + input.add(inputByteString); + + Builder a = TypedDataCollectionBytes.newBuilder(); + a.addAllBytes(input); + + TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + + RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); + + Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(Byte[].class)); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualBytes = (List) actualArg.getValue(); + String actualString = new String(ArrayUtils.toPrimitive(actualBytes.get(0))); + assertEquals(actualString, expectedString); + } + + @Test + public void rpcByteArrayDataSource_No_Generic_To_List_byte() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + byte[] expctedStingBytes = expectedString.getBytes(); + ByteString inputByteString = ByteString.copyFrom(expctedStingBytes); + + List input = new ArrayList(); + input.add(inputByteString); + + Builder a = TypedDataCollectionBytes.newBuilder(); + a.addAllBytes(input); + + TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + + RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); + + Optional actualBindingData = stringData.computeByName(sourceKey, List.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualBytes = (List) actualArg.getValue(); + String actualString = new String(actualBytes.get(0)); + assertEquals(actualString, expectedString); + } + + + + +} diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java new file mode 100644 index 00000000..274b1464 --- /dev/null +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java @@ -0,0 +1,128 @@ + +package com.microsoft.azure.functions.worker.binding.tests; + + import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble; + import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble.Builder; + import com.microsoft.azure.functions.worker.binding.BindingData; + import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource; + import org.junit.Test; + + import java.lang.invoke.WrongMethodTypeException; + import java.util.ArrayList; + import java.util.List; + import java.util.Optional; + + import static org.junit.Assert.assertEquals; + +public class RpcCollectionDoubleDataSourceTest { + @Test + public void rpcCollectionDoubleDataSource_To_Double_Object_Array() { + String sourceKey = "sourceKey"; + Double expectedDouble = 1.1; + + List input = new ArrayList(); + input.add(expectedDouble); + + TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + a.addAllDouble(input); + + TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + + RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); + + Optional actualBindingData = data.computeByName(sourceKey, Double[].class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + Double[] actualDoublegArray = (Double[]) actualArg.getValue(); + Double actualDouble = actualDoublegArray[0]; + assertEquals(actualDouble, expectedDouble); + } + + @Test + public void rpcCollectionDoubleDataSource_To_double_Array() { + String sourceKey = "sourceKey"; + double expectedDouble = 1.1; + + List input = new ArrayList(); + input.add(expectedDouble); + + TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + a.addAllDouble(input); + + TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + + RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); + + Optional actualBindingData = data.computeByName(sourceKey, double[].class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + double[] actualDoubleArray = (double[]) actualArg.getValue(); + double actualDouble = actualDoubleArray[0]; + assertEquals("" + actualDouble, "" + expectedDouble); + } + + @Test + public void rpcCollectionDoubleDataSource_default_To_List_Double() { + String sourceKey = "sourceKey"; + Double expectedDouble = 1.1; + + List input = new ArrayList(); + input.add(expectedDouble); + + TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + a.addAllDouble(input); + + TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + + RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); + + Optional actualBindingData = data.computeByName(sourceKey, String.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualDoubleList = (List) actualArg.getValue(); + Double actualLong = actualDoubleList.get(0); + assertEquals(actualLong, expectedDouble); + } + + @Test + public void rpcCollectionDoubleDataSource_To_List_Double() { + String sourceKey = "sourceKey"; + Double expectedDouble = 1.1; + + List input = new ArrayList(); + input.add(expectedDouble); + + TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + a.addAllDouble(input); + + TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + + RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); + + Optional actualBindingData = data.computeByName(sourceKey, Utility.getActualType(Double[].class)); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualDoubleList = (List) actualArg.getValue(); + Double actualLong = actualDoubleList.get(0); + assertEquals(actualLong, expectedDouble); + } + + @Test + public void rpcCollectionDoubleDataSource_No_Generic_To_List_Long() { + String sourceKey = "sourceKey"; + Double expectedDouble = 1.1; + + List input = new ArrayList(); + input.add(expectedDouble); + + TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + a.addAllDouble(input); + + TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + + RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); + + Optional actualBindingData = data.computeByName(sourceKey, List.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualDoubleList = (List) actualArg.getValue(); + Double actualLong = actualDoubleList.get(0); + assertEquals(actualLong, expectedDouble); + } +} + diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java new file mode 100644 index 00000000..651bfaf0 --- /dev/null +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java @@ -0,0 +1,130 @@ +package com.microsoft.azure.functions.worker.binding.tests; + +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble; +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionSInt64; +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionSInt64.Builder; +import com.microsoft.azure.functions.worker.binding.BindingData; +import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource; +import com.microsoft.azure.functions.worker.binding.RpcCollectionLongDataSource; +import org.junit.Test; + +import java.lang.invoke.WrongMethodTypeException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; + +public class RpcCollectionLongDataSourceTest{ + @Test + public void rpcCollectionSInt64DataSource_To_Long_Object_Array() { + String sourceKey = "sourceKey"; + Long expectedLong = 1L; + + List input = new ArrayList(); + input.add(expectedLong); + + Builder a = TypedDataCollectionSInt64.newBuilder(); + a.addAllSint64(input); + + TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + + RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); + + Optional actualBindingData = stringData.computeByName(sourceKey, Long[].class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + Long[] actualLongArray = (Long[]) actualArg.getValue(); + Long actualLong = actualLongArray[0]; + assertEquals(actualLong, expectedLong); + } + + @Test + public void rpcCollectionDoubleDataSource_To_long_Array() { + String sourceKey = "sourceKey"; + Long expectedLong = 1L; + + List input = new ArrayList(); + input.add(expectedLong); + + Builder a = TypedDataCollectionSInt64.newBuilder(); + a.addAllSint64(input); + + TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + + RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); + + Optional actualBindingData = stringData.computeByName(sourceKey, long[].class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + long[] actualLongArray = (long[]) actualArg.getValue(); + Long actualLong = actualLongArray[0]; + assertEquals(actualLong, expectedLong); + } + + @Test + public void rpcCollectionSInt64DataSource_default_To_List_Long() { + String sourceKey = "sourceKey"; + Long expectedLong = 1L; + + List input = new ArrayList(); + input.add(expectedLong); + + Builder a = TypedDataCollectionSInt64.newBuilder(); + a.addAllSint64(input); + + TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + + RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); + + Optional actualBindingData = stringData.computeByName(sourceKey, String.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualLongList = (List) actualArg.getValue(); + Long actualLong = actualLongList.get(0); + assertEquals(actualLong, expectedLong); + } + + @Test + public void rpcCollectionSInt64DataSource_To_List_Long() { + String sourceKey = "sourceKey"; + Long expectedLong = 1L; + + List input = new ArrayList(); + input.add(expectedLong); + + Builder a = TypedDataCollectionSInt64.newBuilder(); + a.addAllSint64(input); + + TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + + RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); + + + Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(Long[].class)); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualLongList = (List) actualArg.getValue(); + Long actualLong = actualLongList.get(0); + assertEquals(actualLong, expectedLong); + } + + @Test + public void rpcCollectionSInt64DataSource_No_Generic_To_List_Long() { + String sourceKey = "sourceKey"; + Long expectedLong = 1L; + + List input = new ArrayList(); + input.add(expectedLong); + + Builder a = TypedDataCollectionSInt64.newBuilder(); + a.addAllSint64(input); + + TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + + RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); + + + Optional actualBindingData = stringData.computeByName(sourceKey, List.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualLongList = (List) actualArg.getValue(); + Long actualLong = actualLongList.get(0); + assertEquals(actualLong, expectedLong); + } +} diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java new file mode 100644 index 00000000..5d4161ae --- /dev/null +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java @@ -0,0 +1,108 @@ +package com.microsoft.azure.functions.worker.binding.tests; + +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionString.Builder; +import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionString; +import com.microsoft.azure.functions.worker.binding.BindingData; +import com.microsoft.azure.functions.worker.binding.RpcCollectionStringDataSource; +import org.junit.Test; + +import java.lang.invoke.WrongMethodTypeException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; + +import static org.junit.Assert.assertEquals; + +public class RpcCollectionStringDataSourceTest { + @Test + public void rpcStringCollectionDataSource_To_string_Array() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + + List input = new ArrayList(); + input.add(expectedString); + + Builder a = TypedDataCollectionString.newBuilder(); + a.addAllString(input); + + TypedDataCollectionString typedDataCollectionString = a.build(); + + RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); + + Optional actualBindingData = stringData.computeByName(sourceKey, String[].class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + String[] actualStringArray = (String[]) actualArg.getValue(); + String actualString = actualStringArray[0]; + assertEquals(actualString, expectedString); + } + + @Test + public void rpcStringCollectionDataSource_default_To_List_string() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + + List input = new ArrayList(); + input.add(expectedString); + + Builder a = TypedDataCollectionString.newBuilder(); + a.addAllString(input); + + TypedDataCollectionString typedDataCollectionString = a.build(); + + RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); + + Optional actualBindingData = stringData.computeByName(sourceKey, String.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualStringList = (List) actualArg.getValue(); + String actualString = actualStringList.get(0); + assertEquals(actualString, expectedString); + } + + @Test + public void rpcStringCollectionDataSource_To_List_string() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + + List input = new ArrayList(); + input.add(expectedString); + + Builder a = TypedDataCollectionString.newBuilder(); + a.addAllString(input); + + TypedDataCollectionString typedDataCollectionString = a.build(); + + RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); + + Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(String[].class)); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualStringList = (List) actualArg.getValue(); + String actualString = actualStringList.get(0); + assertEquals(actualString, expectedString); + } + + @Test + public void rpcStringCollectionDataSource_No_Generic_To_List_String() { + String sourceKey = "sourceKey"; + String expectedString = "Example String"; + + List input = new ArrayList(); + input.add(expectedString); + + Builder a = TypedDataCollectionString.newBuilder(); + a.addAllString(input); + + TypedDataCollectionString typedDataCollectionString = a.build(); + + RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); + + Optional actualBindingData = stringData.computeByName(sourceKey, List.class); + BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); + List actualStringList = (List) actualArg.getValue(); + String actualString = actualStringList.get(0); + assertEquals(actualString, expectedString); + } + + + + +} diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java new file mode 100644 index 00000000..77876d48 --- /dev/null +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java @@ -0,0 +1,13 @@ +package com.microsoft.azure.functions.worker.binding.tests; + +import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; + +import java.lang.reflect.Type; +import java.util.List; + +public class Utility { + public static Type getActualType(Class clazz) { + return ParameterizedTypeImpl.make(List.class, new Type[]{clazz}, null); + + } +} From 17e42eb5670dc3e58ea461a152575e7f2f1ef33f Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 17 Jul 2019 20:21:57 -0700 Subject: [PATCH 03/14] Updated subtree from https://github.com/azure/azure-functions-language-worker-protobuf. Tag: v1.3.1-protofile. Commit: 9da87c9f1958c18ff38ce3bba7581c9bd88f8dc0 --- .../README.md | 25 +++++-- .../src/proto/FunctionRpc.proto | 75 ++++++++++++++++--- .../proto/identity/ClaimsIdentityRpc.proto | 26 +++++++ .../src/proto/shared/NullableTypes.proto | 30 ++++++++ 4 files changed, 137 insertions(+), 19 deletions(-) create mode 100644 src/main/azure-functions-language-worker-protobuf/src/proto/identity/ClaimsIdentityRpc.proto create mode 100644 src/main/azure-functions-language-worker-protobuf/src/proto/shared/NullableTypes.proto diff --git a/src/main/azure-functions-language-worker-protobuf/README.md b/src/main/azure-functions-language-worker-protobuf/README.md index a490b960..0f0f2341 100644 --- a/src/main/azure-functions-language-worker-protobuf/README.md +++ b/src/main/azure-functions-language-worker-protobuf/README.md @@ -26,19 +26,30 @@ From within the Azure Functions language worker repo: 1. Define remote branch for cleaner git commands - `git remote add proto-file https://github.com/azure/azure-functions-language-worker-protobuf.git` - `git fetch proto-file` -2. Merge updates - - `git merge -s subtree proto-file/ --squash --allow-unrelated-histories` - - You can also merge with an explicit path to subtree: `git merge -X subtree= --squash proto-file/ --allow-unrelated-histories` -3. Finalize with commit - - `git commit -m "Updated subtree from https://github.com/azure/azure-functions-language-worker-protobuf. Branch: . Commit: "` +2. Pull a specific release tag + - `git fetch proto-file refs/tags/` + - Example: `git fetch proto-file refs/tags/v1.1.0-protofile` +3. Merge updates + - Merge with an explicit path to subtree: `git merge -X subtree= --squash --allow-unrelated-histories --strategy-option theirs` + - Example: `git merge -X subtree=src/WebJobs.Script.Grpc/azure-functions-language-worker-protobuf --squash v1.1.0-protofile --allow-unrelated-histories --strategy-option theirs` +4. Finalize with commit + - `git commit -m "Updated subtree from https://github.com/azure/azure-functions-language-worker-protobuf. Tag: . Commit: "` - `git push` - + +## Releasing a Language Worker Protobuf version + +1. Draft a release in the GitHub UI + - Be sure to inculde details of the release +2. Create a release version, following semantic versioning guidelines ([semver.org](https://semver.org/)) +3. Tag the version with the pattern: `v..

-protofile` (example: `v1.1.0-protofile`) +3. Merge `dev` to `master` + ## Consuming FunctionRPC.proto *Note: Update versionNumber before running following commands* ## CSharp ``` -set NUGET_PATH=%UserProfile%\.nuget\packages +set NUGET_PATH="%UserProfile%\.nuget\packages" set GRPC_TOOLS_PATH=%NUGET_PATH%\grpc.tools\\tools\windows_x86 set PROTO_PATH=.\azure-functions-language-worker-protobuf\src\proto set PROTO=.\azure-functions-language-worker-protobuf\src\proto\FunctionRpc.proto diff --git a/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto b/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto index 77a60504..2d54cf94 100644 --- a/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto +++ b/src/main/azure-functions-language-worker-protobuf/src/proto/FunctionRpc.proto @@ -10,6 +10,8 @@ option go_package ="github.com/Azure/azure-functions-go-worker/internal/rpc"; package AzureFunctionsRpcMessages; import "google/protobuf/duration.proto"; +import "identity/ClaimsIdentityRpc.proto"; +import "shared/NullableTypes.proto"; // Interface exported by the server. service FunctionRpc { @@ -201,6 +203,9 @@ message FunctionLoadRequest { // Metadata for the request RpcFunctionMetadata metadata = 2; + + // A flag indicating if managed dependency is enabled or not + bool managed_dependency_enabled = 3; } // Worker tells host result of reload @@ -211,6 +216,9 @@ message FunctionLoadResponse { // Result of load operation StatusResult result = 2; // TODO: return type expected? + + // Result of load operation + bool is_dependency_downloaded = 3; } // Information on how a Function should be loaded and its bindings @@ -229,6 +237,9 @@ message RpcFunctionMetadata { // Bindings info map bindings = 6; + + // Is set to true for proxy + bool is_proxy = 7; } // Host requests worker to invoke a Function @@ -280,30 +291,30 @@ message TypedData { RpcHttp http = 5; sint64 int = 6; double double = 7; - TypedDataCollectionBytes collection_bytes = 8; - TypedDataCollectionString collection_string = 9; - TypedDataCollectionDouble collection_double = 10; - TypedDataCollectionSInt64 collection_sint64 = 11; + CollectionBytes collection_bytes = 8; + CollectionString collection_string = 9; + CollectionDouble collection_double = 10; + CollectionSInt64 collection_sint64 = 11; } } -// Used to encapsulate collection typedata string which could be a variety of types -message TypedDataCollectionString { +// Used to encapsulate collection string +message CollectionString { repeated string string = 1; } -// Used to encapsulate collection typedata bytes which could be a variety of types -message TypedDataCollectionBytes { +// Used to encapsulate collection bytes +message CollectionBytes { repeated bytes bytes = 1; } -// Used to encapsulate collection typedata double which could be a variety of types -message TypedDataCollectionDouble { +// Used to encapsulate collection double +message CollectionDouble { repeated double double = 1; } -// Used to encapsulate collection typedata sint64 which could be a variety of types -message TypedDataCollectionSInt64 { +// Used to encapsulate collection sint64 +message CollectionSInt64 { repeated sint64 sint64 = 1; } @@ -392,6 +403,44 @@ message RpcException { string message = 2; } +// Http cookie type. Note that only name and value are used for Http requests +message RpcHttpCookie { + // Enum that lets servers require that a cookie shouoldn't be sent with cross-site requests + enum SameSite { + None = 0; + Lax = 1; + Strict = 2; + } + + // Cookie name + string name = 1; + + // Cookie value + string value = 2; + + // Specifies allowed hosts to receive the cookie + NullableString domain = 3; + + // Specifies URL path that must exist in the requested URL + NullableString path = 4; + + // Sets the cookie to expire at a specific date instead of when the client closes. + // It is generally recommended that you use "Max-Age" over "Expires". + NullableTimestamp expires = 5; + + // Sets the cookie to only be sent with an encrypted request + NullableBool secure = 6; + + // Sets the cookie to be inaccessible to JavaScript's Document.cookie API + NullableBool http_only = 7; + + // Allows servers to assert that a cookie ought not to be sent along with cross-site requests + SameSite same_site = 8; + + // Number of seconds until the cookie expires. A zero or negative number will expire the cookie immediately. + NullableDouble max_age = 9; +} + // TODO - solidify this or remove it message RpcHttp { string method = 1; @@ -403,4 +452,6 @@ message RpcHttp { map query = 15; bool enable_content_negotiation= 16; TypedData rawBody = 17; + repeated RpcClaimsIdentity identities = 18; + repeated RpcHttpCookie cookies = 19; } diff --git a/src/main/azure-functions-language-worker-protobuf/src/proto/identity/ClaimsIdentityRpc.proto b/src/main/azure-functions-language-worker-protobuf/src/proto/identity/ClaimsIdentityRpc.proto new file mode 100644 index 00000000..c3945bb8 --- /dev/null +++ b/src/main/azure-functions-language-worker-protobuf/src/proto/identity/ClaimsIdentityRpc.proto @@ -0,0 +1,26 @@ +syntax = "proto3"; +// protobuf vscode extension: https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3 + +option java_package = "com.microsoft.azure.functions.rpc.messages"; + +import "shared/NullableTypes.proto"; + +// Light-weight representation of a .NET System.Security.Claims.ClaimsIdentity object. +// This is the same serialization as found in EasyAuth, and needs to be kept in sync with +// its ClaimsIdentitySlim definition, as seen in the WebJobs extension: +// https://github.com/Azure/azure-webjobs-sdk-extensions/blob/dev/src/WebJobs.Extensions.Http/ClaimsIdentitySlim.cs +message RpcClaimsIdentity { + NullableString authentication_type = 1; + NullableString name_claim_type = 2; + NullableString role_claim_type = 3; + repeated RpcClaim claims = 4; +} + +// Light-weight representation of a .NET System.Security.Claims.Claim object. +// This is the same serialization as found in EasyAuth, and needs to be kept in sync with +// its ClaimSlim definition, as seen in the WebJobs extension: +// https://github.com/Azure/azure-webjobs-sdk-extensions/blob/dev/src/WebJobs.Extensions.Http/ClaimSlim.cs +message RpcClaim { + string value = 1; + string type = 2; +} diff --git a/src/main/azure-functions-language-worker-protobuf/src/proto/shared/NullableTypes.proto b/src/main/azure-functions-language-worker-protobuf/src/proto/shared/NullableTypes.proto new file mode 100644 index 00000000..4fb47650 --- /dev/null +++ b/src/main/azure-functions-language-worker-protobuf/src/proto/shared/NullableTypes.proto @@ -0,0 +1,30 @@ +syntax = "proto3"; +// protobuf vscode extension: https://marketplace.visualstudio.com/items?itemName=zxh404.vscode-proto3 + +option java_package = "com.microsoft.azure.functions.rpc.messages"; + +import "google/protobuf/timestamp.proto"; + +message NullableString { + oneof string { + string value = 1; + } +} + +message NullableDouble { + oneof double { + double value = 1; + } +} + +message NullableBool { + oneof bool { + bool value = 1; + } +} + +message NullableTimestamp { + oneof timestamp { + google.protobuf.Timestamp value = 1; + } +} From e1af47102a386704e23b127ae03e7205a318fac9 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 17 Jul 2019 20:22:39 -0700 Subject: [PATCH 04/14] Refactor code based on code reviews --- .../functions/worker/binding/RpcCollectionDoubleDataSource.java | 2 +- .../functions/worker/handler/WorkerInitRequestHandler.java | 2 +- .../microsoft/azure/functions/worker/binding/tests/Utility.java | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java index 9f59a582..a34b43d7 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java @@ -44,7 +44,7 @@ public static Object convertToDoubleArray(List sourceValue, Type targetT COLLECTION_DATA_OPERATIONS.addGenericOperation(List.class, (v, t) -> convertToDoubleList(v, t)); COLLECTION_DATA_OPERATIONS.addGenericOperation(Double[].class, (v, t) -> convertToDoubleObjectArray(v, t)); COLLECTION_DATA_OPERATIONS.addGenericOperation(double[].class, (v, t) -> convertToDoubleArray(v, t)); - COLLECTION_DATA_OPERATIONS.addGenericOperation(String.class, (v, t) -> convertToDoubleListDefault(v, t)); + COLLECTION_DATA_OPERATIONS.addGenericOperation(String.class, (v, t) -> convertToDoubleListDefault(v, t)); } } diff --git a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java index 7075fb55..993860b8 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java +++ b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java @@ -14,7 +14,7 @@ public WorkerInitRequestHandler() { @Override String execute(WorkerInitRequest request, WorkerInitResponse.Builder response) { response.setWorkerVersion(Application.version()); - response.putCapabilities("TYPED_DATA_COLLECTION_SUPPORTED", "TRUE"); + response.putCapabilities("TypedDataCollection", "TypedDataCollection"); return "Worker initialized"; } } diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java index 77876d48..703faeed 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/Utility.java @@ -8,6 +8,5 @@ public class Utility { public static Type getActualType(Class clazz) { return ParameterizedTypeImpl.make(List.class, new Type[]{clazz}, null); - } } From dee1fa8a112904a3528d8b06f14120330dccf405 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 17 Jul 2019 20:30:43 -0700 Subject: [PATCH 05/14] Refactor the protobuf objects names based on the new release 1.3.1 --- .../RpcCollectionByteArrayDataSource.java | 4 +-- .../RpcCollectionDoubleDataSource.java | 4 +-- .../binding/RpcCollectionLongDataSource.java | 4 +-- .../RpcCollectionStringDataSource.java | 4 +-- .../RpcCollectionByteArrayDataSourceTest.java | 28 +++++++++---------- .../RpcCollectionDoubleDataSourceTest.java | 23 ++++++++------- .../RpcCollectionLongDataSourceTest.java | 26 ++++++++--------- .../RpcCollectionStringDataSourceTest.java | 20 ++++++------- 8 files changed, 55 insertions(+), 58 deletions(-) diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java index 350f36e2..b2acfe25 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java @@ -1,7 +1,7 @@ package com.microsoft.azure.functions.worker.binding; import com.google.protobuf.ByteString; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionBytes; +import com.microsoft.azure.functions.rpc.messages.CollectionBytes; import org.apache.commons.lang3.ArrayUtils; import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; @@ -11,7 +11,7 @@ import java.util.stream.Collectors; public final class RpcCollectionByteArrayDataSource extends DataSource> { - public RpcCollectionByteArrayDataSource(String name, TypedDataCollectionBytes value) { + public RpcCollectionByteArrayDataSource(String name, CollectionBytes value) { super(name, value.getBytesList(), COLLECTION_DATA_OPERATIONS); } private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java index a34b43d7..1c3512e9 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java @@ -1,6 +1,6 @@ package com.microsoft.azure.functions.worker.binding; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble; +import com.microsoft.azure.functions.rpc.messages.CollectionDouble; import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; import java.lang.reflect.Array; @@ -9,7 +9,7 @@ import java.util.List; public final class RpcCollectionDoubleDataSource extends DataSource> { - public RpcCollectionDoubleDataSource(String name, TypedDataCollectionDouble value) { + public RpcCollectionDoubleDataSource(String name, CollectionDouble value) { super(name, value.getDoubleList(), COLLECTION_DATA_OPERATIONS); } private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java index e4f7627e..f90e2d0a 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java @@ -1,6 +1,6 @@ package com.microsoft.azure.functions.worker.binding; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionSInt64; +import com.microsoft.azure.functions.rpc.messages.CollectionSInt64; import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; import java.lang.reflect.Type; @@ -8,7 +8,7 @@ import java.util.List; public final class RpcCollectionLongDataSource extends DataSource> { - public RpcCollectionLongDataSource(String name, TypedDataCollectionSInt64 value) { + public RpcCollectionLongDataSource(String name, CollectionSInt64 value) { super(name, value.getSint64List(), COLLECTION_DATA_OPERATIONS); } private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java index 813b2587..f6641a68 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java @@ -1,6 +1,6 @@ package com.microsoft.azure.functions.worker.binding; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionString; +import com.microsoft.azure.functions.rpc.messages.CollectionString; import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; import java.lang.reflect.Type; @@ -8,7 +8,7 @@ import java.util.List; public final class RpcCollectionStringDataSource extends DataSource> { - public RpcCollectionStringDataSource(String name, TypedDataCollectionString value) { + public RpcCollectionStringDataSource(String name, CollectionString value) { super(name, value.getStringList(), COLLECTION_DATA_OPERATIONS); } private static final DataOperations, Object> COLLECTION_DATA_OPERATIONS = new DataOperations<>(); diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java index 997c6321..e29c1f2d 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionByteArrayDataSourceTest.java @@ -3,8 +3,8 @@ import com.google.protobuf.ByteString; import com.microsoft.azure.functions.worker.binding.BindingData; import com.microsoft.azure.functions.worker.binding.RpcCollectionByteArrayDataSource; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionBytes; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionBytes.Builder; +import com.microsoft.azure.functions.rpc.messages.CollectionBytes; +import com.microsoft.azure.functions.rpc.messages.CollectionBytes.Builder; import org.apache.commons.lang3.ArrayUtils; import org.junit.Test; @@ -27,10 +27,10 @@ public void rpcByteArrayDataSource_To_byte_Array() { List input = new ArrayList(); input.add(inputByteString); - Builder a = TypedDataCollectionBytes.newBuilder(); + Builder a = CollectionBytes.newBuilder(); a.addAllBytes(input); - TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + CollectionBytes typedDataCollectionBytes = a.build(); RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); @@ -51,10 +51,10 @@ public void rpcByteArrayDataSource_To_Byte_Array() { List input = new ArrayList(); input.add(inputByteString); - Builder a = TypedDataCollectionBytes.newBuilder(); + Builder a = CollectionBytes.newBuilder(); a.addAllBytes(input); - TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + CollectionBytes typedDataCollectionBytes = a.build(); RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); @@ -75,10 +75,10 @@ public void rpcByteArrayDataSource_default_To_List_byte() { List input = new ArrayList(); input.add(inputByteString); - Builder a = TypedDataCollectionBytes.newBuilder(); + Builder a = CollectionBytes.newBuilder(); a.addAllBytes(input); - TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + CollectionBytes typedDataCollectionBytes = a.build(); RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); @@ -99,10 +99,10 @@ public void rpcByteArrayDataSource_To_List_byte() { List input = new ArrayList(); input.add(inputByteString); - Builder a = TypedDataCollectionBytes.newBuilder(); + Builder a = CollectionBytes.newBuilder(); a.addAllBytes(input); - TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + CollectionBytes typedDataCollectionBytes = a.build(); RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); @@ -123,10 +123,10 @@ public void rpcByteArrayDataSource_To_List_Byte() { List input = new ArrayList(); input.add(inputByteString); - Builder a = TypedDataCollectionBytes.newBuilder(); + Builder a = CollectionBytes.newBuilder(); a.addAllBytes(input); - TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + CollectionBytes typedDataCollectionBytes = a.build(); RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); @@ -147,10 +147,10 @@ public void rpcByteArrayDataSource_No_Generic_To_List_byte() { List input = new ArrayList(); input.add(inputByteString); - Builder a = TypedDataCollectionBytes.newBuilder(); + Builder a = CollectionBytes.newBuilder(); a.addAllBytes(input); - TypedDataCollectionBytes typedDataCollectionBytes = a.build(); + CollectionBytes typedDataCollectionBytes = a.build(); RpcCollectionByteArrayDataSource stringData = new RpcCollectionByteArrayDataSource(sourceKey, typedDataCollectionBytes); diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java index 274b1464..cae3ab73 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java @@ -1,8 +1,7 @@ package com.microsoft.azure.functions.worker.binding.tests; - import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble; - import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble.Builder; + import com.microsoft.azure.functions.rpc.messages.CollectionDouble; import com.microsoft.azure.functions.worker.binding.BindingData; import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource; import org.junit.Test; @@ -23,10 +22,10 @@ public void rpcCollectionDoubleDataSource_To_Double_Object_Array() { List input = new ArrayList(); input.add(expectedDouble); - TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + CollectionDouble.Builder a = CollectionDouble.newBuilder(); a.addAllDouble(input); - TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + CollectionDouble typedDataCollectionDouble = a.build(); RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); @@ -45,10 +44,10 @@ public void rpcCollectionDoubleDataSource_To_double_Array() { List input = new ArrayList(); input.add(expectedDouble); - TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + CollectionDouble.Builder a = CollectionDouble.newBuilder(); a.addAllDouble(input); - TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + CollectionDouble typedDataCollectionDouble = a.build(); RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); @@ -67,10 +66,10 @@ public void rpcCollectionDoubleDataSource_default_To_List_Double() { List input = new ArrayList(); input.add(expectedDouble); - TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + CollectionDouble.Builder a = CollectionDouble.newBuilder(); a.addAllDouble(input); - TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + CollectionDouble typedDataCollectionDouble = a.build(); RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); @@ -89,10 +88,10 @@ public void rpcCollectionDoubleDataSource_To_List_Double() { List input = new ArrayList(); input.add(expectedDouble); - TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + CollectionDouble.Builder a = CollectionDouble.newBuilder(); a.addAllDouble(input); - TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + CollectionDouble typedDataCollectionDouble = a.build(); RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); @@ -111,10 +110,10 @@ public void rpcCollectionDoubleDataSource_No_Generic_To_List_Long() { List input = new ArrayList(); input.add(expectedDouble); - TypedDataCollectionDouble.Builder a = TypedDataCollectionDouble.newBuilder(); + CollectionDouble.Builder a = CollectionDouble.newBuilder(); a.addAllDouble(input); - TypedDataCollectionDouble typedDataCollectionDouble = a.build(); + CollectionDouble typedDataCollectionDouble = a.build(); RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java index 651bfaf0..87e61597 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java @@ -1,10 +1,8 @@ package com.microsoft.azure.functions.worker.binding.tests; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionDouble; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionSInt64; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionSInt64.Builder; +import com.microsoft.azure.functions.rpc.messages.CollectionSInt64; +import com.microsoft.azure.functions.rpc.messages.CollectionSInt64.Builder; import com.microsoft.azure.functions.worker.binding.BindingData; -import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource; import com.microsoft.azure.functions.worker.binding.RpcCollectionLongDataSource; import org.junit.Test; @@ -24,10 +22,10 @@ public void rpcCollectionSInt64DataSource_To_Long_Object_Array() { List input = new ArrayList(); input.add(expectedLong); - Builder a = TypedDataCollectionSInt64.newBuilder(); + Builder a = CollectionSInt64.newBuilder(); a.addAllSint64(input); - TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + CollectionSInt64 typedDataCollectionLong = a.build(); RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); @@ -46,10 +44,10 @@ public void rpcCollectionDoubleDataSource_To_long_Array() { List input = new ArrayList(); input.add(expectedLong); - Builder a = TypedDataCollectionSInt64.newBuilder(); + Builder a = CollectionSInt64.newBuilder(); a.addAllSint64(input); - TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + CollectionSInt64 typedDataCollectionLong = a.build(); RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); @@ -68,10 +66,10 @@ public void rpcCollectionSInt64DataSource_default_To_List_Long() { List input = new ArrayList(); input.add(expectedLong); - Builder a = TypedDataCollectionSInt64.newBuilder(); + Builder a = CollectionSInt64.newBuilder(); a.addAllSint64(input); - TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + CollectionSInt64 typedDataCollectionLong = a.build(); RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); @@ -90,10 +88,10 @@ public void rpcCollectionSInt64DataSource_To_List_Long() { List input = new ArrayList(); input.add(expectedLong); - Builder a = TypedDataCollectionSInt64.newBuilder(); + Builder a = CollectionSInt64.newBuilder(); a.addAllSint64(input); - TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + CollectionSInt64 typedDataCollectionLong = a.build(); RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); @@ -113,10 +111,10 @@ public void rpcCollectionSInt64DataSource_No_Generic_To_List_Long() { List input = new ArrayList(); input.add(expectedLong); - Builder a = TypedDataCollectionSInt64.newBuilder(); + Builder a = CollectionSInt64.newBuilder(); a.addAllSint64(input); - TypedDataCollectionSInt64 typedDataCollectionLong = a.build(); + CollectionSInt64 typedDataCollectionLong = a.build(); RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java index 5d4161ae..71cefa68 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java @@ -1,7 +1,7 @@ package com.microsoft.azure.functions.worker.binding.tests; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionString.Builder; -import com.microsoft.azure.functions.rpc.messages.TypedDataCollectionString; +import com.microsoft.azure.functions.rpc.messages.CollectionString.Builder; +import com.microsoft.azure.functions.rpc.messages.CollectionString; import com.microsoft.azure.functions.worker.binding.BindingData; import com.microsoft.azure.functions.worker.binding.RpcCollectionStringDataSource; import org.junit.Test; @@ -22,10 +22,10 @@ public void rpcStringCollectionDataSource_To_string_Array() { List input = new ArrayList(); input.add(expectedString); - Builder a = TypedDataCollectionString.newBuilder(); + Builder a = CollectionString.newBuilder(); a.addAllString(input); - TypedDataCollectionString typedDataCollectionString = a.build(); + CollectionString typedDataCollectionString = a.build(); RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); @@ -44,10 +44,10 @@ public void rpcStringCollectionDataSource_default_To_List_string() { List input = new ArrayList(); input.add(expectedString); - Builder a = TypedDataCollectionString.newBuilder(); + Builder a = CollectionString.newBuilder(); a.addAllString(input); - TypedDataCollectionString typedDataCollectionString = a.build(); + CollectionString typedDataCollectionString = a.build(); RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); @@ -66,10 +66,10 @@ public void rpcStringCollectionDataSource_To_List_string() { List input = new ArrayList(); input.add(expectedString); - Builder a = TypedDataCollectionString.newBuilder(); + Builder a = CollectionString.newBuilder(); a.addAllString(input); - TypedDataCollectionString typedDataCollectionString = a.build(); + CollectionString typedDataCollectionString = a.build(); RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); @@ -88,10 +88,10 @@ public void rpcStringCollectionDataSource_No_Generic_To_List_String() { List input = new ArrayList(); input.add(expectedString); - Builder a = TypedDataCollectionString.newBuilder(); + Builder a = CollectionString.newBuilder(); a.addAllString(input); - TypedDataCollectionString typedDataCollectionString = a.build(); + CollectionString typedDataCollectionString = a.build(); RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); From 023523fa50f57b74b41f50561f1a9d7350c3c569 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 17 Jul 2019 20:36:58 -0700 Subject: [PATCH 06/14] -Fix the capability name to CollectionSupported --- .../functions/worker/handler/WorkerInitRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java index 993860b8..3bb42480 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java +++ b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java @@ -14,7 +14,7 @@ public WorkerInitRequestHandler() { @Override String execute(WorkerInitRequest request, WorkerInitResponse.Builder response) { response.setWorkerVersion(Application.version()); - response.putCapabilities("TypedDataCollection", "TypedDataCollection"); + response.putCapabilities("CollectionSupported", "CollectionSupported"); return "Worker initialized"; } } From 0c8b6345c6779df5bc116c8a7d6a9e51e399fe01 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 17 Jul 2019 21:13:15 -0700 Subject: [PATCH 07/14] Refactor the neame of the capabilty to TypedDataCollection --- .../functions/worker/handler/WorkerInitRequestHandler.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java index 3bb42480..993860b8 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java +++ b/src/main/java/com/microsoft/azure/functions/worker/handler/WorkerInitRequestHandler.java @@ -14,7 +14,7 @@ public WorkerInitRequestHandler() { @Override String execute(WorkerInitRequest request, WorkerInitResponse.Builder response) { response.setWorkerVersion(Application.version()); - response.putCapabilities("CollectionSupported", "CollectionSupported"); + response.putCapabilities("TypedDataCollection", "TypedDataCollection"); return "Worker initialized"; } } From 6d1a0d8d70d9e3b369f35ec2a9cb87a504c98ec2 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Tue, 23 Jul 2019 17:30:38 -0700 Subject: [PATCH 08/14] Code refactore and adding e2e tests --- .../Constants.cs | 14 ++++-- .../EventHubsEndToEndTests.cs | 44 +++++++++++++------ .../Helpers/EventHubsHelpers.cs | 8 ++-- endtoendtests/local.settings.json | 1 + .../endtoend/EventHubTriggerTests.java | 36 ++++++++------- .../RpcCollectionByteArrayDataSource.java | 6 +-- .../RpcCollectionDoubleDataSource.java | 7 ++- .../binding/RpcCollectionLongDataSource.java | 6 +-- .../RpcCollectionStringDataSource.java | 6 +-- .../RpcCollectionDoubleDataSourceTest.java | 18 ++++---- 10 files changed, 87 insertions(+), 59 deletions(-) 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 75cb7ac6..1e552b5b 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 @@ -44,11 +44,17 @@ public static class Constants public static string OutputOneEventHubQueueName = "test-eventhuboutputone-java"; public static string InputCardinalityOneEventHubName = "test-inputOne-java"; - public static string OutputBinaryOneEventHubQueueName = "test-outputone-java-cardinality-one"; - public static string InputBinaryOneEventHubQueueName = "test-inputone-java-cardinality-one"; + public static string OutputBinaryOneQueueName = "test-binary-output-java-cardinality-one"; + public static string InputBinaryOneEventHubQueueName = "test-binary-input-java-cardinality-one"; - public static string OutputBinaryManyEventHubQueueName = "test-outputbinary-java-cardinality-many"; - public static string InputBinaryManyEventHubQueueName = "test-inputbinary-java-cardinality-many"; + public static string OutputBinaryManyQueueName = "test-binary-output-java-cardinality-many-list"; + public static string InputBinaryManyEventHubQueueName = "test-binary-input-java-cardinality-many-list"; + + public static string OutputBinaryArrayManyQueueName = "test-binary-output-java-cardinality-many-array"; + public static string InputBinaryManyArrayEventHubQueueName = "test-binary-input-java-cardinality-many-array"; + + public static string EventHubsConnectionStringSenderSetting = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender"); + public static string EventHubsConnectionStringSenderSetting2 = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender_2"); public static string EventHubsConnectionStringSetting = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender"); diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs index ad871a7b..0e7d030d 100644 --- a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Reflection.Metadata; using System.Threading.Tasks; using Xunit; @@ -29,7 +30,7 @@ public async Task EventHubTriggerAndOutputJSON_Succeeds() await SetupQueue(Constants.OutputJsonEventHubQueueName); // Need to setup EventHubs: test-inputjson-java and test-outputjson-java - await EventHubsHelpers.SendJSONMessagesAsync(expectedEventId); + await EventHubsHelpers.SendJSONMessagesAsync(expectedEventId, Constants.EventHubsConnectionStringSenderSetting); //Verify var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputJsonEventHubQueueName); @@ -52,7 +53,7 @@ public async Task EventHubTriggerAndOutputString_Succeeds() await SetupQueue(Constants.OutputEventHubQueueName); // Need to setup EventHubs: test-input-java and test-output-java - await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputEventHubName); + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputEventHubName, Constants.EventHubsConnectionStringSenderSetting); //Verify var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputEventHubQueueName); @@ -74,7 +75,7 @@ public async Task EventHubTriggerCardinalityOne_Succeeds() await SetupQueue(Constants.OutputOneEventHubQueueName); // Need to setup EventHubs: test-inputOne-java and test-outputone-java - await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputCardinalityOneEventHubName); + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputCardinalityOneEventHubName, Constants.EventHubsConnectionStringSenderSetting); //Verify IEnumerable queueMessages = await StorageHelpers.ReadMessagesFromQueue(Constants.OutputOneEventHubQueueName); @@ -89,23 +90,39 @@ public async Task EventHubTriggerCardinalityOne_Succeeds() [Fact] - public async Task EventHubTriggerAndOutputBinaryMany_Succeeds() + public async Task EventHubTriggerAndOutputBinaryListMany_Succeeds() { string expectedEventId = Guid.NewGuid().ToString(); try { - await SetupQueue(Constants.OutputBinaryManyEventHubQueueName); + await SetupQueue(Constants.OutputBinaryManyQueueName); - // Need to setup EventHubs: test-input-java and test-output-java - await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyEventHubQueueName); + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyEventHubQueueName, Constants.EventHubsConnectionStringSenderSetting2); //Verify - var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryManyEventHubQueueName); + var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryManyQueueName); Assert.Contains(expectedEventId, queueMessage); } - catch (Exception ex) + finally + { + //Clear queue + await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); + } + } + + [Fact] + public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() + { + string expectedEventId = Guid.NewGuid().ToString(); + try { + await SetupQueue(Constants.OutputBinaryOneQueueName); + + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryOneEventHubQueueName, Constants.EventHubsConnectionStringSenderSetting2); + //Verify + var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryOneQueueName); + Assert.Contains(expectedEventId, queueMessage); } finally { @@ -115,18 +132,17 @@ public async Task EventHubTriggerAndOutputBinaryMany_Succeeds() } [Fact] - public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() + public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() { string expectedEventId = Guid.NewGuid().ToString(); try { - await SetupQueue(Constants.OutputBinaryOneEventHubQueueName); + await SetupQueue(Constants.OutputBinaryArrayManyQueueName); - // Need to setup EventHubs: test-input-java and test-output-java - await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryOneEventHubQueueName); + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyArrayEventHubQueueName, Constants.EventHubsConnectionStringSenderSetting2); //Verify - var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryOneEventHubQueueName); + var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryArrayManyQueueName); Assert.Contains(expectedEventId, queueMessage); } finally diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Helpers/EventHubsHelpers.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Helpers/EventHubsHelpers.cs index d73d7b2c..e1f350e9 100644 --- a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Helpers/EventHubsHelpers.cs +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/Helpers/EventHubsHelpers.cs @@ -12,7 +12,7 @@ namespace Azure.Functions.Java.Tests.E2E { public class EventHubsHelpers { - public static async Task SendJSONMessagesAsync(string eventId) + public static async Task SendJSONMessagesAsync(string eventId, string connectionString) { // write 3 events List events = new List(); @@ -29,13 +29,13 @@ public static async Task SendJSONMessagesAsync(string eventId) events.Add(evt); } - EventHubsConnectionStringBuilder builder = new EventHubsConnectionStringBuilder(Constants.EventHubsConnectionStringSetting); + EventHubsConnectionStringBuilder builder = new EventHubsConnectionStringBuilder(connectionString); builder.EntityPath = Constants.InputJsonEventHubName; EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(builder.ToString()); await eventHubClient.SendAsync(events); } - public static async Task SendMessagesAsync(string eventId, string evenHubName) + public static async Task SendMessagesAsync(string eventId, string evenHubName, string connectionString) { // write 3 events List events = new List(); @@ -48,7 +48,7 @@ public static async Task SendMessagesAsync(string eventId, string evenHubName) events.Add(evt); } - EventHubsConnectionStringBuilder builder = new EventHubsConnectionStringBuilder(Constants.EventHubsConnectionStringSetting); + EventHubsConnectionStringBuilder builder = new EventHubsConnectionStringBuilder(connectionString); builder.EntityPath = evenHubName; EventHubClient eventHubClient = EventHubClient.CreateFromConnectionString(builder.ToString()); await eventHubClient.SendAsync(events); diff --git a/endtoendtests/local.settings.json b/endtoendtests/local.settings.json index 25a28dff..920e6ce9 100644 --- a/endtoendtests/local.settings.json +++ b/endtoendtests/local.settings.json @@ -4,6 +4,7 @@ "AzureWebJobsServiceBus": "", "AzureWebJobsEventHubReceiver":"", "AzureWebJobsEventHubSender":"", + "AzureWebJobsEventHubSender_2":"", "AzureWebJobsEventHubPath":"", "CosmosDBDatabaseName":"", "CosmosDBCollectionName":"", diff --git a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java index 240e7aae..a54be716 100644 --- a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java +++ b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java @@ -47,7 +47,7 @@ public void EventHubTriggerCardinalityOne( /** * This function verifies the above functions */ - @FunctionName("TestEventHubOutputJson") + @FunctionName("EventHubOutputJson") public void TestEventHubOutputJson( @EventHubTrigger(name = "message", eventHubName = "test-outputjson-java", connection = "AzureWebJobsEventHubSender") String message, @QueueOutput(name = "output", queueName = "test-eventhuboutputjson-java", connection = "AzureWebJobsStorage") OutputBinding output, @@ -57,7 +57,7 @@ public void TestEventHubOutputJson( output.setValue(message); } - @FunctionName("TestEventHubOutput") + @FunctionName("EventHubOutput") public void TestEventHubOutput( @EventHubTrigger(name = "message", eventHubName = "test-output-java", connection = "AzureWebJobsEventHubSender", cardinality = Cardinality.ONE) String message, @QueueOutput(name = "output", queueName = "test-eventhuboutput-java", connection = "AzureWebJobsStorage") OutputBinding output, @@ -67,7 +67,7 @@ public void TestEventHubOutput( output.setValue(message); } - @FunctionName("TestEventHubOutputInputOne") + @FunctionName("EventHubOutputInputOne") public void TestEventHubOutputInputOne( @EventHubTrigger(name = "message", eventHubName = "test-outputone-java", connection = "AzureWebJobsEventHubSender", cardinality = Cardinality.ONE) String message, @QueueOutput(name = "output", queueName = "test-eventhuboutputone-java", connection = "AzureWebJobsStorage") OutputBinding output, @@ -77,34 +77,40 @@ public void TestEventHubOutputInputOne( output.setValue(message); } - @FunctionName("EventHubTriggerAndOutputBinaryCardinalityMany") - public void EventHubTriggerAndOutputBinaryCardinalityMany( - @EventHubTrigger(name = "messages", eventHubName = "test-inputbinary-java-cardinality-many", connection = "AzureWebJobsEventHubSender", dataType = "binary", cardinality = Cardinality.MANY) List messages, - @EventHubOutput(name = "output", eventHubName = "test-outputbinary-java-cardinality-many", connection = "AzureWebJobsEventHubSender") OutputBinding output, + @FunctionName("EventHubTriggerAndOutputBinaryCardinalityManyListBinary") + public void EventHubTriggerAndOutputBinaryCardinalityManyListBinary( + @EventHubTrigger(name = "messages", eventHubName = "test-binary-input-java-cardinality-many-list", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.MANY) List messages, + @QueueOutput(name = "output", queueName = "test-binary-output-java-cardinality-many-list", connection = "AzureWebJobsStorage") OutputBinding output, final ExecutionContext context ) { -// context.getLogger().info("Java Event Hub trigger received " + messages.size() +" messages"); -// Byte[] test = messages.get(0); -// output.setValue(messages.get(0)); - - + context.getLogger().info("Java Event Hub trigger received " + messages.size() +" messages"); + output.setValue(messages.get(0)); } @FunctionName("EventHubTriggerAndOutputBinaryCardinalityOne") public void EventHubTriggerAndOutputBinaryCardinalityOne( - @EventHubTrigger(name = "message", eventHubName = "test-inputone-java-cardinality-one", connection = "AzureWebJobsEventHubSender", dataType = "binary", cardinality = Cardinality.ONE) byte[] message, - @EventHubOutput(name = "output", eventHubName = "test-outputone-java-cardinality-one", connection = "AzureWebJobsEventHubSender", dataType = "binary") OutputBinding output, + @EventHubTrigger(name = "message", eventHubName = "test-binary-input-java-cardinality-one", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.ONE) byte[] message, + @QueueOutput(name = "output", queueName = "test-binary-output-java-cardinality-one",connection = "AzureWebJobsStorage") OutputBinding output, final ExecutionContext context ) { context.getLogger().info("Java Event Hub trigger received message" + message); output.setValue(message); } + @FunctionName("EventHubTriggerAndOutputBinaryCardinalityManyArrayBinary") + public void EventHubTriggerAndOutputBinaryCardinalityManyArrayBinary( + @EventHubTrigger(name = "messages", eventHubName = "test-binary-input-java-cardinality-many-array", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.MANY) byte[][] messages, + @QueueOutput(name = "output", queueName = "test-binary-output-java-cardinality-many-array", connection = "AzureWebJobsStorage") OutputBinding output, + final ExecutionContext context + ) { + context.getLogger().info("Java Event Hub trigger received " + messages.length +" messages"); + output.setValue(messages[0]); + } + public static class SystemProperty { public String SequenceNumber; public String Offset; public String PartitionKey; public String EnqueuedTimeUtc; } - } diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java index b2acfe25..408361c4 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionByteArrayDataSource.java @@ -3,8 +3,8 @@ import com.google.protobuf.ByteString; import com.microsoft.azure.functions.rpc.messages.CollectionBytes; import org.apache.commons.lang3.ArrayUtils; -import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; @@ -20,8 +20,8 @@ public static Object convertToByteList(List sourceValue, Type target if(targetType == List.class) { return sourceValue.stream().map(element -> element.toByteArray()).collect(Collectors.toCollection(ArrayList::new)); } - else if(targetType instanceof ParameterizedTypeImpl){ - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + else if(targetType instanceof ParameterizedType){ + Type targetActualType = ((ParameterizedType) targetType).getActualTypeArguments()[0]; if (targetActualType == byte[].class) { return sourceValue.stream().map(element -> element.toByteArray()).collect(Collectors.toCollection(ArrayList::new)); } else if (targetActualType == Byte[].class) { diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java index 1c3512e9..71ada30e 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionDoubleDataSource.java @@ -1,9 +1,8 @@ package com.microsoft.azure.functions.worker.binding; import com.microsoft.azure.functions.rpc.messages.CollectionDouble; -import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; -import java.lang.reflect.Array; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; @@ -22,8 +21,8 @@ public static Object convertToDoubleList(List sourceValue, Type targetTy if(targetType == List.class) { return new ArrayList<>(sourceValue); } - else if(targetType instanceof ParameterizedTypeImpl) { - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + else if(targetType instanceof ParameterizedType) { + Type targetActualType = ((ParameterizedType) targetType).getActualTypeArguments()[0]; if (targetActualType == Double.class) { return new ArrayList<>(sourceValue); } diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java index f90e2d0a..d22ec2b5 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionLongDataSource.java @@ -1,8 +1,8 @@ package com.microsoft.azure.functions.worker.binding; import com.microsoft.azure.functions.rpc.messages.CollectionSInt64; -import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; @@ -17,8 +17,8 @@ public static Object convertToLongList(List sourceValue, Type targetType) if(targetType == List.class) { return new ArrayList<>(sourceValue); } - else if(targetType instanceof ParameterizedTypeImpl) { - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + else if(targetType instanceof ParameterizedType) { + Type targetActualType = ((ParameterizedType) targetType).getActualTypeArguments()[0]; if (targetActualType == Long.class) { return new ArrayList<>(sourceValue); } diff --git a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java index f6641a68..bb4708f8 100644 --- a/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java +++ b/src/main/java/com/microsoft/azure/functions/worker/binding/RpcCollectionStringDataSource.java @@ -1,8 +1,8 @@ package com.microsoft.azure.functions.worker.binding; import com.microsoft.azure.functions.rpc.messages.CollectionString; -import sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl; +import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; import java.util.ArrayList; import java.util.List; @@ -17,8 +17,8 @@ public static Object convertToStringList(List sourceValue, Type targetTy if(targetType == List.class) { return new ArrayList<>(sourceValue); } - else if(targetType instanceof ParameterizedTypeImpl) { - Type targetActualType = ((ParameterizedTypeImpl) targetType).getActualTypeArguments()[0]; + else if(targetType instanceof ParameterizedType) { + Type targetActualType = ((ParameterizedType) targetType).getActualTypeArguments()[0]; if (targetActualType == String.class) { return new ArrayList<>(sourceValue); } diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java index cae3ab73..a8bb53e3 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java @@ -1,17 +1,17 @@ package com.microsoft.azure.functions.worker.binding.tests; - import com.microsoft.azure.functions.rpc.messages.CollectionDouble; - import com.microsoft.azure.functions.worker.binding.BindingData; - import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource; - import org.junit.Test; +import com.microsoft.azure.functions.rpc.messages.CollectionDouble; +import com.microsoft.azure.functions.worker.binding.BindingData; +import com.microsoft.azure.functions.worker.binding.RpcCollectionDoubleDataSource; +import org.junit.Test; - import java.lang.invoke.WrongMethodTypeException; - import java.util.ArrayList; - import java.util.List; - import java.util.Optional; +import java.lang.invoke.WrongMethodTypeException; +import java.util.ArrayList; +import java.util.List; +import java.util.Optional; - import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertEquals; public class RpcCollectionDoubleDataSourceTest { @Test From 7a33f9748e3e6ee80267008f4bf12b3b38d97502 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Tue, 23 Jul 2019 18:12:01 -0700 Subject: [PATCH 09/14] Updated the event hubs names --- .../Azure.Functions.Java.Tests.E2E/Constants.cs | 12 ++++++------ .../functions/endtoend/EventHubTriggerTests.java | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) 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 1e552b5b..3680b8ad 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 @@ -44,14 +44,14 @@ public static class Constants public static string OutputOneEventHubQueueName = "test-eventhuboutputone-java"; public static string InputCardinalityOneEventHubName = "test-inputOne-java"; - public static string OutputBinaryOneQueueName = "test-binary-output-java-cardinality-one"; - public static string InputBinaryOneEventHubQueueName = "test-binary-input-java-cardinality-one"; + public static string OutputBinaryOneQueueName = "test-binary-output-cardinality-one-java"; + public static string InputBinaryOneEventHubQueueName = "test-binary-input-cardinality-one-java"; - public static string OutputBinaryManyQueueName = "test-binary-output-java-cardinality-many-list"; - public static string InputBinaryManyEventHubQueueName = "test-binary-input-java-cardinality-many-list"; + public static string OutputBinaryManyQueueName = "test-binary-output-cardinality-many-list-java"; + public static string InputBinaryManyEventHubQueueName = "test-binary-input-cardinality-many-list-java"; - public static string OutputBinaryArrayManyQueueName = "test-binary-output-java-cardinality-many-array"; - public static string InputBinaryManyArrayEventHubQueueName = "test-binary-input-java-cardinality-many-array"; + public static string OutputBinaryArrayManyQueueName = "test-binary-output-cardinality-many-array-java"; + public static string InputBinaryManyArrayEventHubQueueName = "test-binary-input-cardinality-many-array-java"; public static string EventHubsConnectionStringSenderSetting = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender"); public static string EventHubsConnectionStringSenderSetting2 = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender_2"); diff --git a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java index a54be716..3f1f7840 100644 --- a/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java +++ b/endtoendtests/src/main/java/com/microsoft/azure/functions/endtoend/EventHubTriggerTests.java @@ -79,8 +79,8 @@ public void TestEventHubOutputInputOne( @FunctionName("EventHubTriggerAndOutputBinaryCardinalityManyListBinary") public void EventHubTriggerAndOutputBinaryCardinalityManyListBinary( - @EventHubTrigger(name = "messages", eventHubName = "test-binary-input-java-cardinality-many-list", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.MANY) List messages, - @QueueOutput(name = "output", queueName = "test-binary-output-java-cardinality-many-list", connection = "AzureWebJobsStorage") OutputBinding output, + @EventHubTrigger(name = "messages", eventHubName = "test-binary-input-cardinality-many-list-java", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.MANY) List messages, + @QueueOutput(name = "output", queueName = "test-binary-output-cardinality-many-list-java", connection = "AzureWebJobsStorage") OutputBinding output, final ExecutionContext context ) { context.getLogger().info("Java Event Hub trigger received " + messages.size() +" messages"); @@ -89,8 +89,8 @@ public void EventHubTriggerAndOutputBinaryCardinalityManyListBinary( @FunctionName("EventHubTriggerAndOutputBinaryCardinalityOne") public void EventHubTriggerAndOutputBinaryCardinalityOne( - @EventHubTrigger(name = "message", eventHubName = "test-binary-input-java-cardinality-one", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.ONE) byte[] message, - @QueueOutput(name = "output", queueName = "test-binary-output-java-cardinality-one",connection = "AzureWebJobsStorage") OutputBinding output, + @EventHubTrigger(name = "message", eventHubName = "test-binary-input-cardinality-one-java", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.ONE) byte[] message, + @QueueOutput(name = "output", queueName = "test-binary-output-cardinality-one-java",connection = "AzureWebJobsStorage") OutputBinding output, final ExecutionContext context ) { context.getLogger().info("Java Event Hub trigger received message" + message); @@ -99,8 +99,8 @@ public void EventHubTriggerAndOutputBinaryCardinalityOne( @FunctionName("EventHubTriggerAndOutputBinaryCardinalityManyArrayBinary") public void EventHubTriggerAndOutputBinaryCardinalityManyArrayBinary( - @EventHubTrigger(name = "messages", eventHubName = "test-binary-input-java-cardinality-many-array", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.MANY) byte[][] messages, - @QueueOutput(name = "output", queueName = "test-binary-output-java-cardinality-many-array", connection = "AzureWebJobsStorage") OutputBinding output, + @EventHubTrigger(name = "messages", eventHubName = "test-binary-input-cardinality-many-array-java", connection = "AzureWebJobsEventHubSender_2", dataType = "binary", cardinality = Cardinality.MANY) byte[][] messages, + @QueueOutput(name = "output", queueName = "test-binary-output-cardinality-many-array-java", connection = "AzureWebJobsStorage") OutputBinding output, final ExecutionContext context ) { context.getLogger().info("Java Event Hub trigger received " + messages.length +" messages"); From 9888de4ca1f7572d785c3f8f202b560c5c6958d3 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 24 Jul 2019 09:51:15 -0700 Subject: [PATCH 10/14] Fix tests cases --- .../worker/binding/tests/RpcCollectionDoubleDataSourceTest.java | 2 +- .../worker/binding/tests/RpcCollectionLongDataSourceTest.java | 2 +- .../worker/binding/tests/RpcCollectionStringDataSourceTest.java | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java index a8bb53e3..e18b4a44 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionDoubleDataSourceTest.java @@ -95,7 +95,7 @@ public void rpcCollectionDoubleDataSource_To_List_Double() { RpcCollectionDoubleDataSource data = new RpcCollectionDoubleDataSource(sourceKey, typedDataCollectionDouble); - Optional actualBindingData = data.computeByName(sourceKey, Utility.getActualType(Double[].class)); + Optional actualBindingData = data.computeByName(sourceKey, Utility.getActualType(Double.class)); BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); List actualDoubleList = (List) actualArg.getValue(); Double actualLong = actualDoubleList.get(0); diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java index 87e61597..a16d547f 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionLongDataSourceTest.java @@ -96,7 +96,7 @@ public void rpcCollectionSInt64DataSource_To_List_Long() { RpcCollectionLongDataSource stringData = new RpcCollectionLongDataSource(sourceKey, typedDataCollectionLong); - Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(Long[].class)); + Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(Long.class)); BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); List actualLongList = (List) actualArg.getValue(); Long actualLong = actualLongList.get(0); diff --git a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java index 71cefa68..17a6e07b 100644 --- a/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java +++ b/src/test/java/com/microsoft/azure/functions/worker/binding/tests/RpcCollectionStringDataSourceTest.java @@ -73,7 +73,7 @@ public void rpcStringCollectionDataSource_To_List_string() { RpcCollectionStringDataSource stringData = new RpcCollectionStringDataSource(sourceKey, typedDataCollectionString); - Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(String[].class)); + Optional actualBindingData = stringData.computeByName(sourceKey, Utility.getActualType(String.class)); BindingData actualArg = actualBindingData.orElseThrow(WrongMethodTypeException::new); List actualStringList = (List) actualArg.getValue(); String actualString = actualStringList.get(0); From afe1b687d85541bfb0a9bb18b5077fd343a32a9a Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 24 Jul 2019 18:33:53 -0700 Subject: [PATCH 11/14] Add settings to constants --- .../Azure.Functions.Java.Tests.E2E/Constants.cs | 1 + 1 file changed, 1 insertion(+) 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 3680b8ad..7fed4d3b 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 @@ -53,6 +53,7 @@ public static class Constants public static string OutputBinaryArrayManyQueueName = "test-binary-output-cardinality-many-array-java"; public static string InputBinaryManyArrayEventHubQueueName = "test-binary-input-cardinality-many-array-java"; + // Settings public static string EventHubsConnectionStringSenderSetting = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender"); public static string EventHubsConnectionStringSenderSetting2 = Environment.GetEnvironmentVariable("AzureWebJobsEventHubSender_2"); From de114e8c70d5985a1b025f040dcc3f745f8869e0 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Wed, 24 Jul 2019 19:58:45 -0700 Subject: [PATCH 12/14] Commented the tests it needs the new CLI code --- .../EventHubsEndToEndTests.cs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs index 0e7d030d..98d7837a 100644 --- a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs @@ -88,7 +88,7 @@ public async Task EventHubTriggerCardinalityOne_Succeeds() } } - +/* [Fact] public async Task EventHubTriggerAndOutputBinaryListMany_Succeeds() { @@ -109,9 +109,9 @@ public async Task EventHubTriggerAndOutputBinaryListMany_Succeeds() await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); } } - +*/ [Fact] - public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() + public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() { string expectedEventId = Guid.NewGuid().ToString(); try @@ -132,7 +132,7 @@ public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() } [Fact] - public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() + /* public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() { string expectedEventId = Guid.NewGuid().ToString(); try @@ -151,6 +151,7 @@ public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); } } +*/ private static async Task SetupQueue(string queueName) { From 17f39dfb4c21ac4cc996082ee15e54e9d236ab1e Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Thu, 25 Jul 2019 10:12:05 -0700 Subject: [PATCH 13/14] Remove the tests till CLI update --- .../EventHubsEndToEndTests.cs | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs index 98d7837a..9f31ab33 100644 --- a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs @@ -88,7 +88,7 @@ public async Task EventHubTriggerCardinalityOne_Succeeds() } } -/* + [Fact] public async Task EventHubTriggerAndOutputBinaryListMany_Succeeds() { @@ -109,7 +109,7 @@ public async Task EventHubTriggerAndOutputBinaryListMany_Succeeds() await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); } } -*/ + [Fact] public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() { @@ -131,27 +131,27 @@ public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() } } - [Fact] - /* public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() - { - string expectedEventId = Guid.NewGuid().ToString(); - try - { - await SetupQueue(Constants.OutputBinaryArrayManyQueueName); - - await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyArrayEventHubQueueName, Constants.EventHubsConnectionStringSenderSetting2); - - //Verify - var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryArrayManyQueueName); - Assert.Contains(expectedEventId, queueMessage); - } - finally - { - //Clear queue - await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); - } - } -*/ + [Fact] + public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() + { + string expectedEventId = Guid.NewGuid().ToString(); + try + { + await SetupQueue(Constants.OutputBinaryArrayManyQueueName); + + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyArrayEventHubQueueName, Constants.EventHubsConnectionStringSenderSetting2); + + //Verify + var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryArrayManyQueueName); + Assert.Contains(expectedEventId, queueMessage); + } + finally + { + //Clear queue + await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); + } + } + private static async Task SetupQueue(string queueName) { From 6841f665988d5695baae8cca7d8ad06845245161 Mon Sep 17 00:00:00 2001 From: "Ahmed El Sayed (Mamoun)" <52262708+amamounelsayed@users.noreply.github.com> Date: Thu, 25 Jul 2019 10:18:42 -0700 Subject: [PATCH 14/14] Fix the comment --- .../EventHubsEndToEndTests.cs | 45 ++++++++++--------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs index 9f31ab33..55e59eec 100644 --- a/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs +++ b/endtoendtests/Azure.Functions.Java.Tests.E2E/Azure.Functions.Java.Tests.E2E/EventHubsEndToEndTests.cs @@ -88,7 +88,7 @@ public async Task EventHubTriggerCardinalityOne_Succeeds() } } - + /* [Fact] public async Task EventHubTriggerAndOutputBinaryListMany_Succeeds() { @@ -109,7 +109,7 @@ public async Task EventHubTriggerAndOutputBinaryListMany_Succeeds() await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); } } - + */ [Fact] public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() { @@ -130,27 +130,28 @@ public async Task EventHubTriggerAndOutputBinaryOne_Succeeds() await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); } } + /* + [Fact] + public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() + { + string expectedEventId = Guid.NewGuid().ToString(); + try + { + await SetupQueue(Constants.OutputBinaryArrayManyQueueName); - [Fact] - public async Task EventHubTriggerAndOutputBinaryArrayMany_Succeeds() - { - string expectedEventId = Guid.NewGuid().ToString(); - try - { - await SetupQueue(Constants.OutputBinaryArrayManyQueueName); - - await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyArrayEventHubQueueName, Constants.EventHubsConnectionStringSenderSetting2); - - //Verify - var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryArrayManyQueueName); - Assert.Contains(expectedEventId, queueMessage); - } - finally - { - //Clear queue - await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); - } - } + await EventHubsHelpers.SendMessagesAsync(expectedEventId, Constants.InputBinaryManyArrayEventHubQueueName, Constants.EventHubsConnectionStringSenderSetting2); + + //Verify + var queueMessage = await StorageHelpers.ReadFromQueue(Constants.OutputBinaryArrayManyQueueName); + Assert.Contains(expectedEventId, queueMessage); + } + finally + { + //Clear queue + await StorageHelpers.ClearQueue(Constants.OutputEventHubQueueName); + } + } + */ private static async Task SetupQueue(string queueName)