From d53a9acc2cc14c32e6c0d84f95adfefb4d286e19 Mon Sep 17 00:00:00 2001 From: macfx Date: Thu, 12 Mar 2015 01:39:33 +0800 Subject: [PATCH] dev --- conf/test/datasources.xml | 6 +- .../ctrip/zeus/service/DemoRepository.java | 5 + src/test/java/support/AbstractSpringTest.java | 9 ++ src/test/java/support/GenerateHSqlDBMain.java | 7 +- .../resources/sql/hsqldb-create-table.sql | 105 ++++++++++++++---- 5 files changed, 107 insertions(+), 25 deletions(-) diff --git a/conf/test/datasources.xml b/conf/test/datasources.xml index d4bab6f7..0129c35c 100644 --- a/conf/test/datasources.xml +++ b/conf/test/datasources.xml @@ -6,12 +6,12 @@ 1m 1000 - com.mysql.jdbc.Driver + org.hsqldb.jdbc.JDBCDriver sa - ~{e4d4da51d8c450d0d1c03948b6670} + - + diff --git a/src/test/java/com/ctrip/zeus/service/DemoRepository.java b/src/test/java/com/ctrip/zeus/service/DemoRepository.java index e9110982..0a13d84a 100644 --- a/src/test/java/com/ctrip/zeus/service/DemoRepository.java +++ b/src/test/java/com/ctrip/zeus/service/DemoRepository.java @@ -9,6 +9,7 @@ import org.springframework.stereotype.Repository; import org.unidal.dal.jdbc.DalException; import javax.annotation.Resource; +import javax.sql.DataSource; /** * @author:xingchaowang @@ -16,6 +17,10 @@ import javax.annotation.Resource; */ @Repository public class DemoRepository { + @Resource(name = "embeddedDataSource") + private DataSource embeddedDataSource; + + @Resource private AppDao appDao; diff --git a/src/test/java/support/AbstractSpringTest.java b/src/test/java/support/AbstractSpringTest.java index b4d8a84b..e9a07aaa 100644 --- a/src/test/java/support/AbstractSpringTest.java +++ b/src/test/java/support/AbstractSpringTest.java @@ -1,12 +1,21 @@ package support; +import com.ctrip.zeus.util.S; +import org.junit.Before; +import org.junit.BeforeClass; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests; +import java.io.File; + /** * @author:xingchaowang * @date: 3/10/2015. */ @ContextConfiguration("/test-spring-context.xml") public abstract class AbstractSpringTest extends AbstractJUnit4SpringContextTests{ + @BeforeClass + public static void setup(){ + S.setPropertyDefaultValue("CONF_DIR", new File("").getAbsolutePath() + "/conf/test"); + } } diff --git a/src/test/java/support/GenerateHSqlDBMain.java b/src/test/java/support/GenerateHSqlDBMain.java index b84ad585..e2e9372b 100644 --- a/src/test/java/support/GenerateHSqlDBMain.java +++ b/src/test/java/support/GenerateHSqlDBMain.java @@ -11,6 +11,7 @@ import java.util.regex.Pattern; public class GenerateHSqlDBMain { public static void main(String[] args) throws IOException { + File f = new File("src/main/resources/sql/create-table.sql"); BufferedReader reader = new BufferedReader(new FileReader(f)); @@ -44,6 +45,10 @@ public class GenerateHSqlDBMain { matcher = p.matcher(str); str = matcher.replaceAll("integer"); + p = Pattern.compile("int\\(.*?\\)"); + matcher = p.matcher(str); + str = matcher.replaceAll("int"); + p = Pattern.compile("DEFAULT.*,"); matcher = p.matcher(str); str = matcher.replaceAll(","); @@ -54,7 +59,7 @@ public class GenerateHSqlDBMain { p = Pattern.compile("UNIQUE KEY (`.*?`) (\\(.*?\\))"); matcher = p.matcher(str); - str = matcher.replaceAll("constraint $1 unique $2"); + str = matcher.replaceAll("constraint con_$1 unique $2"); p = Pattern.compile("`(.*?)`"); matcher = p.matcher(str); diff --git a/src/test/resources/sql/hsqldb-create-table.sql b/src/test/resources/sql/hsqldb-create-table.sql index bba470de..34363006 100644 --- a/src/test/resources/sql/hsqldb-create-table.sql +++ b/src/test/resources/sql/hsqldb-create-table.sql @@ -18,7 +18,7 @@ CREATE TABLE IF NOT EXISTS app ( created_time timestamp NULL , last_modified timestamp NOT NULL , - constraint name unique (name) + constraint con_name unique (name) ) ; @@ -29,13 +29,13 @@ CREATE TABLE IF NOT EXISTS app_health_check ( id integer NOT NULL IDENTITY, app_id integer NOT NULL , uri varchar(200) NOT NULL , - intervals int(11) NOT NULL , - fails int(11) NOT NULL , - passes int(11) NOT NULL , + intervals int NOT NULL , + fails int NOT NULL , + passes int NOT NULL , created_time timestamp NULL , last_modified timestamp NOT NULL , - - constraint application_id unique (app_id) + + constraint con_application_id unique (app_id) ) ; @@ -49,8 +49,8 @@ CREATE TABLE IF NOT EXISTS app_load_balancing_method ( value varchar(200) NOT NULL , created_time timestamp NULL , last_modified timestamp NOT NULL , - - constraint application_id unique (app_id) + + constraint con_application_id2 unique (app_id) ) ; @@ -61,16 +61,16 @@ CREATE TABLE IF NOT EXISTS app_server ( id integer NOT NULL IDENTITY, app_id integer NOT NULL , ip varchar(200) NOT NULL , - port int(11) NOT NULL , - weight int(11) NOT NULL , - max_fails int(11) NOT NULL , - fail_timeout int(11) NOT NULL , + port int NOT NULL , + weight int NOT NULL , + max_fails int NOT NULL , + fail_timeout int NOT NULL , healthy bit(1) NOT NULL , enable bit(1) NOT NULL , created_time timestamp NULL , last_modified timestamp NOT NULL , - - constraint app_id_ip unique (app_id,ip) + + constraint con_app_id_ip unique (app_id,ip) ) ; @@ -85,8 +85,8 @@ CREATE TABLE IF NOT EXISTS app_slb ( path varchar(200) NOT NULL , created_time timestamp NULL , last_modified timestamp NOT NULL , - - constraint app_id_slb_name_slb_virtual_server_name unique (app_id,slb_name,slb_virtual_server_name) + + constraint con_app_id_slb_name_slb_virtual_server_name unique (app_id,slb_name,slb_virtual_server_name) ) ; @@ -100,8 +100,8 @@ CREATE TABLE IF NOT EXISTS server ( up bit(1) NOT NULL , created_time timestamp NULL , last_modified timestamp NOT NULL , - - constraint ip unique (ip) + + constraint con_ip unique (ip) ) ; @@ -113,12 +113,75 @@ CREATE TABLE IF NOT EXISTS slb ( name varchar(100) NOT NULL , nginx_bin varchar(300) NOT NULL , nginx_conf varchar(300) NOT NULL , - nginx_worker_processes int(11) NOT NULL , + nginx_worker_processes int NOT NULL , status varchar(300) NOT NULL , created_time timestamp NULL , last_modified timestamp NOT NULL , - - constraint name unique (name) + + constraint con_name2 unique (name) ) ; + + + +CREATE TABLE IF NOT EXISTS slb_domain ( + id integer NOT NULL IDENTITY, + slb_virtual_server_id integer NOT NULL , + name varchar(200) NOT NULL , + created_time timestamp NULL , + last_modified timestamp NOT NULL , + + constraint con_slb_virtual_server_id_name unique (slb_virtual_server_id,name) +) ; + + + + + +CREATE TABLE IF NOT EXISTS slb_server ( + id integer NOT NULL IDENTITY, + slb_id integer NOT NULL , + ip varchar(50) NOT NULL , + host_name varchar(200) NOT NULL , + enable bit(1) NOT NULL , + created_time timestamp NULL , + last_modified timestamp NOT NULL , + + constraint con_ip2 unique (ip) +) ; + + + + + +CREATE TABLE IF NOT EXISTS slb_vip ( + id integer NOT NULL IDENTITY, + slb_id integer NOT NULL , + ip varchar(50) NOT NULL , + created_time timestamp NULL , + last_modified timestamp NOT NULL , + + constraint con_ip3 unique (ip) +) ; + + + + + +CREATE TABLE IF NOT EXISTS slb_virtual_server ( + id integer NOT NULL IDENTITY, + slb_id integer NOT NULL , + name varchar(200) NOT NULL , + port varchar(200) NOT NULL , + is_ssl bit(1) NOT NULL , + created_time timestamp NULL , + last_modified timestamp NOT NULL , + + constraint con_slb_id_name unique (slb_id,name) +) ; + + + + +