From 1685f1bc95bf44584ea52ff2a460c6d598714917 Mon Sep 17 00:00:00 2001 From: wangjianqiang24 Date: Fri, 23 Oct 2020 14:10:07 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=BB=A7=E6=89=BFspringb?= =?UTF-8?q?oot?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../baidu/fsg/uid/UidAutoConfiguraition.java | 91 ++++++++++ .../java/com/baidu/fsg/uid/UidProperties.java | 171 ++++++++++++++++++ .../fsg/uid/worker/dao/WorkerNodeDAO.java | 1 + src/main/resources/META-INF/spring.factories | 1 + .../baidu/fsg/uid/CachedUidGeneratorTest.java | 33 ++-- .../fsg/uid/DefaultUidGeneratorTest.java | 25 +-- .../java/com/baidu/fsg/uid/RejectHandler.java | 21 +++ src/test/resources/application.yml | 14 ++ src/test/resources/uid/cached-uid-spring.xml | 39 ---- src/test/resources/uid/default-uid-spring.xml | 22 --- src/test/resources/uid/mybatis-spring.xml | 80 -------- src/test/resources/uid/mysql.properties | 23 --- 12 files changed, 330 insertions(+), 191 deletions(-) create mode 100644 src/main/java/com/baidu/fsg/uid/UidAutoConfiguraition.java create mode 100644 src/main/java/com/baidu/fsg/uid/UidProperties.java create mode 100644 src/main/resources/META-INF/spring.factories create mode 100644 src/test/java/com/baidu/fsg/uid/RejectHandler.java create mode 100644 src/test/resources/application.yml delete mode 100644 src/test/resources/uid/cached-uid-spring.xml delete mode 100644 src/test/resources/uid/default-uid-spring.xml delete mode 100644 src/test/resources/uid/mybatis-spring.xml delete mode 100644 src/test/resources/uid/mysql.properties diff --git a/src/main/java/com/baidu/fsg/uid/UidAutoConfiguraition.java b/src/main/java/com/baidu/fsg/uid/UidAutoConfiguraition.java new file mode 100644 index 0000000..e4c4f8a --- /dev/null +++ b/src/main/java/com/baidu/fsg/uid/UidAutoConfiguraition.java @@ -0,0 +1,91 @@ +package com.baidu.fsg.uid; + +import java.util.Objects; + +import com.baidu.fsg.uid.buffer.RejectedPutBufferHandler; +import com.baidu.fsg.uid.buffer.RejectedTakeBufferHandler; +import com.baidu.fsg.uid.impl.CachedUidGenerator; +import com.baidu.fsg.uid.impl.DefaultUidGenerator; +import com.baidu.fsg.uid.worker.DisposableWorkerIdAssigner; + +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.ObjectProvider; +import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +/** + * uid autoConfiguration,if you want to use uid with springboot should set the property uid.enable = tre,you will enable default uid. + * @author wangjianqiang24 + * @date 2020/10/22 + */ +@Configuration +@ConditionalOnProperty(name = "uid.enable",havingValue = "true") +@EnableConfigurationProperties(UidProperties.class) +public class UidAutoConfiguraition implements ApplicationContextAware { + + @Bean + public DisposableWorkerIdAssigner disposableWorkerIdAssigner(){ + return new DisposableWorkerIdAssigner(); + } + + + @Bean + @ConditionalOnProperty(name = "uid.cached.enable",havingValue = "true") + @ConfigurationProperties(prefix = "uid.cached") + public UidProperties cachedUidProperties(){ + return new UidProperties(); + } + + + @Bean + @ConditionalOnProperty(name = "uid.cached.enable",havingValue = "true") + public UidGenerator cachedUidGenerator(UidProperties cachedUidProperties, ObjectProvider rejectedTakeBufferHandlers,ObjectProvider rejectedPutBufferHandlers){ + CachedUidGenerator uidGenerator = new CachedUidGenerator(); + uidGenerator.setWorkerIdAssigner(disposableWorkerIdAssigner()); + uidGenerator.setEpochStr(cachedUidProperties.getEpochStr()); + uidGenerator.setSeqBits(cachedUidProperties.getSeqBits()); + uidGenerator.setTimeBits(cachedUidProperties.getTimeBits()); + uidGenerator.setWorkerBits(cachedUidProperties.getWorkerBits()); + uidGenerator.setBoostPower(cachedUidProperties.getBoostPower()); + if (rejectedTakeBufferHandlers.getIfAvailable() != null) + uidGenerator.setRejectedTakeBufferHandler(rejectedTakeBufferHandlers.getIfAvailable()); + if (rejectedPutBufferHandlers.getIfAvailable() != null) + uidGenerator.setRejectedPutBufferHandler(rejectedPutBufferHandlers.getIfAvailable()); + if (Objects.nonNull(cachedUidProperties.getScheduleInterval())) + uidGenerator.setScheduleInterval(cachedUidProperties.getScheduleInterval()); + return uidGenerator; + } + + + @Bean + public UidProperties uidProperties(){ + return new UidProperties(); + } + + @Bean + @ConditionalOnMissingBean + public UidGenerator defaultUidGenerator(UidProperties uidProperties){ + DefaultUidGenerator uidGenerator = new DefaultUidGenerator(); + uidGenerator.setWorkerIdAssigner(disposableWorkerIdAssigner()); + uidGenerator.setEpochStr(uidProperties.getEpochStr()); + uidGenerator.setSeqBits(uidProperties.getSeqBits()); + uidGenerator.setTimeBits(uidProperties.getTimeBits()); + uidGenerator.setWorkerBits(uidProperties.getWorkerBits()); + return uidGenerator; + } + + + + private ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + this.applicationContext = applicationContext; + } +} diff --git a/src/main/java/com/baidu/fsg/uid/UidProperties.java b/src/main/java/com/baidu/fsg/uid/UidProperties.java new file mode 100644 index 0000000..4e7fda5 --- /dev/null +++ b/src/main/java/com/baidu/fsg/uid/UidProperties.java @@ -0,0 +1,171 @@ +package com.baidu.fsg.uid; + +import java.util.concurrent.TimeUnit; + +import com.baidu.fsg.uid.buffer.RingBuffer; + +import org.springframework.boot.context.properties.ConfigurationProperties; + +/** + * + * @author wangjianqiang24 + * @date 2020/10/23 + */ +@ConfigurationProperties(prefix = "uid") +public class UidProperties { + + private static final int DEFAULT_BOOST_POWER = 3; + + private int timeBits = 28; + private int workerBits = 22; + private int seqBits = 13; + + /** Customer epoch, unit as second. For example 2016-05-20 (ms: 1463673600000)*/ + private String epochStr = "2016-05-20";protected long epochSeconds = TimeUnit.MILLISECONDS.toSeconds(1463673600000L); + + private long workerId; + + /** Volatile fields caused by nextId() */ + private long sequence = 0L; + private long lastSecond = -1L; + + //-------------------cache属性---------- + /** Spring properties */ + /** + * RingBuffer size扩容参数, 可提高UID生成的吞吐量. + * 默认:3, 原bufferSize=8192, 扩容后bufferSize= 8192 << 3 = 65536 + */ + private int boostPower = DEFAULT_BOOST_POWER; + + /** + * 指定何时向RingBuffer中填充UID, 取值为百分比(0, 100), 默认为50 + * 举例: bufferSize=1024, paddingFactor=50 -> threshold=1024 * 50 / 100 = 512. + * 当环上可用UID数量 < 512时, 将自动对RingBuffer进行填充补全 + */ + private int paddingFactor = RingBuffer.DEFAULT_PADDING_PERCENT; + + /** + * 另外一种RingBuffer填充时机, 在Schedule线程中, 周期性检查填充 + * 默认:不配置此项, 即不实用Schedule线程. 如需使用, 请指定Schedule线程时间间隔, 单位:秒 + */ + private Long scheduleInterval; + + + + public int getTimeBits() { + return timeBits; + } + + public void setTimeBits(int timeBits) { + this.timeBits = timeBits; + } + + public int getWorkerBits() { + return workerBits; + } + + public void setWorkerBits(int workerBits) { + this.workerBits = workerBits; + } + + public int getSeqBits() { + return seqBits; + } + + public void setSeqBits(int seqBits) { + this.seqBits = seqBits; + } + + public String getEpochStr() { + return epochStr; + } + + public void setEpochStr(String epochStr) { + this.epochStr = epochStr; + } + + public long getEpochSeconds() { + return epochSeconds; + } + + public void setEpochSeconds(long epochSeconds) { + this.epochSeconds = epochSeconds; + } + + public long getWorkerId() { + return workerId; + } + + public void setWorkerId(long workerId) { + this.workerId = workerId; + } + + public long getSequence() { + return sequence; + } + + public void setSequence(long sequence) { + this.sequence = sequence; + } + + public long getLastSecond() { + return lastSecond; + } + + public void setLastSecond(long lastSecond) { + this.lastSecond = lastSecond; + } + + public int getBoostPower() { + return boostPower; + } + + public void setBoostPower(int boostPower) { + this.boostPower = boostPower; + } + + public int getPaddingFactor() { + return paddingFactor; + } + + public void setPaddingFactor(int paddingFactor) { + this.paddingFactor = paddingFactor; + } + + public Long getScheduleInterval() { + return scheduleInterval; + } + + public void setScheduleInterval(Long scheduleInterval) { + this.scheduleInterval = scheduleInterval; + } + + @Override + public String toString() { + final StringBuilder sb = new StringBuilder("{"); + sb.append("\"timeBits\":") + .append(timeBits); + sb.append(",\"workerBits\":") + .append(workerBits); + sb.append(",\"seqBits\":") + .append(seqBits); + sb.append(",\"epochStr\":\"") + .append(epochStr).append('\"'); + sb.append(",\"epochSeconds\":") + .append(epochSeconds); + sb.append(",\"workerId\":") + .append(workerId); + sb.append(",\"sequence\":") + .append(sequence); + sb.append(",\"lastSecond\":") + .append(lastSecond); + sb.append(",\"boostPower\":") + .append(boostPower); + sb.append(",\"paddingFactor\":") + .append(paddingFactor); + sb.append(",\"scheduleInterval\":") + .append(scheduleInterval); + sb.append("}"); + return sb.toString(); + } +} diff --git a/src/main/java/com/baidu/fsg/uid/worker/dao/WorkerNodeDAO.java b/src/main/java/com/baidu/fsg/uid/worker/dao/WorkerNodeDAO.java index 86d7f27..345b193 100644 --- a/src/main/java/com/baidu/fsg/uid/worker/dao/WorkerNodeDAO.java +++ b/src/main/java/com/baidu/fsg/uid/worker/dao/WorkerNodeDAO.java @@ -17,6 +17,7 @@ import com.baidu.fsg.uid.worker.entity.WorkerNodeEntity; import org.apache.ibatis.annotations.Param; + import org.springframework.stereotype.Repository; /** diff --git a/src/main/resources/META-INF/spring.factories b/src/main/resources/META-INF/spring.factories new file mode 100644 index 0000000..4bc3f67 --- /dev/null +++ b/src/main/resources/META-INF/spring.factories @@ -0,0 +1 @@ +org.springframework.boot.autoconfigure.EnableAutoConfiguration=com.baidu.fsg.uid.UidAutoConfiguraition \ No newline at end of file diff --git a/src/test/java/com/baidu/fsg/uid/CachedUidGeneratorTest.java b/src/test/java/com/baidu/fsg/uid/CachedUidGeneratorTest.java index f6801a3..be7c30f 100644 --- a/src/test/java/com/baidu/fsg/uid/CachedUidGeneratorTest.java +++ b/src/test/java/com/baidu/fsg/uid/CachedUidGeneratorTest.java @@ -1,14 +1,5 @@ package com.baidu.fsg.uid; -import com.baidu.fsg.uid.impl.CachedUidGenerator; -import org.apache.commons.lang.StringUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; - -import javax.annotation.Resource; import java.io.IOException; import java.util.ArrayList; import java.util.HashSet; @@ -17,13 +8,25 @@ import java.util.concurrent.ConcurrentSkipListSet; import java.util.concurrent.atomic.AtomicInteger; +import javax.annotation.Resource; + +import com.baidu.fsg.uid.impl.CachedUidGenerator; +import org.apache.commons.lang.StringUtils; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mybatis.spring.annotation.MapperScan; + +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; + /** * Test for {@link CachedUidGenerator} * * @author yutianbao */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:uid/cached-uid-spring.xml" }) +@EnableAutoConfiguration +@SpringBootTest(classes = {UidAutoConfiguraition.class,RejectHandler.class},properties = "uid.cached.enable=true") +@MapperScan(basePackages = "com.baidu.fsg.uid.worker.dao") public class CachedUidGeneratorTest { private static final int SIZE = 7000000; // 700w private static final boolean VERBOSE = false; @@ -76,7 +79,7 @@ public void testParallelGenerate() throws InterruptedException, IOException { } // Check generate 700w times - Assert.assertEquals(SIZE, control.get()); + Assertions.assertEquals(SIZE, control.get()); // Check UIDs are all unique checkUniqueID(uidSet); @@ -108,8 +111,8 @@ private void doGenerate(Set uidSet, int index) { } // Check UID is positive, and can be parsed - Assert.assertTrue(uid > 0L); - Assert.assertTrue(StringUtils.isNotBlank(parsedInfo)); + Assertions.assertTrue(uid > 0L); + Assertions.assertTrue(StringUtils.isNotBlank(parsedInfo)); if (VERBOSE) { System.out.println(Thread.currentThread().getName() + " No." + index + " >>> " + parsedInfo); @@ -121,7 +124,7 @@ private void doGenerate(Set uidSet, int index) { */ private void checkUniqueID(Set uidSet) throws IOException { System.out.println(uidSet.size()); - Assert.assertEquals(SIZE, uidSet.size()); + Assertions.assertEquals(SIZE, uidSet.size()); } } diff --git a/src/test/java/com/baidu/fsg/uid/DefaultUidGeneratorTest.java b/src/test/java/com/baidu/fsg/uid/DefaultUidGeneratorTest.java index 62364c5..19189ad 100644 --- a/src/test/java/com/baidu/fsg/uid/DefaultUidGeneratorTest.java +++ b/src/test/java/com/baidu/fsg/uid/DefaultUidGeneratorTest.java @@ -9,22 +9,23 @@ import javax.annotation.Resource; +import com.baidu.fsg.uid.impl.DefaultUidGenerator; import org.apache.commons.lang.StringUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import org.mybatis.spring.annotation.MapperScan; -import com.baidu.fsg.uid.impl.DefaultUidGenerator; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; /** * Test for {@link DefaultUidGenerator} * * @author yutianbao */ -@RunWith(SpringJUnit4ClassRunner.class) -@ContextConfiguration(locations = { "classpath:uid/default-uid-spring.xml" }) +@EnableAutoConfiguration +@SpringBootTest(classes = UidAutoConfiguraition.class) +@MapperScan(basePackages = "com.baidu.fsg.uid.worker.dao") public class DefaultUidGeneratorTest { private static final int SIZE = 100000; // 10w private static final boolean VERBOSE = true; @@ -74,7 +75,7 @@ public void testParallelGenerate() throws InterruptedException { } // Check generate 10w times - Assert.assertEquals(SIZE, control.get()); + Assertions.assertEquals(SIZE, control.get()); // Check UIDs are all unique checkUniqueID(uidSet); @@ -103,8 +104,8 @@ private void doGenerate(Set uidSet, int index) { uidSet.add(uid); // Check UID is positive, and can be parsed - Assert.assertTrue(uid > 0L); - Assert.assertTrue(StringUtils.isNotBlank(parsedInfo)); + Assertions.assertTrue(uid > 0L); + Assertions.assertTrue(StringUtils.isNotBlank(parsedInfo)); if (VERBOSE) { System.out.println(Thread.currentThread().getName() + " No." + index + " >>> " + parsedInfo); @@ -116,7 +117,7 @@ private void doGenerate(Set uidSet, int index) { */ private void checkUniqueID(Set uidSet) { System.out.println(uidSet.size()); - Assert.assertEquals(SIZE, uidSet.size()); + Assertions.assertEquals(SIZE, uidSet.size()); } } diff --git a/src/test/java/com/baidu/fsg/uid/RejectHandler.java b/src/test/java/com/baidu/fsg/uid/RejectHandler.java new file mode 100644 index 0000000..c628996 --- /dev/null +++ b/src/test/java/com/baidu/fsg/uid/RejectHandler.java @@ -0,0 +1,21 @@ +package com.baidu.fsg.uid; + +import com.baidu.fsg.uid.buffer.RejectedTakeBufferHandler; +import com.baidu.fsg.uid.buffer.RingBuffer; + +/** + * + * @author wangjianqiang24 + * @date 2020/10/23 + */ +public class RejectHandler implements RejectedTakeBufferHandler { + /** + * Reject take buffer request + * + * @param ringBuffer + */ + @Override + public void rejectTakeBuffer(RingBuffer ringBuffer) { + + } +} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 0000000..645c765 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,14 @@ +spring: + datasource: + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 123456 + url: jdbc:mysql://127.0.0.1:3306/zr?useUnicode=true&characterEncoding=utf8&autoReconnect=true&connectTimeout=2000&socketTimeout=2000&&serverTimezone=Asia/Shanghai + +mybatis: + mapper-locations: classpath:/META-INF/mybatis/mapper/WORKER*.xml + type-aliases-package: com.baidu.fsg.uid.worker.dao + + +uid: + enable: true diff --git a/src/test/resources/uid/cached-uid-spring.xml b/src/test/resources/uid/cached-uid-spring.xml deleted file mode 100644 index 7f81032..0000000 --- a/src/test/resources/uid/cached-uid-spring.xml +++ /dev/null @@ -1,39 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/uid/default-uid-spring.xml b/src/test/resources/uid/default-uid-spring.xml deleted file mode 100644 index 188be7f..0000000 --- a/src/test/resources/uid/default-uid-spring.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/uid/mybatis-spring.xml b/src/test/resources/uid/mybatis-spring.xml deleted file mode 100644 index 6339e9e..0000000 --- a/src/test/resources/uid/mybatis-spring.xml +++ /dev/null @@ -1,80 +0,0 @@ - - - - - - - - - - - - classpath:/uid/*.properties - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/test/resources/uid/mysql.properties b/src/test/resources/uid/mysql.properties deleted file mode 100644 index 01f1d6b..0000000 --- a/src/test/resources/uid/mysql.properties +++ /dev/null @@ -1,23 +0,0 @@ -#datasource db info -mysql.driver=com.mysql.jdbc.Driver -jdbc.url=jdbc:mysql://localhost:xxxx/xxxx -jdbc.username=xxxx -jdbc.password=xxxx -jdbc.maxActive=2 - -#datasource base -datasource.defaultAutoCommit=true -datasource.initialSize=2 -datasource.minIdle=0 -datasource.maxWait=5000 -datasource.testWhileIdle=true -datasource.testOnBorrow=true -datasource.testOnReturn=false -datasource.validationQuery=SELECT 1 FROM DUAL -datasource.timeBetweenEvictionRunsMillis=30000 -datasource.minEvictableIdleTimeMillis=60000 -datasource.logAbandoned=true -datasource.removeAbandoned=true -datasource.removeAbandonedTimeout=120 -datasource.filters=stat - From 82d4691be135051ff4e4a71e4b67887c2c81554b Mon Sep 17 00:00:00 2001 From: wangjianqiang24 Date: Fri, 23 Oct 2020 14:54:17 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=B5=8B=E8=AF=95=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E5=BA=93=E4=BD=BF=E7=94=A8h2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 265 ++++++++++++++--------------- src/test/resources/WORKER_NODE.sql | 12 ++ src/test/resources/application.yml | 5 +- 3 files changed, 139 insertions(+), 143 deletions(-) create mode 100644 src/test/resources/WORKER_NODE.sql diff --git a/pom.xml b/pom.xml index ceffec5..6ef4416 100644 --- a/pom.xml +++ b/pom.xml @@ -1,146 +1,129 @@ - 4.0.0 - UID-Generator - An unique id generator - - com.baidu.fsg - uid-generator - 1.0.0-SNAPSHOT - jar - - - - UTF-8 - 1.8 - 4.2.5.RELEASE - 1.7.7 - - - - - - - org.springframework - spring-core - ${spring.version} - - - org.springframework - spring-beans - ${spring.version} - - - org.springframework - spring-context - ${spring.version} - - - org.springframework - spring-jdbc - ${spring.version} - - - - - org.mybatis - mybatis - 3.2.3 - - - org.mybatis - mybatis-spring - 1.2.4 - - - - - commons-collections - commons-collections - 3.2.2 - - - commons-lang - commons-lang - 2.6 - - - - - ch.qos.logback - logback-classic - 1.1.3 - - - org.slf4j - slf4j-api - ${slf4j-version} - - - org.slf4j - log4j-over-slf4j - ${slf4j-version} - - - - - junit - junit - 4.10 - test - - - org.springframework - spring-test - ${spring.version} - test - - - - mysql - mysql-connector-java - 5.1.18 - test - - - - com.alibaba - druid - 1.0.19 - test - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - ${jdk.version} - ${jdk.version} - ${project.build.sourceEncoding} - - 3.5.1 - - - org.apache.maven.plugins - maven-source-plugin - 2.3 - - - package - - jar - - - - - - + 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"> + 4.0.0 + UID-Generator + An unique id generator + + com.baidu.fsg + uid-generator + 1.0.0-SNAPSHOT + jar + + + + UTF-8 + 1.8 + 4.2.5.RELEASE + 1.7.7 + 2.3.4.RELEASE + 8.0.16 + 2.1.3 + 1.4.200 + + + + + + + org.springframework.boot + spring-boot-starter + + + + org.springframework.boot + spring-boot-starter-logging + + + + org.mybatis.spring.boot + mybatis-spring-boot-starter + ${mybatis-spring-starter.version} + + + + + commons-collections + commons-collections + 3.2.2 + + + commons-lang + commons-lang + 2.6 + + + + org.springframework.boot + spring-boot-starter-test + test + + + + com.h2database + h2 + ${h2.version} + test + + + + org.springframework.boot + spring-boot-autoconfigure-processor + true + + + + org.springframework.boot + spring-boot-configuration-processor + true + + + + + + + + org.springframework.boot + spring-boot-dependencies + ${spring-boot.version} + pom + import + + + + mysql + mysql-connector-java + ${mysql-connector.version} + + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + ${jdk.version} + ${jdk.version} + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-source-plugin + + + package + + jar + + + + + + \ No newline at end of file diff --git a/src/test/resources/WORKER_NODE.sql b/src/test/resources/WORKER_NODE.sql new file mode 100644 index 0000000..1f85798 --- /dev/null +++ b/src/test/resources/WORKER_NODE.sql @@ -0,0 +1,12 @@ +DROP TABLE IF EXISTS WORKER_NODE; +CREATE TABLE WORKER_NODE +( +ID int NOT NULL identity COMMENT 'auto increment id', +HOST_NAME VARCHAR(64) NOT NULL COMMENT 'host name', +PORT VARCHAR(64) NOT NULL COMMENT 'port', +TYPE INT NOT NULL COMMENT 'node type: ACTUAL or CONTAINER', +LAUNCH_DATE DATE NOT NULL COMMENT 'launch date', +MODIFIED TIMESTAMP NOT NULL COMMENT 'modified time', +CREATED TIMESTAMP NOT NULL COMMENT 'created time', +PRIMARY KEY(ID) +); \ No newline at end of file diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml index 645c765..6a2ebef 100644 --- a/src/test/resources/application.yml +++ b/src/test/resources/application.yml @@ -1,9 +1,10 @@ spring: datasource: - driver-class-name: com.mysql.cj.jdbc.Driver + driver-class-name: org.h2.Driver username: root password: 123456 - url: jdbc:mysql://127.0.0.1:3306/zr?useUnicode=true&characterEncoding=utf8&autoReconnect=true&connectTimeout=2000&socketTimeout=2000&&serverTimezone=Asia/Shanghai + url: jdbc:h2:mem:uid + schema: classpath:WORKER_NODE.sql mybatis: mapper-locations: classpath:/META-INF/mybatis/mapper/WORKER*.xml