|
| 1 | +/* |
| 2 | + * JBoss, Home of Professional Open Source. |
| 3 | + * Copyright 2025 Red Hat, Inc., and individual contributors |
| 4 | + * as indicated by the @author tags. |
| 5 | + * |
| 6 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 7 | + * you may not use this file except in compliance with the License. |
| 8 | + * You may obtain a copy of the License at |
| 9 | + * |
| 10 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | + * |
| 12 | + * Unless required by applicable law or agreed to in writing, software |
| 13 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 14 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 15 | + * See the License for the specific language governing permissions and |
| 16 | + * limitations under the License. |
| 17 | + */ |
| 18 | +package io.undertow.servlet.test.listener.request.async.onTimeout.property; |
| 19 | + |
| 20 | +import java.io.IOException; |
| 21 | + |
| 22 | +import org.apache.http.HttpResponse; |
| 23 | +import org.apache.http.client.methods.HttpGet; |
| 24 | +import org.junit.Assert; |
| 25 | +import org.junit.BeforeClass; |
| 26 | +import org.junit.Test; |
| 27 | +import org.junit.runner.RunWith; |
| 28 | + |
| 29 | +import io.undertow.server.handlers.PathHandler; |
| 30 | +import io.undertow.servlet.api.DeploymentInfo; |
| 31 | +import io.undertow.servlet.api.DeploymentManager; |
| 32 | +import io.undertow.servlet.api.ListenerInfo; |
| 33 | +import io.undertow.servlet.api.ServletContainer; |
| 34 | +import io.undertow.servlet.api.ServletInfo; |
| 35 | +import io.undertow.servlet.test.listener.request.async.onTimeout.SimpleRequestListener; |
| 36 | +import io.undertow.servlet.test.util.TestClassIntrospector; |
| 37 | +import io.undertow.testutils.DefaultServer; |
| 38 | +import io.undertow.testutils.TestHttpClient; |
| 39 | +import io.undertow.util.StatusCodes; |
| 40 | +import jakarta.servlet.ServletException; |
| 41 | + |
| 42 | +@RunWith(DefaultServer.class) |
| 43 | +public class DefaultAsyncTimeoutTestCase { |
| 44 | + @BeforeClass |
| 45 | + public static void setup() throws ServletException { |
| 46 | + |
| 47 | + final PathHandler root = new PathHandler(); |
| 48 | + final ServletContainer container = ServletContainer.Factory.newInstance(); |
| 49 | + |
| 50 | + ServletInfo a = new ServletInfo("asyncServlet", AsyncServlet.class) |
| 51 | + .setAsyncSupported(true) |
| 52 | + .addMapping("/async"); |
| 53 | + |
| 54 | + DeploymentInfo builder = new DeploymentInfo() |
| 55 | + .setClassLoader(DefaultAsyncTimeoutTestCase.class.getClassLoader()) |
| 56 | + .setContextPath("/servletContext") |
| 57 | + .setClassIntrospecter(TestClassIntrospector.INSTANCE) |
| 58 | + .setDeploymentName("servletContext.war") |
| 59 | + .addServlets(a) |
| 60 | + .addListener(new ListenerInfo(SimpleRequestListener.class)); |
| 61 | + |
| 62 | + DeploymentManager manager = container.addDeployment(builder); |
| 63 | + manager.deploy(); |
| 64 | + root.addPrefixPath(builder.getContextPath(), manager.start()); |
| 65 | + |
| 66 | + DefaultServer.setRootHandler(root); |
| 67 | + } |
| 68 | + |
| 69 | + @Test |
| 70 | + public void testDefaultTimeout() throws IOException { |
| 71 | + TestHttpClient client = new TestHttpClient(); |
| 72 | + try { |
| 73 | + HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/async?"+AsyncServlet.TEST_TIMEOUT+"=30000"); |
| 74 | + HttpResponse response = client.execute(get); |
| 75 | + Assert.assertEquals(StatusCodes.OK, response.getStatusLine().getStatusCode()); |
| 76 | + Assert.assertFalse(SimpleRequestListener.hasNestedInvocationOccured()); |
| 77 | + } finally { |
| 78 | + client.getConnectionManager().shutdown(); |
| 79 | + } |
| 80 | + } |
| 81 | + |
| 82 | + @Test |
| 83 | + public void testNewDefaultTimeout() throws IOException { |
| 84 | + TestHttpClient client = new TestHttpClient(); |
| 85 | + try { |
| 86 | + HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/async?"+AsyncServlet.TEST_TIMEOUT+"=20000"); |
| 87 | + HttpResponse response = client.execute(get); |
| 88 | + Assert.assertEquals(StatusCodes.OK, response.getStatusLine().getStatusCode()); |
| 89 | + Assert.assertFalse(SimpleRequestListener.hasNestedInvocationOccured()); |
| 90 | + } finally { |
| 91 | + client.getConnectionManager().shutdown(); |
| 92 | + } |
| 93 | + } |
| 94 | +} |
0 commit comments