-
Notifications
You must be signed in to change notification settings - Fork 890
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use SecureRandom in AsynchronousDispatcher to generate job ids.
- Loading branch information
Showing
7 changed files
with
170 additions
and
3 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
80 changes: 80 additions & 0 deletions
80
...ite/integration-tests/src/test/java/org/jboss/resteasy/test/asynch/AsynchCounterTest.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,80 @@ | ||
| package org.jboss.resteasy.test.asynch; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.Map; | ||
|
|
||
| import javax.servlet.http.HttpServletResponse; | ||
| import javax.ws.rs.client.Client; | ||
| import javax.ws.rs.client.ClientBuilder; | ||
| import javax.ws.rs.core.HttpHeaders; | ||
| import javax.ws.rs.core.Response; | ||
|
|
||
| import org.jboss.arquillian.container.test.api.Deployment; | ||
| import org.jboss.arquillian.container.test.api.RunAsClient; | ||
| import org.jboss.arquillian.junit.Arquillian; | ||
| import org.jboss.resteasy.test.asynch.resource.AsynchCounterResource; | ||
| import org.jboss.resteasy.utils.PortProviderUtil; | ||
| import org.jboss.resteasy.utils.TestUtil; | ||
| import org.jboss.shrinkwrap.api.Archive; | ||
| import org.jboss.shrinkwrap.api.spec.WebArchive; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.Test; | ||
| import org.junit.runner.RunWith; | ||
|
|
||
| /** | ||
| * @tpSubChapter Asynchronous RESTEasy | ||
| * @tpChapter Integration tests | ||
| * @tpTestCaseDetails Tests use of SecureRandom to generate location job ids | ||
| * @tpSince RESTEasy 3.1.0.Final | ||
| */ | ||
| @RunWith(Arquillian.class) | ||
| @RunAsClient | ||
| public class AsynchCounterTest { | ||
|
|
||
| static Client client; | ||
|
|
||
| @BeforeClass | ||
| public static void setup() { | ||
| client = ClientBuilder.newClient(); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void close() { | ||
| client.close(); | ||
| } | ||
|
|
||
| @Deployment | ||
| public static Archive<?> deploy() { | ||
| WebArchive war = TestUtil.prepareArchive(AsynchCounterTest.class.getSimpleName()); | ||
| Map<String, String> contextParam = new HashMap<>(); | ||
| contextParam.put("resteasy.async.job.service.enabled", "true"); | ||
| contextParam.put("resteasy.secure.random.max.use", "2"); | ||
| return TestUtil.finishContainerPrepare(war, contextParam, AsynchCounterResource.class); | ||
| } | ||
|
|
||
| private String generateURL(String path) { | ||
| return PortProviderUtil.generateURL(path, AsynchCounterTest.class.getSimpleName()); | ||
| } | ||
|
|
||
| /** | ||
| * @tpTestDetails Test that job ids are no longer consecutive | ||
| * @tpSince RESTEasy 3.1.0.Final | ||
| */ | ||
| @Test | ||
| public void testAsynchCounter() throws Exception { | ||
|
|
||
| Response response = client.target(generateURL("?asynch=true")).request().get(); | ||
| Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); | ||
| String jobUrl = response.getHeaderString(HttpHeaders.LOCATION); | ||
| int job1 = Integer.parseInt(jobUrl.substring(jobUrl.lastIndexOf('-') + 1)); | ||
| response.close(); | ||
| response = client.target(generateURL("?asynch=true")).request().get(); | ||
| Assert.assertEquals(HttpServletResponse.SC_ACCEPTED, response.getStatus()); | ||
| jobUrl = response.getHeaderString(HttpHeaders.LOCATION); | ||
| int job2 = Integer.parseInt(jobUrl.substring(jobUrl.lastIndexOf('-') + 1)); | ||
| Assert.assertTrue(job2 != job1 + 1); | ||
| response.close(); | ||
| } | ||
| } |
14 changes: 14 additions & 0 deletions
14
...on-tests/src/test/java/org/jboss/resteasy/test/asynch/resource/AsynchCounterResource.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,14 @@ | ||
| package org.jboss.resteasy.test.asynch.resource; | ||
|
|
||
| import javax.ws.rs.GET; | ||
| import javax.ws.rs.Path; | ||
|
|
||
| @Path("/") | ||
| public class AsynchCounterResource { | ||
|
|
||
| @GET | ||
| public String get() throws Exception { | ||
| Thread.sleep(1500); | ||
| return "get"; | ||
| } | ||
| } |