Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/typo_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@ jobs:
# 2. Run the typo check with the following command:
# typos
- name: Check typos
uses: crate-ci/typos@master
uses: crate-ci/typos@v1.38.1
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.servicecomb.samples;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.servicecomb.core.CoreConst;
Expand All @@ -33,17 +35,21 @@ public class WebsocketController {
@PostMapping("/websocket")
@Transport(name = CoreConst.WEBSOCKET)
public void websocket(ServerWebSocket serverWebsocket) {
// Client may have not registered message handler, and messages sent may get lost.
// So we sleep for a while to send message.
AtomicInteger receiveCount = new AtomicInteger(0);
CountDownLatch startSend = new CountDownLatch(1);
serverWebsocket.textMessageHandler(s -> {
if ("start".equals(s)) {
startSend.countDown();
serverWebsocket.writeTextMessage("started");
return;
}
receiveCount.getAndIncrement();
});
serverWebsocket.closeHandler((v) -> System.out.println("closed"));

new Thread(() -> {
try {
Thread.sleep(1000);
startSend.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down
2 changes: 1 addition & 1 deletion demo/demo-consul/test-client/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@
<configuration>
<images>
<image>
<name>hashicorp/consul</name>
<name>hashicorp/consul:1.21</name>
<alias>consul</alias>
<run>
<namingStrategy>alias</namingStrategy>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ public class WebsocketIT implements CategorizedTestCase {
public void testRestTransport() throws Exception {
StringBuffer sb = new StringBuffer();
AtomicBoolean closed = new AtomicBoolean(false);
CountDownLatch latchStarted = new CountDownLatch(1);
CountDownLatch latch = new CountDownLatch(1);

WebSocket webSocket = websocketClient.websocket();
webSocket.textMessageHandler(s -> {
if ("started".equals(s)) {
latchStarted.countDown();
return;
}
sb.append(s);
sb.append(" ");
webSocket.writeTextMessage(s);
Expand All @@ -50,6 +55,17 @@ public void testRestTransport() throws Exception {
closed.set(true);
latch.countDown();
});

webSocket.writeTextMessage("start");
int i = 0;
for (; i < 10; i++) {
if (!latchStarted.await(3, TimeUnit.SECONDS)) {
webSocket.writeTextMessage("start");
continue;
}
break;
}
TestMgr.check(i < 10, true);
latch.await(30, TimeUnit.SECONDS);
TestMgr.check(sb.toString(), "hello hello 0 hello 1 hello 2 hello 3 hello 4 total 6 ");
TestMgr.check(closed.get(), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

package org.apache.servicecomb.samples;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.servicecomb.core.CoreConst;
Expand All @@ -33,17 +35,21 @@ public class WebsocketController {
@PostMapping("/websocket")
@Transport(name = CoreConst.WEBSOCKET)
public void websocket(ServerWebSocket serverWebsocket) {
// Client may have not registered message handler, and messages sent may get lost.
// So we sleep for a while to send message.
AtomicInteger receiveCount = new AtomicInteger(0);
CountDownLatch startSend = new CountDownLatch(1);
serverWebsocket.textMessageHandler(s -> {
if ("start".equals(s)) {
startSend.countDown();
serverWebsocket.writeTextMessage("started");
return;
}
receiveCount.getAndIncrement();
});
serverWebsocket.closeHandler((v) -> System.out.println("closed"));

new Thread(() -> {
try {
Thread.sleep(1000);
startSend.await(30, TimeUnit.SECONDS);
} catch (InterruptedException e) {
e.printStackTrace();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,15 @@ public class WebsocketIT implements CategorizedTestCase {
public void testRestTransport() throws Exception {
StringBuffer sb = new StringBuffer();
AtomicBoolean closed = new AtomicBoolean(false);
CountDownLatch latchStarted = new CountDownLatch(1);
CountDownLatch latch = new CountDownLatch(1);

WebSocket webSocket = websocketClient.websocket();
webSocket.textMessageHandler(s -> {
if ("started".equals(s)) {
latchStarted.countDown();
return;
}
sb.append(s);
sb.append(" ");
webSocket.writeTextMessage(s);
Expand All @@ -50,6 +55,17 @@ public void testRestTransport() throws Exception {
closed.set(true);
latch.countDown();
});

webSocket.writeTextMessage("start");
int i = 0;
for (; i < 10; i++) {
if (!latchStarted.await(3, TimeUnit.SECONDS)) {
webSocket.writeTextMessage("start");
continue;
}
break;
}
TestMgr.check(i < 10, true);
latch.await(30, TimeUnit.SECONDS);
TestMgr.check(sb.toString(), "hello hello 0 hello 1 hello 2 hello 3 hello 4 total 6 ");
TestMgr.check(closed.get(), true);
Expand Down
Loading