-
Notifications
You must be signed in to change notification settings - Fork 566
Fix Asynchronous Dispatch Logic in AwsAsyncContext with Spring's DispatcherServlet #631
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
4019c87
Fix dispatch order issue in async request handling
leekib 14ae260
Disable Servlet mapping tests of AwsAsyncContext
leekib 0738e25
Merge branch 'awslabs:main' into main
leekib 096c481
add tests
leekib 5615394
Add test case for AwsAsyncContext
leekib ab62529
fix handleRequest redispatch
leekib aa20391
fix handleRequest re-dispatch
leekib 3047ca9
add test case for spring
leekib ff1d5cf
edit test case for AwsAsyncContext
leekib 4a10969
Merge branch 'aws:main' into main
leekib 36a6803
Merge branch 'aws:main' into main
leekib 98434dd
Update spring-boot-starter-data-jpa version for test
leekib fc53fa6
Refactor: Move Redispatch Logic from Spring Boot 3 and Spring Package…
leekib 0982dc1
Deleted 2 disabled tests
leekib 185dfef
Merge branch 'aws:main' into main
leekib 96b1a4a
Remove AwsLambdaServletContainerHandler from AwsAsyncContext since it…
leekib 4e628fb
Merge remote-tracking branch 'origin/main'
leekib 1fa314b
Refactor Dispatch Start Check for Atomicity
leekib File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
46 changes: 46 additions & 0 deletions
46
...va-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/AsyncAppTest.java
This file contains hidden or 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,46 @@ | ||
package com.amazonaws.serverless.proxy.spring; | ||
|
||
import com.amazonaws.serverless.exceptions.ContainerInitializationException; | ||
import com.amazonaws.serverless.proxy.internal.testutils.AwsProxyRequestBuilder; | ||
import com.amazonaws.serverless.proxy.internal.testutils.MockLambdaContext; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyRequest; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyResponse; | ||
import com.amazonaws.serverless.proxy.spring.springapp.LambdaHandler; | ||
import com.amazonaws.serverless.proxy.spring.springapp.MessageController; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
public class AsyncAppTest { | ||
|
||
private static LambdaHandler handler; | ||
|
||
@BeforeAll | ||
public static void setUp() { | ||
try { | ||
handler = new LambdaHandler(); | ||
} catch (ContainerInitializationException e) { | ||
e.printStackTrace(); | ||
fail(); | ||
} | ||
} | ||
|
||
@Test | ||
void springApp_helloRequest_returnsCorrect() { | ||
AwsProxyRequest req = new AwsProxyRequestBuilder("/hello", "GET").build(); | ||
AwsProxyResponse resp = handler.handleRequest(req, new MockLambdaContext()); | ||
assertEquals(200, resp.getStatusCode()); | ||
assertEquals(MessageController.HELLO_MESSAGE, resp.getBody()); | ||
} | ||
|
||
@Test | ||
void springApp_asyncRequest_returnsCorrect() { | ||
AwsProxyRequest req = new AwsProxyRequestBuilder("/async", "GET").build(); | ||
AwsProxyResponse resp = handler.handleRequest(req, new MockLambdaContext()); | ||
assertEquals(200, resp.getStatusCode()); | ||
assertEquals(MessageController.HELLO_MESSAGE, resp.getBody()); | ||
} | ||
|
||
} |
8 changes: 8 additions & 0 deletions
8
...ainer-spring/src/test/java/com/amazonaws/serverless/proxy/spring/springapp/AppConfig.java
This file contains hidden or 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,8 @@ | ||
package com.amazonaws.serverless.proxy.spring.springapp; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
|
||
@Configuration | ||
@Import({MessageController.class}) | ||
public class AppConfig { } |
26 changes: 26 additions & 0 deletions
26
...r-spring/src/test/java/com/amazonaws/serverless/proxy/spring/springapp/LambdaHandler.java
This file contains hidden or 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,26 @@ | ||
package com.amazonaws.serverless.proxy.spring.springapp; | ||
|
||
import com.amazonaws.serverless.exceptions.ContainerInitializationException; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyRequest; | ||
import com.amazonaws.serverless.proxy.model.AwsProxyResponse; | ||
import com.amazonaws.serverless.proxy.spring.SpringLambdaContainerHandler; | ||
import com.amazonaws.serverless.proxy.spring.SpringProxyHandlerBuilder; | ||
import com.amazonaws.services.lambda.runtime.Context; | ||
import com.amazonaws.services.lambda.runtime.RequestHandler; | ||
|
||
public class LambdaHandler implements RequestHandler<AwsProxyRequest, AwsProxyResponse> { | ||
private SpringLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler; | ||
|
||
public LambdaHandler() throws ContainerInitializationException { | ||
handler = new SpringProxyHandlerBuilder<AwsProxyRequest>() | ||
.defaultProxy() | ||
.asyncInit() | ||
.configurationClasses(AppConfig.class) | ||
.buildAndInitialize(); | ||
} | ||
|
||
@Override | ||
public AwsProxyResponse handleRequest(AwsProxyRequest awsProxyRequest, Context context) { | ||
return handler.proxy(awsProxyRequest, context); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...ring/src/test/java/com/amazonaws/serverless/proxy/spring/springapp/MessageController.java
This file contains hidden or 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,25 @@ | ||
package com.amazonaws.serverless.proxy.spring.springapp; | ||
|
||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestMethod; | ||
import org.springframework.web.bind.annotation.RestController; | ||
import org.springframework.web.context.request.async.DeferredResult; | ||
import org.springframework.web.servlet.config.annotation.EnableWebMvc; | ||
|
||
@RestController | ||
@EnableWebMvc | ||
public class MessageController { | ||
public static final String HELLO_MESSAGE = "Hello"; | ||
|
||
@RequestMapping(path="/hello", method= RequestMethod.GET) | ||
public String hello() { | ||
return HELLO_MESSAGE; | ||
} | ||
|
||
@RequestMapping(path="/async", method= RequestMethod.GET) | ||
public DeferredResult<String> asyncHello() { | ||
DeferredResult<String> result = new DeferredResult<>(); | ||
result.setResult(HELLO_MESSAGE); | ||
return result; | ||
} | ||
} |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.