Skip to content

Commit

Permalink
[Improvement][Seatunnel-web] Support H2 database in integration tests (
Browse files Browse the repository at this point in the history
  • Loading branch information
arshadmohammad authored Sep 27, 2024
1 parent d110b97 commit 5302b8c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<insert id="insert" keyColumn="id" keyProperty="id" parameterType="org.apache.seatunnel.app.dal.entity.User"
useGeneratedKeys="true">
insert into `user` (username, password, status, type)
value (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
values (#{username,jdbcType=VARCHAR}, #{password,jdbcType=VARCHAR}, #{status,jdbcType=TINYINT},
#{type,jdbcType=TINYINT})
</insert>
<update id="updateByPrimaryKey">
Expand Down Expand Up @@ -99,7 +99,7 @@
<select id="queryEnabledUsers" resultType="org.apache.seatunnel.app.dal.entity.User">
select
<include refid="Base_Column_List"/>
from user
from `user`
where status = 0
</select>
</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ CREATE TABLE role (
update_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

-- ----------------------------
-- Records of role
-- ----------------------------
INSERT INTO role (type, role_name, description) VALUES (0, 'ADMIN_ROLE', 'Admin User');
INSERT INTO role (type, role_name, description) VALUES (1, 'NORMAL_ROLE', 'Normal User');

-- ----------------------------
-- Table structure for role_user_relation
-- ----------------------------
Expand Down
11 changes: 7 additions & 4 deletions seatunnel-web-it/README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
Build seatunnel-web
./mvnw clean install -DskipTests

Update mysql database details in src/test/resources/application.yml and Run the seatunnel-web-it integration tests
./mvnw -T 1C -B verify -DskipUT=true -DskipIT=false -DSEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7 -DST_WEB_BASEDIR_PATH=seatunnel-web-dist/target/apache-seatunnel-web-1.0.0-SNAPSHOT/apache-seatunnel-web-1.0.0-SNAPSHOT
Run seatunnel-web-it integration tests
./mvnw -T 1C -B verify -DskipUT=true -DskipIT=false -DSEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7 -DST_WEB_BASEDIR_PATH=seatunnel-web-dist/target/apache-seatunnel-web-1.0.2-SNAPSHOT/apache-seatunnel-web-1.0.2-SNAPSHOT
NOTE: Please remember to update the versions according to the latest supported versions.

If you're using a version of Java higher than Java 8 for running the tests, add the following VM options:
-DitJvmArgs="--add-opens java.base/java.lang.invoke=ALL-UNNAMED".
-DitJvmArgs="-Xmx1024m --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED"

While running integrations tests from IDE, ensure following VM options are set
SEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7
ST_WEB_BASEDIR_PATH=/some/path/seatunnel-web-dist/target/apache-seatunnel-web-1.0.0-SNAPSHOT/apache-seatunnel-web-1.0.0-SNAPSHOT
ST_WEB_BASEDIR_PATH=/some/path/seatunnel-web-dist/target/apache-seatunnel-web-1.0.2-SNAPSHOT/apache-seatunnel-web-1.0.2-SNAPSHOT

By default, integration tests use the H2 database. If you want to use the MySQL database, update the MySQL database details in src/test/resources/application.yml and run the seatunnel-web-it integration tests with the -DdbType=mysql option as shown below:
./mvnw -T 1C -B verify -DskipUT=true -DskipIT=false -DdbType=mysql -DSEATUNNEL_HOME=/some/path/apache-seatunnel-2.3.7 -DST_WEB_BASEDIR_PATH=seatunnel-web-dist/target/apache-seatunnel-web-1.0.2-SNAPSHOT/apache-seatunnel-web-1.0.2-SNAPSHOT
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,19 @@
import lombok.extern.slf4j.Slf4j;

import java.io.File;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertTrue;

@Slf4j
public class SeaTunnelWebCluster {
private static final String DB_TYPE_H2 = "h2";
private static final String DB_TYPE_MYSQL = "mysql";
private static final Set<String> SUPPORTED_DB_TYPES =
Collections.unmodifiableSet(new HashSet<>(Arrays.asList(DB_TYPE_H2, DB_TYPE_MYSQL)));
private SeaTunnelServer server;
private HazelcastInstanceImpl instance;
private ConfigurableApplicationContext applicationContext;
Expand All @@ -59,8 +67,16 @@ public void start() {
server = instance.node.nodeEngine.getService(SeaTunnelServer.SERVICE_NAME);
ILogger LOGGER = instance.node.nodeEngine.getLogger(SeaTunnelWebCluster.class);

// String[] args = {"--spring.profiles.active=h2"};
String[] args = {};
// For integration tests, default database is H2, so the default spring profile is h2
String dbType = System.getProperty("dbType", DB_TYPE_H2);
if (!SUPPORTED_DB_TYPES.contains(dbType)) {
throw new IllegalArgumentException(
"Invalid dbType: " + dbType + ". Supported values are: " + SUPPORTED_DB_TYPES);
}

String springProfile = dbType.equals(DB_TYPE_MYSQL) ? "default" : "h2";
String[] args = {"--spring.profiles.active=" + springProfile};

applicationContext = SpringApplication.run(SeatunnelApplication.class, args);
LOGGER.info("SeaTunnel-web server started.");
assertTrue(isRunning());
Expand Down
11 changes: 10 additions & 1 deletion seatunnel-web-it/src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ jwt:

---
spring:
application:
name: seatunnel
jackson:
date-format: yyyy-MM-dd HH:mm:ss
config:
activate:
on-profile: h2
Expand All @@ -57,4 +61,9 @@ spring:
path: /h2
settings:
trace: false
web-allow-others: false
web-allow-others: false
jwt:
expireTime: 86400
# please add key when deploy
secretKey: https://github.com/apache/seatunnel
algorithm: HS256

0 comments on commit 5302b8c

Please sign in to comment.