-
Notifications
You must be signed in to change notification settings - Fork 560
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from awslabs/spark-upgrade
Spark upgrade
- Loading branch information
Showing
13 changed files
with
168 additions
and
68 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
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
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
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
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
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
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
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
75 changes: 75 additions & 0 deletions
75
...er-spark/src/test/java/com/amazonaws/serverless/proxy/spark/InitExceptionHandlerTest.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,75 @@ | ||
package com.amazonaws.serverless.proxy.spark; | ||
|
||
|
||
import com.amazonaws.serverless.exceptions.ContainerInitializationException; | ||
import com.amazonaws.serverless.proxy.internal.AwsProxyExceptionHandler; | ||
import com.amazonaws.serverless.proxy.internal.AwsProxySecurityContextWriter; | ||
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletRequestReader; | ||
import com.amazonaws.serverless.proxy.internal.servlet.AwsProxyHttpServletResponseWriter; | ||
import com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServer; | ||
import com.amazonaws.serverless.proxy.spark.embeddedserver.LambdaEmbeddedServerFactory; | ||
|
||
import org.junit.AfterClass; | ||
import org.junit.Test; | ||
import spark.Spark; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.fail; | ||
import static org.mockito.Matchers.anyInt; | ||
import static org.mockito.Matchers.anyObject; | ||
import static org.mockito.Matchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.reset; | ||
import static org.mockito.Mockito.when; | ||
import static spark.Spark.get; | ||
import static spark.Spark.initExceptionHandler; | ||
|
||
|
||
public class InitExceptionHandlerTest { | ||
|
||
private static final String TEST_EXCEPTION_MESSAGE = "test exception"; | ||
private static LambdaEmbeddedServer embeddedServer = mock(LambdaEmbeddedServer.class); | ||
|
||
@Test | ||
public void initException_mockException_expectHandlerToRun() { | ||
try { | ||
|
||
when(embeddedServer.ignite(anyString(), anyInt(), anyObject(), anyInt(), anyInt(), anyInt())) | ||
.thenThrow(new ContainerInitializationException(TEST_EXCEPTION_MESSAGE, null)); | ||
LambdaEmbeddedServerFactory serverFactory = new LambdaEmbeddedServerFactory(embeddedServer); | ||
new SparkLambdaContainerHandler<>(new AwsProxyHttpServletRequestReader(), | ||
new AwsProxyHttpServletResponseWriter(), | ||
new AwsProxySecurityContextWriter(), | ||
new AwsProxyExceptionHandler(), | ||
serverFactory); | ||
|
||
configureRoutes(); | ||
|
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
fail("Error while mocking server"); | ||
} | ||
|
||
} | ||
|
||
@AfterClass | ||
public static void stopSpark() { | ||
// un-mock the embedded server to avoid blocking other tests | ||
reset(embeddedServer); | ||
// reset the static variable in the factory so that it will be instantiated again next time | ||
new LambdaEmbeddedServerFactory(null); | ||
Spark.stop(); | ||
} | ||
|
||
private static void configureRoutes() { | ||
initExceptionHandler((e) -> { | ||
System.out.println("Exception Handler called: " + e.getLocalizedMessage()); | ||
assertEquals(TEST_EXCEPTION_MESSAGE, e.getLocalizedMessage()); | ||
}); | ||
|
||
get("/test-route", (req, res) -> { | ||
res.status(200); | ||
return "test"; | ||
}); | ||
} | ||
} |
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
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
Oops, something went wrong.