Skip to content

Commit

Permalink
WebSocket test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
finefuture committed Jul 8, 2024
1 parent 4d033dd commit 5df1960
Show file tree
Hide file tree
Showing 11 changed files with 820 additions and 0 deletions.
57 changes: 57 additions & 0 deletions 2-advanced/dubbo-samples-triple-websocket/case-configuration.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

services:
nacos:
image: nacos/nacos-server:${nacos-server.version:2.0.0}
environment:
- PREFER_HOST_MODE=hostname
- MODE=standalone
- NACOS_AUTH_ENABLE=true
- JVM_XMS=512m
- JVM_XMX=512m
- JVM_XMN=256m

tri-websocket-server:
type: app
basedir: .
mainClass: org.apache.dubbo.tri.websocket.demo.WebSocketDemoApplication
systemProps:
- nacos.address=nacos
- nacos.port=8848
waitPortsBeforeRun:
- nacos:8848
checkPorts:
- 50052
checkLog: "Current Spring Boot Application is await..."
depends_on:
- nacos

test:
type: test
basedir: .
tests:
- "**/*Test.class"
systemProps:
- nacos.address=nacos
- nacos.port=8848
- dubbo.address=tri-websocket-server
waitPortsBeforeRun:
- nacos:8848
- tri-websocket-server:50052
depends_on:
- nacos
- tri-websocket-server
25 changes: 25 additions & 0 deletions 2-advanced/dubbo-samples-triple-websocket/case-versions.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#


# Supported component versions of the test case

# Spring app
dubbo.version=3.3.*
spring.version=4.*, 5.*
java.version= [>= 8]
126 changes: 126 additions & 0 deletions 2-advanced/dubbo-samples-triple-websocket/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache</groupId>
<artifactId>apache</artifactId>
<version>23</version>
<relativePath/>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>dubbo-samples-triple-websocket</artifactId>

<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>

<dubbo.version>3.3.0-beta.5-SNAPSHOT</dubbo.version>
<spring-boot.version>2.7.18</spring-boot.version>
<java-websocket.version>1.5.6</java-websocket.version>
<servlet.version>4.0.1</servlet.version>
<tomcat.version>9.0.83</tomcat.version>
<junit.version>4.13.2</junit.version>

<maven-compiler-plugin.version>3.7.0</maven-compiler-plugin.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-dependencies-bom</artifactId>
<version>${dubbo.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-dependencies</artifactId>
<version>${spring-boot.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>
<dependency>
<groupId>org.apache.dubbo</groupId>
<artifactId>dubbo-nacos-spring-boot-starter</artifactId>
<version>${dubbo.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring-boot.version}</version>
</dependency>

<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>${servlet.version}</version>
</dependency>

<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-core</artifactId>
<version>${tomcat.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>${spring-boot.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.java-websocket</groupId>
<artifactId>Java-WebSocket</artifactId>
<version>${java-websocket.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>${spring-boot.version}</version>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.tri.websocket.demo;

import org.apache.dubbo.common.stream.StreamObserver;

public interface DemoService {

String sayHello(String name);

String sayHelloError(String name);

void greetServerStream(String request, StreamObserver<String> response);

void greetServerStreamError(String request, StreamObserver<String> response);

void greetServerStreamDirectError(String request, StreamObserver<String> response);

StreamObserver<String> greetBiStream(StreamObserver<String> response);

StreamObserver<String> greetBiStreamError(StreamObserver<String> response);

StreamObserver<String> greetBiStreamDirectError(StreamObserver<String> response);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.dubbo.tri.websocket.demo;

import org.apache.dubbo.common.stream.StreamObserver;
import org.apache.dubbo.config.annotation.DubboService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@DubboService
public class DemoServiceImpl implements DemoService {

private static final Logger LOGGER = LoggerFactory.getLogger(DemoServiceImpl.class);

@Override
public String sayHello(String name) {
return "Hello, " + name;
}

@Override
public String sayHelloError(String name) {
throw new RuntimeException("test error: " + name);
}

@Override
public void greetServerStream(String request, StreamObserver<String> response) {
for (int i = 0; i < 10; i++) {
response.onNext("Hello, " + request + i);
}
response.onCompleted();
}

@Override
public void greetServerStreamError(String request, StreamObserver<String> response) {
response.onError(new RuntimeException("test error: " + request));
}

@Override
public void greetServerStreamDirectError(String request, StreamObserver<String> response) {
throw new RuntimeException("test direct error: " + request);
}

@Override
public StreamObserver<String> greetBiStream(StreamObserver<String> response) {
return new StreamObserver<String>() {
@Override
public void onNext(String data) {
LOGGER.info(data);
response.onNext("Hello, " + data);
}

@Override
public void onError(Throwable throwable) {
LOGGER.error("GreetBiStream on error", throwable);
}

@Override
public void onCompleted() {
LOGGER.info("onCompleted");
response.onCompleted();
}
};
}

@Override
public StreamObserver<String> greetBiStreamError(StreamObserver<String> response) {
return new StreamObserver<String>() {
@Override
public void onNext(String data) {
response.onError(new RuntimeException("test error: " + data));
}

@Override
public void onError(Throwable throwable) {
LOGGER.error("GreetBiStream on error", throwable);
}

@Override
public void onCompleted() {
LOGGER.info("onCompleted");
response.onCompleted();
}
};
}

@Override
public StreamObserver<String> greetBiStreamDirectError(StreamObserver<String> response) {
return new StreamObserver<String>() {
@Override
public void onNext(String data) {
throw new RuntimeException("test direct error: " + data);
}

@Override
public void onError(Throwable throwable) {
LOGGER.error("GreetBiStream on error", throwable);
}

@Override
public void onCompleted() {
LOGGER.info("onCompleted");
response.onCompleted();
}
};
}

}
Loading

0 comments on commit 5df1960

Please sign in to comment.