-
Notifications
You must be signed in to change notification settings - Fork 65
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set Thread Context ClassLoader correctly when invoking handler c…
…onstructor (#239)
- Loading branch information
1 parent
6dfc3c7
commit 9f7155b
Showing
2 changed files
with
40 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
invoker/core/src/test/java/com/google/cloud/functions/invoker/HttpFunctionExecutorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package com.google.cloud.functions.invoker; | ||
|
||
import static com.google.common.truth.Truth.assertThat; | ||
|
||
import com.google.cloud.functions.HttpFunction; | ||
import com.google.cloud.functions.HttpRequest; | ||
import com.google.cloud.functions.HttpResponse; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class HttpFunctionExecutorTest { | ||
private static ClassLoader customClassLoader = | ||
new ClassLoader(ClassLoader.getSystemClassLoader()) {}; | ||
|
||
public static class ClassLoaderVerifier implements HttpFunction { | ||
public ClassLoaderVerifier() { | ||
assertThat(Thread.currentThread().getContextClassLoader()) | ||
.isNotSameInstanceAs(customClassLoader); | ||
} | ||
|
||
@Override | ||
public void service(HttpRequest request, HttpResponse response) throws Exception { | ||
throw new UnsupportedOperationException("Not implemented"); | ||
} | ||
} | ||
|
||
@Test | ||
public void usesCorrectClassLoaderOverride() { | ||
ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader(); | ||
Thread.currentThread().setContextClassLoader(customClassLoader); | ||
HttpFunctionExecutor.forClass(ClassLoaderVerifier.class); | ||
Thread.currentThread().setContextClassLoader(oldClassLoader); | ||
} | ||
} |