|
| 1 | +/******************************************************************************* |
| 2 | + * Copyright (c) 2025 IBM Corporation and others. |
| 3 | + * All rights reserved. This program and the accompanying materials |
| 4 | + * are made available under the terms of the Eclipse Public License 2.0 |
| 5 | + * which accompanies this distribution, and is available at |
| 6 | + * http://www.eclipse.org/legal/epl-2.0/ |
| 7 | + * |
| 8 | + * SPDX-License-Identifier: EPL-2.0 |
| 9 | + *******************************************************************************/ |
| 10 | +package io.openliberty.transport.http_fat; |
| 11 | + |
| 12 | +import static org.junit.Assert.assertNotNull; |
| 13 | + |
| 14 | +import java.util.logging.Logger; |
| 15 | + |
| 16 | +import org.junit.After; |
| 17 | +import org.junit.AfterClass; |
| 18 | +import org.junit.Before; |
| 19 | +import org.junit.BeforeClass; |
| 20 | +import org.junit.Test; |
| 21 | +import org.junit.runner.RunWith; |
| 22 | + |
| 23 | +import com.ibm.websphere.simplicity.config.HttpEndpoint; |
| 24 | +import com.ibm.websphere.simplicity.config.ServerConfiguration; |
| 25 | + |
| 26 | +import componenttest.annotation.Server; |
| 27 | +import componenttest.custom.junit.runner.FATRunner; |
| 28 | +import componenttest.custom.junit.runner.Mode; |
| 29 | +import componenttest.custom.junit.runner.Mode.TestMode; |
| 30 | +import componenttest.topology.impl.LibertyServer; |
| 31 | + |
| 32 | +/** |
| 33 | + * Test to ensure that the tcpOptions inactivityTimeout works. |
| 34 | + */ |
| 35 | +@RunWith(FATRunner.class) |
| 36 | +@Mode(TestMode.FULL) |
| 37 | +public class InactivityTimeoutTests { |
| 38 | + |
| 39 | + static final Logger LOG = Logger.getLogger(InactivityTimeoutTests.class.getName()); |
| 40 | + private static final String APP_NAME = "InactivityTimeout"; |
| 41 | + |
| 42 | + @Server("InactivityTimeout") |
| 43 | + public static LibertyServer server; |
| 44 | + |
| 45 | + @BeforeClass |
| 46 | + public static void setup() throws Exception { |
| 47 | + // Start the server and use the class name so we can find logs easily. |
| 48 | + server.startServer(InactivityTimeoutTests.class.getSimpleName() + ".log"); |
| 49 | + } |
| 50 | + |
| 51 | + /** |
| 52 | + * Save the server configuration before each test, this should be the default server |
| 53 | + * configuration. |
| 54 | + * |
| 55 | + * @throws Exception |
| 56 | + */ |
| 57 | + @Before |
| 58 | + public void beforeTest() throws Exception { |
| 59 | + server.saveServerConfiguration(); |
| 60 | + |
| 61 | + ServerConfiguration configuration = server.getServerConfiguration(); |
| 62 | + LOG.info("Server configuration that was saved: " + configuration); |
| 63 | + } |
| 64 | + |
| 65 | + /** |
| 66 | + * Restore the server configuration to the default state after each test. |
| 67 | + * |
| 68 | + * @throws Exception |
| 69 | + */ |
| 70 | + @After |
| 71 | + public void afterTest() throws Exception { |
| 72 | + // Restore the server to the default state. |
| 73 | + server.setMarkToEndOfLog(); |
| 74 | + server.restoreServerConfiguration(); |
| 75 | + server.waitForConfigUpdateInLogUsingMark(null); |
| 76 | + } |
| 77 | + |
| 78 | + @AfterClass |
| 79 | + public static void tearDown() throws Exception { |
| 80 | + // Stop the server |
| 81 | + if (server != null && server.isStarted()) { |
| 82 | + server.stopServer(); |
| 83 | + } |
| 84 | + |
| 85 | + } |
| 86 | + |
| 87 | + /** |
| 88 | + * The test will check the default value of inactivityTimeout by searching the trace file. |
| 89 | + * |
| 90 | + * The default value is 60 seconds will be logged as 60000 miliseconds. |
| 91 | + */ |
| 92 | + @Test |
| 93 | + public void testInactivityTimeout_default() throws Exception { |
| 94 | + |
| 95 | + // Validate that inActivityTimeout default is 60s. |
| 96 | + assertNotNull("The default value of inactivityTimeout was not: 60000!", server.waitForStringInTrace("inactivityTimeout: 60000")); |
| 97 | + |
| 98 | + } |
| 99 | + |
| 100 | + /** |
| 101 | + * The test will set inactivityTimeout to a value of 120s and validate in the trace file that |
| 102 | + * the correct value is being used. |
| 103 | + * |
| 104 | + * The below configuration will be used to set inactivityTimeout to 120s: |
| 105 | + * <tcpOptions inactivityTimeout="120s"/> |
| 106 | + * |
| 107 | + * @throws Exception |
| 108 | + */ |
| 109 | + @Test |
| 110 | + public void testInactivityTimeout_nonDefault() throws Exception { |
| 111 | + ServerConfiguration configuration = server.getServerConfiguration(); |
| 112 | + LOG.info("Server configuration that the test started with: " + configuration); |
| 113 | + |
| 114 | + HttpEndpoint httpEndpoint = configuration.getHttpEndpoints().getById("defaultHttpEndpoint"); |
| 115 | + httpEndpoint.getTcpOptions().setInactivityTimeout("120s"); |
| 116 | + |
| 117 | + server.setMarkToEndOfLog(); |
| 118 | + server.setTraceMarkToEndOfDefaultTrace(); |
| 119 | + server.updateServerConfiguration(configuration); |
| 120 | + server.waitForConfigUpdateInLogUsingMark(null); |
| 121 | + |
| 122 | + // Validate that inactivityTimeout is set to 120000 (120s). |
| 123 | + assertNotNull("The configured value of inactivityTimeout was not 120000!", server.waitForStringInTraceUsingMark("inactivityTimeout: 120000")); |
| 124 | + |
| 125 | + } |
| 126 | + |
| 127 | +} |
0 commit comments