-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
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
add deploy action #27
Changes from 16 commits
3be8762
db1ebda
ee0efac
079e895
51d9e28
e7106f3
c208a2b
a5e7d21
9ccdfd1
6c90182
0be8ba1
4b6c00f
1579cb4
01b0ec0
7d9d4f4
d344346
8e63ce1
bee3dc9
4fb808d
51a1942
b65aba3
4c878c7
1a50e50
c17da85
b17eed1
3e9b0c2
443e3f1
ec73bcd
a1f9a38
ab75e39
61c6378
2b694bc
3512890
e95a170
2429b9e
10d1501
d5e29d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
name: Deploy and Test | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
types: [ opened, synchronize, reopened ] | ||
jobs: | ||
test: | ||
name: Deploy and Test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up JDK 17 | ||
uses: actions/setup-java@v3 | ||
with: | ||
java-version: 17 | ||
distribution: 'temurin' | ||
|
||
- name: Run Internal Test | ||
run: mvn test -pl '!rill-flow-test' && echo "Maven Run Internal Test succeeded"|| { echo "Run Internal Test failed."; exit 1; } | ||
|
||
- name: Install Docker Compose | ||
run: | | ||
sudo curl -L "https://github.com/docker/compose/releases/latest/download/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose | ||
sudo chmod +x /usr/local/bin/docker-compose | ||
|
||
- name: Deploy with Docker Compose | ||
run: | | ||
cd docker | ||
docker-compose up -d | ||
|
||
- name: Run API Test | ||
run: mvn test -pl 'rill-flow-test' && echo "Run API Test succeeded"|| { echo "Run API Test failed."; exit 1; } | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
version: '3' | ||
services: | ||
rill-flow: | ||
image: weibocom/rill-flow | ||
depends_on: | ||
- cache | ||
- jaeger | ||
ports: | ||
- "8080:8080" | ||
environment: | ||
- RILL_FLOW_DESCRIPTOR_REDIS_HOST=cache | ||
- RILL_FLOW_DEFAULT_REDIS_HOST=cache | ||
- RILL_FLOW_TRACE_ENDPOINT=http://jaeger:4317 | ||
- RILL_FLOW_CALLBACK_URL=http://rill-flow:8080/flow/finish.json | ||
- RILL_FLOW_TRACE_QUERY_HOST=http://jaeger:16686 | ||
cache: | ||
image: redis:6.2-alpine | ||
restart: always | ||
command: redis-server --save 20 1 --loglevel warning | ||
jaeger: | ||
image: jaegertracing/all-in-one:1.39 | ||
restart: always | ||
environment: | ||
- COLLECTOR_OTLP_ENABLED=true | ||
ui: | ||
image: weibocom/rill-flow-ui | ||
ports: | ||
- "8088:80" | ||
depends_on: | ||
- rill-flow | ||
- jaeger | ||
environment: | ||
- BACKEND_SERVER=http://rill-flow:8080 | ||
sample-executor: | ||
image: weibocom/rill-flow-sample:sample-executor |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<parent> | ||
<groupId>com.weibo</groupId> | ||
<artifactId>rill-flow</artifactId> | ||
<version>0.1.6-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>rill-flow-test</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.5.14</version> | ||
</dependency> | ||
</dependencies> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,170 @@ | ||
package com.weibo.rill.flow.sample | ||
|
||
import org.apache.http.HttpEntity | ||
import org.apache.http.HttpResponse | ||
import org.apache.http.client.HttpClient | ||
import org.apache.http.client.methods.HttpPost | ||
import org.apache.http.entity.ContentType | ||
import org.apache.http.entity.StringEntity | ||
import org.apache.http.impl.client.HttpClientBuilder | ||
import org.apache.http.util.EntityUtils | ||
import org.junit.jupiter.api.MethodOrderer | ||
import org.junit.jupiter.api.Order | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import org.junit.jupiter.api.TestMethodOrder | ||
import spock.lang.Specification | ||
|
||
import java.nio.file.Files | ||
import java.nio.file.Paths | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 应该使用spock的 |
||
class SampleApiTest extends Specification { | ||
class ApiResponse { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以直接用map,不需要单独定义类 |
||
int statusCode; | ||
String responseContent; | ||
|
||
ApiResponse(int statusCode, String responseContent) { | ||
this.statusCode = statusCode; | ||
this.responseContent = responseContent; | ||
} | ||
|
||
int getStatusCode() { | ||
return statusCode | ||
} | ||
|
||
void setStatusCode(int statusCode) { | ||
this.statusCode = statusCode | ||
} | ||
|
||
String getResponseContent() { | ||
return responseContent | ||
} | ||
|
||
void setResponseContent(String responseContent) { | ||
this.responseContent = responseContent | ||
} | ||
} | ||
|
||
|
||
@Test | ||
@Order(1) | ||
public void testChoiceSampleAddDescriptor() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里没有使用spock的基本测试格式 |
||
String url = "http://localhost:8080/flow/bg/manage/descriptor/add_descriptor.json?business_id=rillFlowSample&feature_name=choiceSample&alias=release"; | ||
String contentType = "text/plain"; | ||
String requestData = readFileContent("../docs/samples/choice-sample.yaml"); | ||
// 执行 API 请求并获取响应 | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
// 使用测试断言来验证测试结果 | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里没有使用spock风格的assert |
||
} | ||
|
||
@Test | ||
@Order(2) | ||
public void testChoiceSampleSubmit() { | ||
String url = "http://localhost:8080/flow/submit.json?descriptor_id=rillFlowSample:choiceSample"; | ||
String contentType = "application/json"; | ||
String requestData = "{\"input_num\":10}"; | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
} | ||
|
||
@Test | ||
@Order(3) | ||
public void testCallApiSampleAddDescriptor() { | ||
String url = "http://localhost:8080/flow/bg/manage/descriptor/add_descriptor.json?business_id=rillFlowSample&feature_name=callApiSample&alias=release"; | ||
String contentType = "text/plain"; | ||
String requestData = readFileContent("../docs/samples/call-api-sample.yaml"); | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
} | ||
|
||
@Test | ||
@Order(4) | ||
public void testCallApiSampleSubmit() { | ||
String url = "http://localhost:8080/flow/submit.json?descriptor_id=rillFlowSample:callApiSample"; | ||
String contentType = "application/json"; | ||
String requestData = "{\"input_num\":10}"; | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 只验证了状态码,没有验证返回内容和图的业务结果 |
||
} | ||
|
||
@Test | ||
@Order(5) | ||
public void testParallelAsyncTaskAddDescriptor() { | ||
String url = "http://localhost:8080/flow/bg/manage/descriptor/add_descriptor.json?business_id=rillFlowSample&feature_name=parallelAsyncTask&alias=release"; | ||
String contentType = "text/plain"; | ||
String requestData = readFileContent("../docs/samples/parallel-async-dag.yaml"); | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
} | ||
|
||
@Test | ||
@Order(6) | ||
public void testParallelAsyncTaskSubmit() { | ||
String url = "http://localhost:8080/flow/submit.json?descriptor_id=rillFlowSample:parallelAsyncTask"; | ||
String contentType = "application/json"; | ||
String requestData = "{\"rand_num\":20}"; | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
} | ||
|
||
@Test | ||
@Order(7) | ||
public void testSubDagTaskAddDescriptor() { | ||
String url = "http://localhost:8080/flow/bg/manage/descriptor/add_descriptor.json?business_id=rillFlowSample&feature_name=subdagTask&alias=release"; | ||
String contentType = "text/plain"; | ||
String requestData = readFileContent("../docs/samples/ref-dag.yaml"); | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
} | ||
|
||
@Test | ||
@Order(8) | ||
public void testSubDagTaskSubmit() { | ||
String url = "http://localhost:8080/flow/submit.json?descriptor_id=rillFlowSample:subdagTask"; | ||
String contentType = "application/json"; | ||
String requestData = "{\"parent_rand_num\":20}"; | ||
ApiResponse response = sendApiRequest(url, contentType, requestData); | ||
assertEquals(200, response.getStatusCode(), response.getResponseContent()); | ||
} | ||
|
||
|
||
|
||
|
||
private String readFileContent(String filePath) { | ||
try { | ||
// 读取文件内容并返回 | ||
return new String(Files.readAllBytes(Paths.get(filePath))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
|
||
private ApiResponse sendApiRequest(String url, String contentType, String requestData) { | ||
HttpClient httpClient = HttpClientBuilder.create().build(); | ||
try { | ||
HttpPost httpPost = new HttpPost(url); | ||
httpPost.addHeader("Content-Type", contentType); | ||
|
||
// 设置请求体 | ||
httpPost.setEntity(new StringEntity(requestData, ContentType.create(contentType))); | ||
|
||
HttpResponse response = httpClient.execute(httpPost); | ||
HttpEntity entity = response.getEntity(); | ||
|
||
// 获取响应状态码和内容 | ||
int statusCode = response.getStatusLine().getStatusCode(); | ||
String responseContent = EntityUtils.toString(entity); | ||
|
||
return new ApiResponse(statusCode, responseContent); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 可以直接用 |
||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return null; | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
应该默认不运行rill-flow-test,而不是显式指定不运行