We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
클라이언트가 SSE 연결을 끊었을 때를 테스트해야 한다. 아래 코드에 걸려서 에러 핸들링이 제대로 되는지 검증한다.
@Slf4j public class SseErrorHandler { public static void handle(IOException e) { if (isClientAbortException(e)) { log.info("클라이언트가 연결을 종료했습니다."); } else { log.error("SSE 연결 중 오류 발생: {}", e.getMessage()); throw new RuntimeException(e); } } private static boolean isClientAbortException(Throwable throwable) { while (throwable != null) { if (throwable instanceof org.apache.catalina.connector.ClientAbortException) { return true; } throwable = throwable.getCause(); } return false; } }
테스트용 웹 컨테이너에 요청을 보내고 커넥션을 끊었을 때, 클라이언트가 연결을 종료했습니다.라는 로그가 찍혀야 한다. 다음은 시도했지만 실패한 방법이다.
클라이언트가 연결을 종료했습니다.
@DisplayName("SSE를 연결하고 클라이언트가 연결을 끊으면, 에러가 찍히지 않는다.") @Test void sseConnectionCloseTest() throws IOException { // when Response response = RestAssured.given() .accept("text/event-stream") .when() .get("/api/connect") .then() .statusCode(200) .extract() .response(); response.body().asInputStream().close(); // then // no exception }
@DisplayName("SSE를 연결하고 클라이언트가 연결을 끊으면, 에러가 찍히지 않는다.") @Test void sseConnectionCloseTest() throws IOException, InterruptedException { // when String sseUrl = "http://localhost:" + RestAssured.port + "/api/connect"; // Open connection HttpURLConnection connection = (HttpURLConnection) new URL(sseUrl).openConnection(); connection.setRequestMethod("GET"); connection.setRequestProperty("Accept", "text/event-stream"); connection.setDoInput(true); // Assert the connection was successful int responseCode = connection.getResponseCode(); assertThat(responseCode).isEqualTo(200); System.out.println("SSE 연결 성공: " + responseCode); // Read a portion of the stream BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream())); String line = reader.readLine(); // SSE 메시지의 첫 번째 줄 System.out.println("수신된 메시지: " + line); // Assert that the connection is active and receiving data assertThat(line).contains("success"); // Disconnect the connection connection.disconnect(); System.out.println("SSE 연결 종료"); Thread.sleep(2000); }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
작업할 내용
클라이언트가 SSE 연결을 끊었을 때를 테스트해야 한다. 아래 코드에 걸려서 에러 핸들링이 제대로 되는지 검증한다.
시도한 방법
테스트용 웹 컨테이너에 요청을 보내고 커넥션을 끊었을 때,
클라이언트가 연결을 종료했습니다.
라는 로그가 찍혀야 한다. 다음은 시도했지만 실패한 방법이다.RestAssured
Java Connection 사용
The text was updated successfully, but these errors were encountered: