Skip to content

Commit

Permalink
Add test demo for database write prohibition plugin
Browse files Browse the repository at this point in the history
Signed-off-by: hanbingleixue <hanbingleixue@hotmail.com>
  • Loading branch information
hanbingleixue committed Mar 22, 2024
1 parent 3c1ae15 commit 712b84b
Show file tree
Hide file tree
Showing 24 changed files with 1,851 additions and 131 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "Opengauss Database Write Prohibition Plugin Test"
description: "Auto test for opengauss database write prohibition"
runs:
using: composite
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/database-write-prohibition/opengauss
- name: install opengauss
shell: bash
run: |
sudo apt-get update
sudo apt-get install -y apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
docker run --name opengauss -d --privileged=true -e GS_PASSWORD=${{ env.datasourcePassword }} -p 5432:5432 enmotech/opengauss:3.0.0
sleep 20s
- name: package demos
shell: bash
run: |
mvn package -Ddatabase.version=${{ matrix.opengaussVersion }} -Ddatabase.groupId=org.opengauss -Ddatabase.artifactId=opengauss-jdbc \
-DskipTests -Ppostgresql-opengauss-test --file sermant-integration-tests/database-write-prohibition-test/pom.xml
- name: start opengauss(org.opengauss) demo
if: matrix.opengaussVersion == '3.0.0' || matrix.opengaussVersion == '3.0.5-og' || matrix.opengaussVersion == '3.1.0-og' || matrix.opengaussVersion =='3.1.1-og'
shell: bash
env:
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.opengauss.Driver
SPRING_DATASOURCE_URL: jdbc:opengauss://127.0.0.1:5432/postgres?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
SPRING_DATASOURCE_USERNAME: gaussdb
SPRING_DATASOURCE_PASSWORD: ${{ env.datasourcePassword }}
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \
-Dsermant_log_dir=${{ env.logDir }}/opengauss \
sermant-integration-tests/database-write-prohibition-test/postgresql-opengauss-demo/target/postgresql-opengauss-demo.jar > ${{ env.logDir }}/opengauss.log 2>&1 &
- name: start opengauss(org.postgresql) demo
if: matrix.opengaussVersion == '3.1.0' || matrix.opengaussVersion =='3.1.1' || matrix.opengaussVersion == '3.0.5'
shell: bash
env:
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.postgresql.Driver
SPRING_DATASOURCE_URL: jdbc:postgresql://127.0.0.1:5432/postgres?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
SPRING_DATASOURCE_USERNAME: gaussdb
SPRING_DATASOURCE_PASSWORD: ${{ env.datasourcePassword }}
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \
-Dsermant_log_dir=${{ env.logDir }}/opengauss \
sermant-integration-tests/database-write-prohibition-test/postgresql-opengauss-demo/target/postgresql-opengauss-demo.jar > ${{ env.logDir }}/opengauss.log 2>&1 &
- name: waiting for services start
shell: bash
run: |
ps -ef | grep java
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/checkStatus 120
- name: test opengauss
shell: bash
run: |
mvn test -Ddatabase.prohibition.integration.test.type=POSTGRESQL_OPENGAUSS --file \
sermant-integration-tests/database-write-prohibition-test/database-write-prohibition-integration-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
with:
processor-keyword: postgresql
- name: if failure then upload error log
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: (${{ github.job }})-database-write-prohibition-opengauss-${{ matrix.opengaussVersion }}-logs
path: |
./*.log
./logs/**
if-no-files-found: warn
retention-days: 2
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: "Postgresql Database Write Prohibition Plugin Test"
description: "Auto test for postgresql database write prohibition"
runs:
using: composite
steps:
- name: entry
uses: ./.github/actions/common/entry
with:
log-dir: ./logs/database-write-prohibition/postgresql
- name: install postgresql
shell: bash
run: |
curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc|sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/postgresql.gpg
echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |sudo tee /etc/apt/sources.list.d/pgdg.list
sudo apt update
sudo apt install postgresql-14 -y
sudo service postgresql start
sudo service postgresql status
sudo -u postgres psql -c "CREATE DATABASE test;"
sudo chmod -R 777 /etc/postgresql/14/main/
sudo sed -i 's/scram-sha-256/trust/g' /etc/postgresql/14/main/pg_hba.conf
sudo sed -i 's/peer/trust/g' /etc/postgresql/14/main/pg_hba.conf
sudo echo "host all all all md5" >> /etc/postgresql/14/main/pg_hba.conf
sudo sed -i 's/#password_encryption = scram-sha-256/password_encryption = md5/g' /etc/postgresql/14/main/postgresql.conf
sudo -u postgres psql -c "SELECT pg_reload_conf();set password_encryption = 'md5';show password_encryption;ALTER USER postgres WITH PASSWORD '${{ env.datasourcePassword }}';"
- name: package demos
shell: bash
run: |
mvn package -Ddatabase.version=${{ matrix.postgresqlVersion }} -Ddatabase.groupId=org.postgresql -Ddatabase.artifactId=postgresql \
-DskipTests -Ppostgresql-opengauss-test --file sermant-integration-tests/database-write-prohibition-test/pom.xml
- name: start postgresql demo
shell: bash
env:
SPRING_DATASOURCE_DRIVER_CLASS_NAME: org.postgresql.Driver
SPRING_DATASOURCE_URL: jdbc:postgresql://127.0.0.1:5432/test?useUnicode=true&useSSL=false&characterEncoding=utf8&serverTimezone=GMT%2B8&allowPublicKeyRetrieval=true
SPRING_DATASOURCE_USERNAME: postgres
SPRING_DATASOURCE_PASSWORD: ${{ env.datasourcePassword }}
run: |
nohup java -javaagent:sermant-agent-${{ env.sermantVersion }}/agent/sermant-agent.jar -jar \
-Dsermant_log_dir=${{ env.logDir }}/postgresql \
sermant-integration-tests/database-write-prohibition-test/postgresql-opengauss-demo/target/postgresql-opengauss-demo.jar > ${{ env.logDir }}/postgresql.log 2>&1 &
- name: waiting for services start
shell: bash
run: |
ps -ef | grep java
bash ./sermant-integration-tests/scripts/checkService.sh http://127.0.0.1:8081/checkStatus 120
- name: test postgresql
shell: bash
run: |
mvn test -Ddatabase.prohibition.integration.test.type=POSTGRESQL_OPENGAUSS --file \
sermant-integration-tests/database-write-prohibition-test/database-write-prohibition-integration-test/pom.xml
- name: exit
if: always()
uses: ./.github/actions/common/exit
with:
processor-keyword: postgresql
- name: if failure then upload error log
uses: actions/upload-artifact@v3
if: ${{ failure() || cancelled() }}
with:
name: (${{ github.job }})-database-write-prohibition-postgresql-${{ matrix.postgresqlVersion }}-logs
path: |
./*.log
./logs/**
if-no-files-found: warn
retention-days: 2
Original file line number Diff line number Diff line change
Expand Up @@ -118,4 +118,92 @@ jobs:
- name: common operations
uses: ./.github/actions/common/database-write-prohibition
- name: database-write-prohibition-mysql test for mysqlClientVersion=${{ matrix.mysqlClientVersion }}
uses: ./.github/actions/scenarios/database-write-prohibition/mysql
uses: ./.github/actions/scenarios/database-write-prohibition/mysql
test-for-postgresql:
name: Test for postgresql
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
strategy:
matrix:
include:
- postgresqlVersion: "9.4-1200-jdbc4"
- postgresqlVersion: "9.4-1203-jdbc4"
- postgresqlVersion: "9.4-1206-jdbc4"
- postgresqlVersion: "9.4-1200-jdbc41"
- postgresqlVersion: "9.4-1203-jdbc41"
- postgresqlVersion: "9.4-1206-jdbc41"
- postgresqlVersion: "9.4.1207"
- postgresqlVersion: "9.4.1210"
- postgresqlVersion: "9.4.1212"
- postgresqlVersion: "42.0.0"
- postgresqlVersion: "42.1.0"
- postgresqlVersion: "42.1.2"
- postgresqlVersion: "42.1.4"
- postgresqlVersion: "42.2.0"
- postgresqlVersion: "42.2.3"
- postgresqlVersion: "42.2.6"
- postgresqlVersion: "42.2.9"
- postgresqlVersion: "42.2.12"
- postgresqlVersion: "42.2.15"
- postgresqlVersion: "42.2.18"
- postgresqlVersion: "42.2.21"
- postgresqlVersion: "42.2.24"
- postgresqlVersion: "42.2.27"
- postgresqlVersion: "42.2.29"
- postgresqlVersion: "42.3.0"
- postgresqlVersion: "42.3.3"
- postgresqlVersion: "42.3.6"
- postgresqlVersion: "42.3.8"
- postgresqlVersion: "42.3.10"
- postgresqlVersion: "42.4.0"
- postgresqlVersion: "42.4.3"
- postgresqlVersion: "42.4.5"
- postgresqlVersion: "42.5.0"
- postgresqlVersion: "42.5.3"
- postgresqlVersion: "42.5.6"
- postgresqlVersion: "42.6.0"
- postgresqlVersion: "42.6.2"
- postgresqlVersion: "42.7.0"
- postgresqlVersion: "42.7.2"
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
datasourcePassword=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 10)A1a#$
echo "datasourcePassword=$datasourcePassword" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/database-write-prohibition
- name: database-write-prohibition test for postgresqlVersion=${{ matrix.postgresqlVersion }}
uses: ./.github/actions/scenarios/database-write-prohibition/postgresql/
test-for-opengauss:
name: Test for opengauss
runs-on: ubuntu-latest
needs: [build-agent-and-cache, download-midwares-and-cache]
strategy:
matrix:
include:
- opengaussVersion: "3.0.0"
- opengaussVersion: "3.0.5"
- opengaussVersion: "3.0.5-og"
- opengaussVersion: "3.1.0"
- opengaussVersion: "3.1.0-og"
- opengaussVersion: "3.1.1"
- opengaussVersion: "3.1.1-og"
fail-fast: false
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 100
- name: set java version to environment
run: |
echo "javaVersion=8" >> $GITHUB_ENV
datasourcePassword=$(openssl rand -base64 16 | tr -dc 'a-zA-Z0-9' | head -c 10)A1a#$
echo "datasourcePassword=$datasourcePassword" >> $GITHUB_ENV
- name: common operations
uses: ./.github/actions/common/database-write-prohibition
- name: database-write-prohibition test for opengaussVersion=${{ matrix.opengaussVersion }}
uses: ./.github/actions/scenarios/database-write-prohibition/opengauss/
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,82 @@ public class DatabaseConstant {
public static final String SQL_EXCEPTION_MESSAGE_PREFIX = "Database prohibit to write";

/**
* fail to execute database write operation status code
* Status code for execute database operation failure
*/
public static final String OPERATION_FAIL_CODE = "100";

