Skip to content

Commit 0b4d5b6

Browse files
Fix the load for no lib case.
1 parent 903da5b commit 0b4d5b6

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

src/main/java/com/microsoft/azure/functions/worker/broker/JavaFunctionBroker.java

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,33 @@ public Map<String, TypedData> getTriggerMetadataMap(InvocationRequest request) {
8989
private void addSearchPathsToClassLoader(FunctionMethodDescriptor function) throws IOException {
9090
URL jarUrl = new File(function.getJarPath()).toURI().toURL();
9191
classLoaderProvider.addUrl(jarUrl);
92-
function.getLibDirectory().ifPresent(d -> registerWithClassLoaderProvider(d));
92+
if(function.getLibDirectory().isPresent()) {
93+
registerWithClassLoaderProvider(function.getLibDirectory().get());
94+
} else {
95+
registerWithClassLoaderProviderWorkerLibOnly();
96+
}
97+
}
98+
99+
void registerWithClassLoaderProviderWorkerLibOnly() {
100+
try {
101+
if(SystemUtils.IS_JAVA_1_8 && !isTesting()) {
102+
String workerLibPath = System.getenv(Constants.FUNCTIONS_WORKER_DIRECTORY) + "/lib";
103+
File workerLib = new File(workerLibPath);
104+
verifyLibrariesExist (workerLib, workerLibPath);
105+
classLoaderProvider.addDirectory(workerLib);
106+
}
107+
} catch (Exception ex) {
108+
ExceptionUtils.rethrow(ex);
109+
}
110+
}
111+
112+
private boolean isTesting(){
113+
if(System.getProperty("azure.functions.worker.java.skip.testing") != null
114+
&& System.getProperty("azure.functions.worker.java.skip.testing").equals("true")) {
115+
return true;
116+
} else {
117+
return false;
118+
}
93119
}
94120

95121
void registerWithClassLoaderProvider(File libDirectory) {

src/test/java/com/microsoft/azure/functions/worker/broker/JavaFunctionBrokerTest.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.microsoft.azure.functions.rpc.messages.ParameterBinding;
55
import com.microsoft.azure.functions.rpc.messages.TypedData;
66
import com.microsoft.azure.functions.worker.broker.JavaFunctionBroker;
7+
import com.microsoft.azure.functions.worker.description.FunctionMethodDescriptor;
78
import com.microsoft.azure.functions.worker.reflect.DefaultClassLoaderProvider;
89
import mockit.*;
910
import org.junit.Test;
@@ -123,4 +124,10 @@ public void checkLibFolderNoJarsInLib() throws Exception {
123124
File file = new File(path);
124125
broker.verifyLibrariesExist (file, path);
125126
}
127+
128+
@Test(expected = FileNotFoundException.class)
129+
public void registerWithClassLoaderProviderWorkerLibOnly_Exception() throws Exception {
130+
JavaFunctionBroker broker = new JavaFunctionBroker(null);
131+
broker.registerWithClassLoaderProviderWorkerLibOnly();
132+
}
126133
}

src/test/java/com/microsoft/azure/functions/worker/functional/tests/SimpleParamReturnTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public String ReturnStringFunction() {
2828
@Test
2929
public void testStringData() throws Exception {
3030
stringReturnValue = stringInput;
31+
System.setProperty("azure.functions.worker.java.skip.testing", "true");
3132
try (FunctionsTestHost host = new FunctionsTestHost()) {
3233
this.loadFunction(host, "returnStringTestId", "ReturnStringFunction");
3334
InvocationResponse stringResponse = host.call("getret", "returnStringTestId");

0 commit comments

Comments
 (0)