Repository: Azure/azure-functions-java-worker
Pull request #366 (2020-05-05 23:51:53)

Revert "Support RpcHttpBodyOnly and RpcHttpTriggerMetadataRemoved"
Reverts Azure/azure-functions-java-worker#364


Patch:
diff --git a/pom.xml b/pom.xml
index 06aa909..1654312 100644
--- a/pom.xml
+++ b/pom.xml
@@ -113,12 +113,6 @@
    			<artifactId>jna-platform</artifactId>
    			<version>5.3.0</version>
 		</dependency>
-		<dependency>
-			<groupId>org.jmockit</groupId>
-			<artifactId>jmockit</artifactId>
-			<version>1.49</version>
-			<scope>test</scope>
-		</dependency>
 	</dependencies>
 
 	<build>
@@ -243,15 +237,6 @@
 					</execution>
 				</executions>
 			</plugin>
-			<plugin>
-				<artifactId>maven-surefire-plugin</artifactId>
-				<version>2.22.2</version> <!-- or some other version -->
-				<configuration>
-					<argLine>
-						-javaagent:"${settings.localRepository}"\org\jmockit\jmockit\1.49\jmockit-1.49.jar
-					</argLine>
-				</configuration>
-			</plugin>
 		</plugins>
 	</build>
 </project>
diff --git a/src/main/java/com/microsoft/azure/functions/worker/Constants.java b/src/main/java/com/microsoft/azure/functions/worker/Constants.java
deleted file mode 100644
index 8be2597..0000000
--- a/src/main/java/com/microsoft/azure/functions/worker/Constants.java
+++ /dev/null
@@ -1,9 +0,0 @@
-package com.microsoft.azure.functions.worker;
-
-/**
- * The Constants file for Java language worker
- */
-public final class Constants {
-    private Constants(){}
-    public final static String TRIGGER_METADATA_DOLLAR_REQUEST_KEY = "$request";
-}
diff --git a/src/main/java/com/microsoft/azure/functions/worker/broker/JavaFunctionBroker.java b/src/main/java/com/microsoft/azure/functions/worker/broker/JavaFunctionBroker.java
index 9ba5637..3838f05 100644
--- a/src/main/java/com/microsoft/azure/functions/worker/broker/JavaFunctionBroker.java
+++ b/src/main/java/com/microsoft/azure/functions/worker/broker/JavaFunctionBroker.java
@@ -3,11 +3,12 @@ package com.microsoft.azure.functions.worker.broker;
 import java.io.File;
 import java.io.IOException;
 import java.net.URL;
-import java.util.*;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
 import java.util.concurrent.ConcurrentHashMap;
 
 import com.microsoft.azure.functions.rpc.messages.*;
-import com.microsoft.azure.functions.worker.Constants;
 import com.microsoft.azure.functions.worker.binding.BindingDataStore;
 import com.microsoft.azure.functions.worker.description.FunctionMethodDescriptor;
 import com.microsoft.azure.functions.worker.reflect.ClassLoaderProvider;
@@ -45,7 +46,7 @@ public class JavaFunctionBroker {
 
 		BindingDataStore dataStore = new BindingDataStore();
 		dataStore.setBindingDefinitions(executor.getBindingDefinitions());
-		dataStore.addTriggerMetadataSource(getTriggerMetadataMap(request));
+		dataStore.addTriggerMetadataSource(request.getTriggerMetadataMap());
 		dataStore.addParameterSources(request.getInputDataList());
 		dataStore.addExecutionContextSource(request.getInvocationId(), methodEntry.left, request.getTraceContext().getTraceParent(), request.getTraceContext().getTraceState(), request.getTraceContext().getAttributesMap());
 
@@ -58,29 +59,6 @@ public class JavaFunctionBroker {
 		return Optional.ofNullable(this.methods.get(id)).map(entry -> entry.left);
 	}
 
-	// TODO the scope should be package private for testability. Modify the package name as same as main package
-	public Map<String, TypedData> getTriggerMetadataMap(InvocationRequest request) {
-		String    name ="";
-		TypedData dataWithHttp = null;
-		for(ParameterBinding e: request.getInputDataList()) {
-			if (e.getData().hasHttp()) {
-				dataWithHttp = e.getData();
-				name = e.getName();
-				break;
-			}
-		}
-
-		Map<String, TypedData> triggerMetadata = new HashMap(request.getTriggerMetadataMap());
-		if (!name.isEmpty() && !triggerMetadata.containsKey(name)) {
-			triggerMetadata.put(name, dataWithHttp);
-		}
-		String requestKey = Constants.TRIGGER_METADATA_DOLLAR_REQUEST_KEY;
-		if (dataWithHttp != null & !triggerMetadata.containsKey(requestKey)) {
-			triggerMetadata.put(requestKey, dataWithHttp);
-		}
-		return Collections.unmodifiableMap(triggerMetadata);
-	}
-
 	private void addSearchPathsToClassLoader(FunctionMethodDescriptor function) throws IOException {
 		URL jarUrl = new File(function.getJarPath()).toURI().toURL();
 		classLoaderProvider.addUrl(jarUrl);
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 7190f5a..7f6003f 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
@@ -16,8 +16,6 @@ public class WorkerInitRequestHandler extends MessageHandler<WorkerInitRequest,
         response.setWorkerVersion(Application.version());
         response.putCapabilities("TypedDataCollection", "TypedDataCollection");
         response.putCapabilities("WorkerStatus", "WorkerStatus");
-        response.putCapabilities("RpcHttpBodyOnly", "RpcHttpBodyOnly");
-        response.putCapabilities("RpcHttpTriggerMetadataRemoved", "RpcHttpTriggerMetadataRemoved");
         return "Worker initialized";
     }
 }


