-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: websocket timeout and close server on error (#2914)
Signed-off-by: Pablo Hernán Carle <[email protected]> Co-authored-by: Pavel Jareš <[email protected]> Signed-off-by: Pablo Carle <[email protected]> --------- Signed-off-by: Pablo Hernán Carle <[email protected]> Signed-off-by: Pablo Carle <[email protected]> Co-authored-by: Pablo Hernán Carle <[email protected]> Co-authored-by: Pavel Jareš <[email protected]> Co-authored-by: Petr Weinfurt <[email protected]>
- Loading branch information
1 parent
3809622
commit 020da87
Showing
9 changed files
with
179 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
gateway-service/src/test/java/org/zowe/apiml/gateway/ws/WebSocketProxyClientHandlerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.gateway.ws; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
import java.util.concurrent.TimeoutException; | ||
|
||
import org.eclipse.jetty.websocket.api.CloseException; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import org.springframework.web.socket.CloseStatus; | ||
import org.springframework.web.socket.WebSocketSession; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class WebSocketProxyClientHandlerTest { | ||
|
||
@Mock | ||
private WebSocketSession serverSession; | ||
|
||
private WebSocketProxyClientHandler webSocketProxyClientHandler; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
webSocketProxyClientHandler = new WebSocketProxyClientHandler(serverSession); | ||
} | ||
|
||
@Nested | ||
class GivenHandler { | ||
|
||
@Nested | ||
class AndConnectionIsClosed { | ||
|
||
@Test | ||
void thenCloseServer() throws Exception { | ||
webSocketProxyClientHandler.afterConnectionClosed(mock(WebSocketSession.class), CloseStatus.NORMAL); | ||
verify(serverSession, times(1)).close(CloseStatus.NORMAL); | ||
} | ||
|
||
} | ||
|
||
@Nested | ||
class AndConnectionTransportError { | ||
|
||
@Test | ||
void andTimeout_thenCloseNormal() throws Exception { | ||
webSocketProxyClientHandler.handleTransportError(mock(WebSocketSession.class), new CloseException(0, new TimeoutException("null"))); | ||
verify(serverSession, times(1)).close(CloseStatus.NORMAL); | ||
} | ||
|
||
@Test | ||
void andCloseException_thenForwardError() throws Exception { | ||
webSocketProxyClientHandler.handleTransportError(mock(WebSocketSession.class), new CloseException(CloseStatus.PROTOCOL_ERROR.getCode(), new Exception("message"))); | ||
verify(serverSession, times(1)).close(new CloseStatus(1002, "java.lang.Exception: message")); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters