Skip to content

Commit

Permalink
Fix the functionality breaking
Browse files Browse the repository at this point in the history
  • Loading branch information
Kalaiyarasi committed Nov 14, 2019
1 parent ae92021 commit 5fc5852
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public void onSuccess(WebSocketConnection webSocketConnection, HttpCarbonRespons
}
setWebSocketClient(webSocketClient, carbonResponse, webSocketConnection, retryConfig);
WebSocketConnectionInfo connectionInfo = WebSocketUtil.getWebSocketOpenConnectionInfo(webSocketConnection,
webSocketConnector,
webSocketClient, wsService);
webSocketConnector, webSocketClient, wsService);
clientConnectorListener.setConnectionInfo(connectionInfo);
// Read the next frame when readyOnConnect is true or isReady is true
WebSocketUtil.readNextFrame(readyOnConnect, webSocketClient, webSocketConnection);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.ballerinalang.jvm.values.ObjectValue;
import org.ballerinalang.net.http.websocket.WebSocketConstants;
import org.ballerinalang.net.http.websocket.WebSocketService;
import org.ballerinalang.net.http.websocket.client.FailoverContext;
import org.ballerinalang.net.http.websocket.server.WebSocketConnectionInfo;
import org.ballerinalang.net.http.websocket.server.WebSocketServerService;
import org.slf4j.Logger;
Expand Down Expand Up @@ -209,7 +210,14 @@ static String getServicePathOrClientUrl(WebSocketConnectionInfo connectionInfo)
if (service instanceof WebSocketServerService) {
return ((WebSocketServerService) service).getBasePath();
} else {
return connectionInfo.getWebSocketEndpoint().getStringValue("url");
if (connectionInfo.getWebSocketEndpoint().getType().getName().
equalsIgnoreCase(WebSocketConstants.FAILOVER_WEBSOCKET_CLIENT)) {
FailoverContext failoverConfig = (FailoverContext) connectionInfo.getWebSocketEndpoint().
getNativeData(WebSocketConstants.FAILOVER_CONFIG);
return failoverConfig.getTargetUrls().get(failoverConfig.getCurrentIndex());
} else {
return connectionInfo.getWebSocketEndpoint().getStringValue("url");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class FailoverClientTest extends WebSocketTestCommons {
private WebSocketRemoteServer remoteServer15200;
private String url = "ws://localhost:21033";
private int port = 15300;
private String textSent = "hi all";

@Test(description = "Tests starting the second server in the target URLs, sending and receiving text frames " +
"using the failover websocket client")
Expand All @@ -50,7 +51,6 @@ public void testTextFrameWithSecondServer() throws URISyntaxException, Interrupt
remoteServer15200.run();
WebSocketTestClient client = new WebSocketTestClient(url);
client.handshake();
String textSent = "hi all";
client.sendText(textSent);
countDownLatch.await(TIMEOUT_IN_SECS, TimeUnit.SECONDS);
Assert.assertEquals(client.getTextReceived(), textSent);
Expand Down Expand Up @@ -102,14 +102,12 @@ public void testFailoverWithBothServer() throws URISyntaxException, InterruptedE
ByteBuffer bufferSent = ByteBuffer.wrap(new byte[]{1, 2, 3, 4, 6});
WebSocketTestClient client = new WebSocketTestClient(url);
client.handshake();
String textSent = "hi all";

client.sendText(textSent);
countDownLatchFor15300.await(TIMEOUT_IN_SECS, TimeUnit.SECONDS);
Assert.assertEquals(client.getTextReceived(), textSent);
remoteServer15300.stop();
CountDownLatch countDownLatchFor15200 = new CountDownLatch(1);
int time = 2;
countDownLatchFor15200.await(time, TimeUnit.SECONDS);
String text = "hi";
client.sendText(text);
countDownLatchFor15200.await(TIMEOUT_IN_SECS, TimeUnit.SECONDS);
Expand All @@ -120,4 +118,31 @@ public void testFailoverWithBothServer() throws URISyntaxException, InterruptedE
client.shutDown();
remoteServer15200.stop();
}

@Test(description = "Test the Failover websocket client (starting the second server in the target URLs, " +
"first sending and receiving text frames Afterthat stop the second server and start the in the target " +
"URLs, sending and receiving binary frames) ")
public void testFailoverWithBothServerFirstStartSecondServer() throws URISyntaxException, InterruptedException,
BallerinaTestException {
CountDownLatch countDownLatch = new CountDownLatch(1);
remoteServer15200 = new WebSocketRemoteServer(15200);
remoteServer15300 = new WebSocketRemoteServer(port);
remoteServer15200.run();
ByteBuffer bufferSent = ByteBuffer.wrap(new byte[]{1, 2, 3, 4, 6});
WebSocketTestClient client = new WebSocketTestClient(url);
client.handshake();
client.sendText(textSent);
countDownLatch.await(TIMEOUT_IN_SECS, TimeUnit.SECONDS);
Assert.assertEquals(client.getTextReceived(), textSent);
remoteServer15300.run();
countDownLatch.await(TIMEOUT_IN_SECS, TimeUnit.SECONDS);
remoteServer15200.stop();
CountDownLatch countDownLatchFor15300 = new CountDownLatch(1);
String text = "hi";
client.sendText(text);
countDownLatchFor15300.await(TIMEOUT_IN_SECS, TimeUnit.SECONDS);
Assert.assertEquals(client.getTextReceived(), text);
client.shutDown();
remoteServer15300.stop();
}
}

0 comments on commit 5fc5852

Please sign in to comment.