[e2eTest] add e2eTest model
diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-package.yml
similarity index 95%
rename from .github/workflows/maven-publish.yml
rename to .github/workflows/maven-package.yml
index fd183e2..37eb4dc 100644
--- a/.github/workflows/maven-publish.yml
+++ b/.github/workflows/maven-package.yml
@@ -1,7 +1,11 @@
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
name: Redis runner example
-on: push
+on:
+ pull_request:
+ types: [ opened, reopened, synchronize ]
+ release:
+ types: [ created ]
jobs:
# Label of the runner job
diff --git a/dist/pom.xml b/dist/pom.xml
new file mode 100644
index 0000000..8990d41
--- /dev/null
+++ b/dist/pom.xml
@@ -0,0 +1,158 @@
+<?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">
+ <parent>
+ <artifactId>rocketmq-eventbridge</artifactId>
+ <groupId>org.apache.rocketmq</groupId>
+ <version>1.0.0</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>rocketmq-eventbridge-dist</artifactId>
+
+ <properties>
+ <maven.compiler.source>8</maven.compiler.source>
+ <maven.compiler.target>8</maven.compiler.target>
+ </properties>
+ <dependencies>
+ <!-- Project Version -->
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-adapter-persistence</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-adapter-rpc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-adapter-api</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-adapter-runtime</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-adapter-storage</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-domain</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-infrastructure</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.rocketmq</groupId>
+ <artifactId>rocketmq-eventbridge-start</artifactId>
+ </dependency>
+ <!-- Framework -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-webflux</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-test</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <!--Tools -->
+ <dependency>
+ <groupId>com.google.code.gson</groupId>
+ <artifactId>gson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger2</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>io.springfox</groupId>
+ <artifactId>springfox-swagger-ui</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-validation</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>com.alibaba</groupId>
+ <artifactId>fastjson</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <resources>
+ <resource>
+ <directory>src/main/resources</directory>
+ <filtering>true</filtering>
+ <includes>
+ <include>logback.xml</include>
+ <include>application.properties</include>
+ <include>**/*.xml</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/java</directory>
+ <includes>
+ <include>**/*.properties</include>
+ <include>**/*.xml</include>
+ <include>**/*.tld</include>
+ </includes>
+ <filtering>false</filtering>
+ </resource>
+ </resources>
+ <plugins>
+ <plugin>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-maven-plugin</artifactId>
+ <version>2.2.10.RELEASE</version>
+ <executions>
+ <execution>
+ <id>repackage</id>
+ <goals>
+ <goal>repackage</goal>
+ </goals>
+ <configuration>
+ <mainClass>org.apache.rocketmq.eventbridge.StartMain</mainClass>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+ <profiles>
+ <profile>
+ <id>local</id>
+ <activation>
+ <activeByDefault>true</activeByDefault>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-assembly-plugin</artifactId>
+ <configuration>
+ <appendAssemblyId>false</appendAssemblyId>
+ <descriptors>
+ <descriptor>src/main/assembly/assembly.xml</descriptor>
+ </descriptors>
+ </configuration>
+ <executions>
+ <execution>
+ <id>assembly</id>
+ <phase>package</phase>
+ <goals>
+ <goal>single</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+
+ </profiles>
+</project>
\ No newline at end of file
diff --git a/dist/src/main/assembly/assembly.xml b/dist/src/main/assembly/assembly.xml
new file mode 100644
index 0000000..26b0cc6
--- /dev/null
+++ b/dist/src/main/assembly/assembly.xml
@@ -0,0 +1,35 @@
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+ <id>assembly</id>
+ <formats>
+ <format>dir</format>
+ </formats>
+
+ <includeBaseDirectory>true</includeBaseDirectory>
+ <baseDirectory>rocketmq-eventbridge</baseDirectory>
+ <dependencySets>
+ <dependencySet>
+ <outputDirectory>/</outputDirectory>
+ <includes>
+ <include>org.apache.rocketmq:rocketmq-eventbridge-dist:jar</include>
+ </includes>
+ <outputFileNameMapping>rocketmq-eventbridge.jar</outputFileNameMapping>
+ </dependencySet>
+ </dependencySets>
+
+ <fileSets>
+ <fileSet>
+ <directory>src/main/bin</directory>
+ <outputDirectory>bin/</outputDirectory>
+ <fileMode>0755</fileMode>
+ <lineEnding>unix</lineEnding>
+ <filtered>true</filtered>
+ </fileSet>
+ <fileSet>
+ <directory>src/main/resources</directory>
+ <outputDirectory>config/</outputDirectory>
+ <fileMode>0755</fileMode>
+ </fileSet>
+ </fileSets>
+</assembly>
\ No newline at end of file
diff --git a/bin/eventbridge.sh b/dist/src/main/bin/eventbridge.sh
similarity index 100%
rename from bin/eventbridge.sh
rename to dist/src/main/bin/eventbridge.sh
diff --git a/bin/runserver.sh b/dist/src/main/bin/runserver.sh
similarity index 97%
rename from bin/runserver.sh
rename to dist/src/main/bin/runserver.sh
index de9541c..dfa7221 100755
--- a/bin/runserver.sh
+++ b/dist/src/main/bin/runserver.sh
@@ -87,7 +87,6 @@
#JAVA_OPT="${JAVA_OPT} -Xdebug -Xrunjdwp:transport=dt_socket,address=9555,server=y,suspend=n"
JAVA_OPT="${JAVA_OPT} ${JAVA_OPT_EXT}"
JAVA_OPT="${JAVA_OPT} -cp ${CLASSPATH}"
-
-JAVA_OPT="${JAVA_OPT} -Dlogback.configurationFile=${BASE_DIR}/conf/logback.xml"
+JAVA_OPT="${JAVA_OPT} -Dlogback.configurationFile=${BASE_DIR}/config/logback.xml -Dspring.config.location=${BASE_DIR}/config/application.properties"
$JAVA ${JAVA_OPT} $@
\ No newline at end of file
diff --git a/dist/src/main/resources/application.properties b/dist/src/main/resources/application.properties
new file mode 100644
index 0000000..5911b30
--- /dev/null
+++ b/dist/src/main/resources/application.properties
@@ -0,0 +1,41 @@
+# 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.
+
+server.port=7001
+management.server.port=7002
+management.endpoints.web.base-path=/
+spring.profiles.active=local
+## database
+#spring.datasource.hikari.jdbc-url=jdbc:mysql://localhost:3306/eventBridge?useUnicode=true&characterEncoding=utf8&useSSL=false
+#spring.datasource.hikari.driver-class-name=com.mysql.jdbc.Driver
+#spring.datasource.hikari.username=xxxxx
+#spring.datasource.hikari.password=xxxxx
+mybatis.configuration.log-impl=org.apache.ibatis.logging.stdout.StdOutImpl
+## flyway
+## rocketmq
+rocketmq.namesrvAddr=localhost:9876
+
+rocketmq.cluster.name=DefaultCluster
+## runtime
+runtime.config.mode=DB
+runtime.storage.mode=ROCKETMQ
+rumtime.name=eventbridge-runtimer
+runtime.pluginpath=~/eventbridge/plugin
+
+
+## log
+app.name=rocketmqeventbridge
+log.level=INFO
+log.path=~/logs
\ No newline at end of file
diff --git a/dist/src/main/resources/logback.xml b/dist/src/main/resources/logback.xml
new file mode 100644
index 0000000..c86f339
--- /dev/null
+++ b/dist/src/main/resources/logback.xml
@@ -0,0 +1,63 @@
+<!-- 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. -->
+
+<configuration>
+ <jmxConfigurator/>
+
+ <springProperty scope="context" name="app.name" source="app.name"/>
+ <springProperty scope="context" name="log.path" source="log.path"/>
+ <springProperty scope="context" name="log.level" source="log.level"/>
+
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <target>System.out</target>
+ <encoder>
+ <pattern>%d{yyyy-MM-dd
+ HH:mm:ss.SSS}@@%X{traceId:-}@@%X{parentId:-}@@%X{spanId:-}@@[%thread]@@%level@@%logger{36}[%line]@@%msg%n
+ </pattern>
+ </encoder>
+ </appender>
+
+ <appender name="PROJECT" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.path}/${app.name}/${app.name}.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${log.path}/${app.name}/${app.name}.%d{yyyy-MM-dd}.log</fileNamePattern>
+ <maxHistory>30</maxHistory>
+ <totalSizeCap>10GB</totalSizeCap>
+ </rollingPolicy>
+ <encoder>
+ <pattern>%d{yyyy-MM-dd
+ HH:mm:ss.SSS}@@%X{traceId:-}@@%X{parentId:-}@@%X{spanId:-}@@[%thread]@@%level@@%logger{36}[%line]@@%msg%n
+ </pattern>
+ </encoder>
+ </appender>
+
+ <appender name="ACCESS" class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${log.path}/${app.name}/access.log</file>
+ <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
+ <fileNamePattern>${log.path}/${app.name}/access.%d{yyyy-MM-dd}.log</fileNamePattern>
+ <maxHistory>30</maxHistory>
+ <totalSizeCap>3GB</totalSizeCap>
+ </rollingPolicy>
+ <encoder>
+ <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS}@@%X{traceId:-}@@%X{parentId:-}@@%X{spanId:-}@@[%thread]@@%level@@%logger{36}[%line]@@%msg%n</pattern>
+ </encoder>
+ </appender>
+
+ <logger name="accessLog" level="${log.level}" additivity="false">
+ <appender-ref ref="ACCESS"/>
+ <appender-ref ref="STDOUT"/>
+ </logger>
+
+ <root level="${log.level}">
+ <appender-ref ref="STDOUT"/>
+ <appender-ref ref="PROJECT"/>
+ </root>
+</configuration>
\ No newline at end of file
diff --git a/pom.xml b/pom.xml
index dd83d24..b60d031 100644
--- a/pom.xml
+++ b/pom.xml
@@ -106,6 +106,7 @@
<module>common</module>
<module>infrastructure</module>
<module>test</module>
+ <module>dist</module>
</modules>
<dependencyManagement>
diff --git a/start/pom.xml b/start/pom.xml
index a7e115d..b07569a 100644
--- a/start/pom.xml
+++ b/start/pom.xml
@@ -91,8 +91,7 @@
</dependency>
</dependencies>
- <!-- <build>
- <finalName>rocketmq-eventbridge</finalName>
+ <build>
<resources>
<resource>
<directory>src/main/resources</directory>
@@ -114,22 +113,15 @@
</resource>
</resources>
<plugins>
+ <!-- java编译插件 -->
<plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- <version>2.2.10.RELEASE</version>
- <executions>
- <execution>
- <id>repackage</id>
- <goals>
- <goal>repackage</goal>
- </goals>
- <configuration>
- <mainClass>org.apache.rocketmq.eventbridge.StartMain</mainClass>
- </configuration>
- </execution>
- </executions>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>3.3.0</version>
+ <configuration>
+ <finalName>rocketmq-eventbridge-start-1.0.0</finalName>
+ </configuration>
</plugin>
</plugins>
- </build>-->
+ </build>
</project>
\ No newline at end of file
diff --git a/test/rocketmq-eventbridge-e2etest/pom.xml b/test/rocketmq-eventbridge-e2etest/pom.xml
index 8ded330..ac82308 100644
--- a/test/rocketmq-eventbridge-e2etest/pom.xml
+++ b/test/rocketmq-eventbridge-e2etest/pom.xml
@@ -27,6 +27,7 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
+ <scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
@@ -36,7 +37,6 @@
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.ow2.asm</groupId>
diff --git a/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/controller/ApplicationTagControllerTest.java b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/controller/ApplicationTagControllerTest.java
index 0f5446e..bac500b 100644
--- a/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/controller/ApplicationTagControllerTest.java
+++ b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/controller/ApplicationTagControllerTest.java
@@ -1,5 +1,7 @@
package org.apache.rocketmq.eventbridge.e2etest.controller;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.io.FileUtils;
import org.apache.rocketmq.eventbridge.Main;
import org.apache.rocketmq.eventbridge.e2etest.BaseTest;
import org.apache.rocketmq.eventbridge.e2etest.util.Utils;
@@ -11,21 +13,45 @@
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit4.SpringRunner;
+import java.io.File;
import java.util.HashMap;
import java.util.Map;
+@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = Main.class)
public class ApplicationTagControllerTest extends BaseTest {
@Test
- public void testGetAllApplicationTags() {
- String url = String.format("%s/bus/createEventBus", baseUrl);
- Map<String, String> maps = new HashMap<>();
- maps.put("eventBusName", "demo-bus");
- maps.put("description", "a demo bus.");
- ResponseEntity<Void> response = Utils.request(template, url, HttpMethod.POST, maps, Void.class);
+ public void testGetAllApplicationTags() throws Exception {
+
+ String url = String.format("%s/putEvents", baseUrl);
+ Map<String, String> headers = new HashMap<>();
+ headers.put("Content-Type", "application/json; charset=UTF-8");
+ headers.put("ce-specversion","1.0");
+ headers.put("ce-type", "com.github.pull_request.opened");
+ headers.put("ce-source", "https://github.com/cloudevents/spec/pull");
+ headers.put("ce-subject", "demo");
+ headers.put("ce-id", "1234-1234-1234");
+ headers.put("ce-datacontenttype", "application/json");
+ headers.put("ce-time","2018-04-05T17:31:00Z");
+ headers.put("ce-eventbusname", "demo-bus");
+
+ ResponseEntity<Void> response = Utils.request(template, url, HttpMethod.POST, "A test recrod.", Void.class, headers);
Assert.assertTrue(response.getStatusCode().is2xxSuccessful());
+
+ File file = new File(System.getProperty("user.home") + "/demo");
+ String data = null;
+ long current = System.currentTimeMillis();
+ while((System.currentTimeMillis() - current)/1000 <300 ) {
+ data = FileUtils.readFileToString(file, "UTF-8");
+ if (data != null) {
+ break;
+ }
+ Thread.sleep(1000);
+ }
+
+ Assert.assertEquals("A test recrod.\n", data);
}
diff --git a/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/util/Utils.java b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/util/Utils.java
index cc29fe7..6627ffe 100644
--- a/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/util/Utils.java
+++ b/test/rocketmq-eventbridge-e2etest/src/test/java/org/apache/rocketmq/eventbridge/e2etest/util/Utils.java
@@ -15,10 +15,9 @@
public class Utils {
- public static <T> ResponseEntity<T> request(TestRestTemplate template, String url, HttpMethod method, Object body, Class<T> clazz) {
- HttpHeaders headers = devHeaders();
-
- HttpEntity entity = new HttpEntity(body, headers);
+ public static <T> ResponseEntity<T> request(TestRestTemplate template, String url, HttpMethod method, Object body, Class<T> clazz, Map<String, String> headers) {
+ HttpHeaders httpHeaders = devHeaders(headers);
+ HttpEntity entity = new HttpEntity(body, httpHeaders);
return template.exchange(url, method, entity, clazz);
}
@@ -26,37 +25,25 @@
return template.getForEntity(url, clazz ,args);
}
- public static <T> ResponseEntity<T> requestAsAdmin(TestRestTemplate template, String url, HttpMethod method, Object body, Class<T> clazz) {
- HttpHeaders headers = new HttpHeaders();
- headers.add("X-AI-USER", "admin");
-
- HttpEntity entity = new HttpEntity(body, headers);
- return template.exchange(url, method, entity, clazz);
- }
-
- public static <T> ResponseEntity<T> request(TestRestTemplate template, String url, String fileKey, String file, Class<T> clazz, Object... urlVariables) throws IOException {
- HttpHeaders headers = devHeaders();
- headers.setContentType(MediaType.MULTIPART_FORM_DATA);
+ public static <T> ResponseEntity<T> requestByPost(TestRestTemplate template, String url, String fileKey, String file, Class<T> clazz, Map<String, String> headers, Object... urlVariables) throws IOException {
+ HttpHeaders httpHeaders = devHeaders(headers);
+ httpHeaders.setContentType(MediaType.MULTIPART_FORM_DATA);
MultiValueMap<String, Object> multipartRequest = new LinkedMultiValueMap<>();
multipartRequest.add(fileKey, new ClassPathResource(file));
- HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(multipartRequest, headers);
+ HttpEntity<MultiValueMap<String, Object>> entity = new HttpEntity<>(multipartRequest, httpHeaders);
return template.exchange(url, HttpMethod.POST, entity, clazz, urlVariables);
}
- private static HttpHeaders devHeaders() {
- HttpHeaders headers = new HttpHeaders();
- headers.add("X-AI-USER", "developer");
-
- return headers;
+ private static HttpHeaders devHeaders(Map<String, String> headers) {
+ HttpHeaders httpHeaders = new HttpHeaders();
+ if (headers != null && !headers.isEmpty()) {
+ for (Map.Entry<String, String> entry : headers.entrySet()) {
+ httpHeaders.add(entry.getKey(), entry.getValue());
+ }
+ }
+ return httpHeaders;
}
- public static <T> ResponseEntity<T> requestAsWanyaWu(TestRestTemplate template, String url, HttpMethod method, Object body, Class<T> clazz) {
- HttpHeaders headers = new HttpHeaders();
- headers.add("X-AI-USER", "vanya.wu");
-
- HttpEntity entity = new HttpEntity(body, headers);
- return template.exchange(url, method, entity, clazz);
- }
}