Skip to content

Commit 2a4b485

Browse files
senivamjansupol
authored andcommitted
ErrorTest adjustments
Signed-off-by: Maxim Nesen <maxim.nesen@oracle.com>
1 parent 5c58377 commit 2a4b485

File tree

1 file changed

+18
-10
lines changed
  • connectors/jnh-connector/src/test/java/org/glassfish/jersey/jnh/connector

1 file changed

+18
-10
lines changed

connectors/jnh-connector/src/test/java/org/glassfish/jersey/jnh/connector/ErrorTest.java

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,18 @@
2222
import jakarta.ws.rs.client.Entity;
2323
import jakarta.ws.rs.client.WebTarget;
2424
import jakarta.ws.rs.core.Application;
25+
import jakarta.ws.rs.core.Feature;
2526
import jakarta.ws.rs.core.Response;
2627
import org.glassfish.jersey.client.ClientConfig;
2728
import org.glassfish.jersey.logging.LoggingFeature;
2829
import org.glassfish.jersey.server.ResourceConfig;
2930
import org.glassfish.jersey.test.JerseyTest;
3031
import org.junit.Test;
3132

33+
import java.util.ArrayList;
34+
import java.util.List;
35+
import java.util.concurrent.ExecutionException;
36+
import java.util.concurrent.Future;
3237
import java.util.logging.Logger;
3338

3439
import static org.junit.Assert.assertEquals;
@@ -67,13 +72,11 @@ public Response postWithEntity(String entity) {
6772

6873
@Test
6974
public void testPostError() {
70-
WebTarget r = target("test");
75+
final WebTarget target = target("test");
7176

7277
for (int i = 0; i < 100; i++) {
73-
try {
74-
r.request().post(Entity.text("POST"));
75-
} catch (ClientErrorException ex) {
76-
}
78+
final Response resp = target.request().post(Entity.text("POST"));
79+
assertEquals(500, resp.getStatus());
7780
}
7881
}
7982

@@ -92,13 +95,18 @@ public void testPostErrorWithEntity() {
9295
}
9396

9497
@Test
95-
public void testPostErrorAsync() {
96-
WebTarget r = target("test");
98+
public void testPostErrorAsync() throws ExecutionException, InterruptedException {
99+
final WebTarget target = target("test");
100+
101+
final List<Future<Response>> responses = new ArrayList<>(100);
97102

98103
for (int i = 0; i < 100; i++) {
99-
try {
100-
r.request().async().post(Entity.text("POST"));
101-
} catch (ClientErrorException ex) {
104+
responses.add(target.request().async().post(Entity.text("POST")));
105+
}
106+
for (int i = responses.size() - 1; i >= 0;) {
107+
if (responses.get(i).isDone()) {
108+
assertEquals(500, responses.remove(i).get().getStatus());
109+
i--;
102110
}
103111
}
104112
}

0 commit comments

Comments
 (0)