Test patch:
diff --git a/src/test/java/com/microsoft/azure/functions/worker/broker/tests/JavaFunctionBrokerTest.java b/src/test/java/com/microsoft/azure/functions/worker/broker/tests/JavaFunctionBrokerTest.java
deleted file mode 100644
index 1422c56..0000000
--- a/src/test/java/com/microsoft/azure/functions/worker/broker/tests/JavaFunctionBrokerTest.java
+++ /dev/null
@@ -1,108 +0,0 @@
-package com.microsoft.azure.functions.worker.broker.tests;
-
-import com.microsoft.azure.functions.rpc.messages.InvocationRequest;
-import com.microsoft.azure.functions.rpc.messages.ParameterBinding;
-import com.microsoft.azure.functions.rpc.messages.TypedData;
-import com.microsoft.azure.functions.worker.broker.JavaFunctionBroker;
-import com.microsoft.azure.functions.worker.reflect.DefaultClassLoaderProvider;
-import mockit.*;
-import org.junit.Test;
-import java.util.*;
-
-import static org.junit.Assert.assertEquals;
-
-public class JavaFunctionBrokerTest {
-
-    @Test
-    public void getTriggerMetadataMap_success(
-            @Mocked InvocationRequest request,
-            @Mocked ParameterBinding binding,
-            @Mocked TypedData bindingData,
-            @Mocked TypedData name,
-            @Mocked TypedData query,
-            @Mocked TypedData headers,
-            @Mocked TypedData sys
-            ) throws Exception {
-
-        String expectedData = "http {\n  method: \"GET\"\n  url: \"https://localhost:5001/api/HttpExample?name=ushio\"\n  headers {\n    key: \"cache-control\"\n    value: \"max-age=0\"\n  }\n  headers {\n    key: \"connection\"\n    value: \"Keep-Alive\"\n  }\n  headers {\n    key: \"accept\"\n    value: \"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\"\n  }\n  headers {\n    key: \"accept-encoding\"\n    value: \"gzip, deflate, br\"\n  }\n  headers {\n    key: \"accept-language\"\n    value: \"en-US,ja;q=0.8,en-GB;q=0.5,en;q=0.3\"\n  }\n  headers {\n    key: \"host\"\n    value: \"localhost:5001\"\n  }\n  headers {\n    key: \"user-agent\"\n    value: \"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041\"\n  }\n  headers {\n    key: \"upgrade-insecure-requests\"\n    value: \"1\"\n  }\n  query {\n    key: \"name\"\n    value: \"ushio\"\n  }\n  identities {\n    name_claim_type {\n      value: \"http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name\"\n    }\n    role_claim_type {\n      value: \"http://schemas.microsoft.com/ws/2008/06/identity/claims/role\"\n    }\n  }\n}\n";
-        String expectedName = "req";
-        new Expectations() {{
-            bindingData.hasHttp(); result = true;
-            bindingData.getString(); result = expectedData;
-            binding.getName(); result = expectedName;
-            binding.getData(); result = bindingData;
-            request.getInputDataList(); result = Arrays.asList(binding);
-
-            name.getString(); result = "string: \"John\"\n"; minTimes = 0;
-            query.getString(); result = "json: \"{\"name\":\"ushio\"}\""; minTimes = 0;
-            headers.getString(); result = "json: \"{\"Cache-Control\":\"max-age=0\",\"Connection\":\"Keep-Alive\",\"Accept\":\"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\",\"Accept-Encoding\":\"gzip, deflate, br\",\"Accept-Language\":\"en-US,ja;q=0.8,en-GB;q=0.5,en;q=0.3\",\"Host\":\"localhost:5001\",\"User-Agent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.102 Safari/537.36 Edge/18.19041\",\"Upgrade-Insecure-Requests\":\"1\"}\""; minTimes = 0;
-            sys.getString(); result = "json: \"{\"MethodName\":\"HttpExample\",\"UtcNow\":\"2020-04-30T15:26:57.281277Z\",\"RandGuid\":\"cd332c4a-df9e-415a-acd4-973994072e46\"}\""; minTimes = 0;
-
-            Map<String,TypedData> triggerMetadata = new HashMap<String, TypedData>();
-            triggerMetadata.put("name", name);
-            triggerMetadata.put("Query", query);
-            triggerMetadata.put("Headers", headers);
-            triggerMetadata.put("sys", sys);
-            request.getTriggerMetadataMap(); result = Collections.unmodifiableMap(triggerMetadata);
-        }};
-
-        JavaFunctionBroker broker = new JavaFunctionBroker(new DefaultClassLoaderProvider());
-        Map<String, TypedData> actualTriggerMetadata = broker.getTriggerMetadataMap(request);
-        TypedData actual = actualTriggerMetadata.get("$request");
-        assertEquals(actual.getString(), expectedData);
-        TypedData actual2 = actualTriggerMetadata.get(expectedName);
-        assertEquals(actual2.getString(), expectedData);
-    }
-
-    @Test
-    public void getTriggerMetadataMap_ignored(
-            @Mocked InvocationRequest request,
-            @Mocked ParameterBinding binding,
-            @Mocked TypedData bindingData,
-            @Mocked TypedData queueTrigger,
-            @Mocked TypedData dequeueCount,
-            @Mocked TypedData expirationTime,
-            @Mocked TypedData id,
-            @Mocked TypedData insertionTime,
-            @Mocked TypedData nextVisibleTime,
-            @Mocked TypedData popReceipt,
-            @Mocked TypedData sys
-    ) throws Exception {
-
-        String data = "string: \"hello queue\"\n";
-        String name = "msg";
-        new Expectations() {{
-            bindingData.hasHttp(); result = false;
-            bindingData.getString(); result = data; minTimes = 0;
-            binding.getName(); result = name; minTimes = 0;
-            binding.getData(); result = bindingData; minTimes = 0;
-            request.getInputDataList(); result = Arrays.asList(binding);
-
-            queueTrigger.getString(); result = "string: \"hello queue\"\n"; minTimes = 0;
-            dequeueCount.getString(); result = "json: \"1\"\n"; minTimes = 0;
-            expirationTime.getString(); result = "json: \"\"2020-05-08T17:47:22+00:00\"\n"; minTimes = 0;
-            id.getString(); result = "string: \"e4f4a332-df80-41a1-8ecd-c2f7fba91f28\"\n"; minTimes = 0;
-            insertionTime.getString(); result = "json: \"\"2020-05-01T17:47:22+00:00\"\n"; minTimes = 0;
-            nextVisibleTime.getString(); result = "json: \"\"2020-05-01T17:57:22+00:00\"\n"; minTimes = 0;
-            popReceipt.getString(); result = "string: \"oJCJGfnt1wgBAAAA\"\n"; minTimes = 0;
-            sys.getString(); result =  "json: \"{\"MethodName\":\"QueueProcessor\",\"UtcNow\":\"2020-05-01T17:47:29.2664174Z\",\"RandGuid\":\"7f67ac1c-b7b0-43f5-a51a-73af321d7d9f\"}\n"; minTimes = 0;
-
-            Map<String,TypedData> triggerMetadata = new HashMap<String, TypedData>();
-            triggerMetadata.put("QueueTrigger", queueTrigger);
-            triggerMetadata.put("DequeueCount", dequeueCount);
-            triggerMetadata.put("ExpirationTime", expirationTime);
-            triggerMetadata.put("Id", id);
-            triggerMetadata.put("InsertionTime", insertionTime);
-            triggerMetadata.put("NextVisibleTime", nextVisibleTime);
-            triggerMetadata.put("PopReceipt", popReceipt);
-            triggerMetadata.put("sys", sys);
-            request.getTriggerMetadataMap(); result = Collections.unmodifiableMap(triggerMetadata);
-        }};
-
-        int expectedCount = request.getTriggerMetadataMap().size();
-        JavaFunctionBroker broker = new JavaFunctionBroker(new DefaultClassLoaderProvider());
-        Map<String, TypedData> actualTriggerMetadata = broker.getTriggerMetadataMap(request);
-        // In case of non-http request, it will not modify the triggerMetadata
-        assertEquals(expectedCount, actualTriggerMetadata.size());
-    }
-}
diff --git a/src/test/java/com/microsoft/azure/functions/worker/test/utilities/FunctionsTestHost.java b/src/test/java/com/microsoft/azure/functions/worker/test/utilities/FunctionsTestHost.java
index 207f063..63d792d 100644
--- a/src/test/java/com/microsoft/azure/functions/worker/test/utilities/FunctionsTestHost.java
+++ b/src/test/java/com/microsoft/azure/functions/worker/test/utilities/FunctionsTestHost.java
@@ -1,7 +1,6 @@
 package com.microsoft.azure.functions.worker.test.utilities;
 
 import java.io.*;
-import java.net.ServerSocket;
 import java.util.*;
 import java.util.concurrent.atomic.*;
 import java.util.concurrent.locks.*;
@@ -18,23 +17,11 @@ import io.grpc.stub.*;
 import org.apache.commons.lang3.tuple.*;
 
 public final class FunctionsTestHost implements AutoCloseable, IApplication {
-    private int port;
     public FunctionsTestHost() throws Exception {
-        this.port = populatePort();
         this.initializeServer();
         this.initializeClient();
     }
 
-    private final List<Integer> list = Arrays.asList(55005, 5005);
-
-    private int populatePort() {
-        try (ServerSocket ignored = new ServerSocket(this.list.get(0))) {
-            return this.list.get(0);
-        } catch (IOException e) {
-            return this.list.get(1);
-        }
-    }
-
     @PostConstruct
     private void initializeServer() throws IOException {
         ServerBuilder<?> builder = ServerBuilder.forPort(this.getPort());
@@ -78,7 +65,7 @@ public final class FunctionsTestHost implements AutoCloseable, IApplication {
     @Override
     public String getHost() { return "localhost"; }
     @Override
-    public int getPort() { return this.port; }
+    public int getPort() { return 55005; }
     @Override
     public Integer getMaxMessageSize() { return null; }