/**
* succeed to execute database write operation status code
* Status code for successful execute database operation
*/
public static final String OPERATION_SUCCEED_CODE = "101";

/**
* select sql
*/
public static final String SELECT_SQL = "SELECT NAME,AGE FROM %s WHERE %s = %s";

/**
* delete sql
*/
public static final String DELETE_SQL = "DELETE FROM %s WHERE %s = %s";

/**
* insert sql
*/
public static final String INSERT_SQL = "INSERT INTO %s (%s) values (%s) RETURNING id";

/**
* insert sql no return value
*/
public static final String INSERT_SQL_NO_RETURN = "INSERT INTO %s (%s) values (%s)";

/**
* update sql
*/
public static final String UPDATE_SQL = "UPDATE %s SET %s = %s WHERE %s = %s";

/**
* create table sql
*/
public static final String CREATE_TABLE_SQL = "CREATE TABLE %s (id int4 NOT NULL DEFAULT "
+ "nextval('%s'::regclass), name varchar(255) ,age int4)";

/**
* delete table sql
*/
public static final String DELETE_TABLE_SQL = "DROP TABLE %s";

/**
* create index sql
*/
public static final String CREATE_INDEX_SQL = "CREATE INDEX %s ON %s (%s)";

/**
* delete index sql
*/
public static final String DELETE_INDEX_SQL = "DROP INDEX %s";

/**
* create sequence sql
*/
public static final String CREATE_SEQUENCE_SQL = "CREATE SEQUENCE %s INCREMENT 1 MINVALUE 1 MAXVALUE "
+ "9223372036854775807 START 1 CACHE 1";

/**
* delete sequence sql
*/
public static final String DELETE_SEQUENCE_SQL = "DROP SEQUENCE %s";

/**
* alter table sql
*/
public static final String ALTER_TABLE_SQL = "ALTER TABLE %s ADD COLUMN %s %s";

/**
* Request parameter separator
*/
public static final String PARAM_SEPARATOR = ",";

private DatabaseConstant() {
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<curator.version>4.3.0</curator.version>
<httpclient4x.version>4.5.13</httpclient4x.version>
<commons-log.version>1.2</commons-log.version>
<fastjson.version>1.2.83</fastjson.version>
</properties>

<dependencies>
Expand All @@ -37,6 +38,12 @@
<version>${httpclient4x.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>${fastjson.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
Expand Down
Loading

0 comments on commit 712b84b

Please sign in to comment.