|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright 2002-2025 the original author or authors. | 
|  | 3 | + * | 
|  | 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 5 | + * you may not use this file except in compliance with the License. | 
|  | 6 | + * You may obtain a copy of the License at | 
|  | 7 | + * | 
|  | 8 | + *      https://www.apache.org/licenses/LICENSE-2.0 | 
|  | 9 | + * | 
|  | 10 | + * Unless required by applicable law or agreed to in writing, software | 
|  | 11 | + * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 13 | + * See the License for the specific language governing permissions and | 
|  | 14 | + * limitations under the License. | 
|  | 15 | + */ | 
|  | 16 | + | 
|  | 17 | +package org.springframework.web.util; | 
|  | 18 | + | 
|  | 19 | +import java.io.EOFException; | 
|  | 20 | +import java.io.IOException; | 
|  | 21 | +import java.util.List; | 
|  | 22 | + | 
|  | 23 | +import org.apache.catalina.connector.ClientAbortException; | 
|  | 24 | +import org.eclipse.jetty.io.EofException; | 
|  | 25 | +import org.junit.jupiter.api.Test; | 
|  | 26 | +import org.junit.jupiter.params.ParameterizedTest; | 
|  | 27 | +import org.junit.jupiter.params.provider.MethodSource; | 
|  | 28 | +import org.junit.jupiter.params.provider.ValueSource; | 
|  | 29 | +import reactor.netty.channel.AbortedException; | 
|  | 30 | + | 
|  | 31 | +import org.springframework.web.context.request.async.AsyncRequestNotUsableException; | 
|  | 32 | + | 
|  | 33 | +import static org.assertj.core.api.Assertions.assertThat; | 
|  | 34 | + | 
|  | 35 | +/** | 
|  | 36 | + * Unit tests for {@link DisconnectedClientHelper}. | 
|  | 37 | + * @author Rossen Stoyanchev | 
|  | 38 | + */ | 
|  | 39 | +public class DisconnectedClientHelperTests { | 
|  | 40 | + | 
|  | 41 | +	@ParameterizedTest | 
|  | 42 | +	@ValueSource(strings = {"broKen pipe", "connection reset By peer"}) | 
|  | 43 | +	void exceptionPhrases(String phrase) { | 
|  | 44 | +		Exception ex = new IOException(phrase); | 
|  | 45 | +		assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isTrue(); | 
|  | 46 | + | 
|  | 47 | +		ex = new IOException(ex); | 
|  | 48 | +		assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isTrue(); | 
|  | 49 | +	} | 
|  | 50 | + | 
|  | 51 | +	@Test | 
|  | 52 | +	void connectionResetExcluded() { | 
|  | 53 | +		Exception ex = new IOException("connection reset"); | 
|  | 54 | +		assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isFalse(); | 
|  | 55 | +	} | 
|  | 56 | + | 
|  | 57 | +	@ParameterizedTest | 
|  | 58 | +	@MethodSource("disconnectedExceptions") | 
|  | 59 | +	void name(Exception ex) { | 
|  | 60 | +		assertThat(DisconnectedClientHelper.isClientDisconnectedException(ex)).isTrue(); | 
|  | 61 | +	} | 
|  | 62 | + | 
|  | 63 | +	static List<Exception> disconnectedExceptions() { | 
|  | 64 | +		return List.of( | 
|  | 65 | +				new AbortedException(""), new ClientAbortException(""), | 
|  | 66 | +				new EOFException(), new EofException(), new AsyncRequestNotUsableException("")); | 
|  | 67 | +	} | 
|  | 68 | + | 
|  | 69 | +} | 
0 commit comments