Skip to content

Commit

Permalink
Adding debug in Jenkins to spot the issue
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Bescos Gascon <[email protected]>
  • Loading branch information
jbescos committed Jul 9, 2021
1 parent 294be77 commit d9b1098
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All @@ -35,7 +34,6 @@

import org.glassfish.jersey.client.ClientConfig;
import org.glassfish.jersey.internal.guava.ThreadFactoryBuilder;
import org.glassfish.jersey.jdk.connector.JdkConnectorProperties;
import org.glassfish.jersey.jdk.connector.JdkConnectorProvider;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.test.JerseyTest;
Expand All @@ -44,29 +42,15 @@

public class StressTest extends JerseyTest {

private static final int PARALLELISM = 10;
private static final int IDLE_TIMEOUT = 50;
private static final int PARALLELISM = 50;
private static final int ITERATIONS = 1000;
private static CountDownLatch requests;
private static CountDownLatch latch;

@Path("/test")
public static class TestResource {
@GET
@Path("/1")
public String test1() throws InterruptedException {
requests.countDown();
if (latch.await(10, TimeUnit.SECONDS)) {
return "test1";
} else {
throw new IllegalStateException("Timeout");
}
}

@GET
@Path("/2")
public String test2() {
return "test2";
public String test() {
return "test";
}
}

Expand All @@ -79,33 +63,9 @@ protected Application configure() {

@Override
protected void configureClient(ClientConfig config) {
config.property(JdkConnectorProperties.MAX_CONNECTIONS_PER_DESTINATION, PARALLELISM);
config.property(JdkConnectorProperties.CONNECTION_IDLE_TIMEOUT, IDLE_TIMEOUT);
config.connectorProvider(new JdkConnectorProvider());
}

@Test
public void hangAllRequestsStatus200() throws InterruptedException, ExecutionException {
ExecutorService executor = Executors.newFixedThreadPool(PARALLELISM,
new ThreadFactoryBuilder().setNameFormat("client-%d").build());
for (int i = 0; i < ITERATIONS; i++) {
requests = new CountDownLatch(PARALLELISM);
latch = new CountDownLatch(1);
List<Future<Response>> responses = new ArrayList<>();
for (int j = 0; j < PARALLELISM; j++) {
Future<Response> future = executor.submit(() -> target("/test/1").request().get());
responses.add(future);
}
assertTrue(requests.await(20, TimeUnit.SECONDS));
latch.countDown();
for (Future<Response> response : responses) {
assertEquals(200, response.get().getStatus());
}
}
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
}

@Test
public void randomnessStatus200() throws InterruptedException, ExecutionException {
ExecutorService executor = Executors.newFixedThreadPool(PARALLELISM,
Expand All @@ -114,7 +74,7 @@ public void randomnessStatus200() throws InterruptedException, ExecutionExceptio
System.out.println("Iteration " + i);
List<Future<Response>> responses = new ArrayList<>();
for (int j = 0; j < 100; j++) {
Future<Response> future = executor.submit(() -> target("/test/2").request().get());
Future<Response> future = executor.submit(() -> target("/test").request().get());
responses.add(future);
}
for (Future<Response> response : responses) {
Expand All @@ -124,16 +84,4 @@ public void randomnessStatus200() throws InterruptedException, ExecutionExceptio
executor.shutdown();
assertTrue(executor.awaitTermination(10, TimeUnit.SECONDS));
}

@Test
public void syncTest() {
Response response = target("/test/2").request().get();
assertEquals(200, response.getStatus());
}

@Test
public void asyncTest() throws InterruptedException, ExecutionException {
Future<Response> response = target("/test/2").request().async().get();
assertEquals(200, response.get().getStatus());
}
}
2 changes: 1 addition & 1 deletion etc/jenkins/jenkins_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@

export DEBUG=true

mvn -V -U -B -e clean install glassfish-copyright:check -Dcopyright.quiet=false -Dsurefire.systemPropertiesFile=${WORKSPACE}/etc/jenkins/systemPropertiesFile
mvn -X -V -U -B -e clean install glassfish-copyright:check -Dcopyright.quiet=false -Dsurefire.systemPropertiesFile=${WORKSPACE}/etc/jenkins/systemPropertiesFile

0 comments on commit d9b1098

Please sign in to comment.