Skip to content

Commit f733a9b

Browse files
committed
update test
1 parent a11c1e2 commit f733a9b

File tree

4 files changed

+110
-9
lines changed

4 files changed

+110
-9
lines changed

pom.xml

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.codingapi.dbstream</groupId>
66
<artifactId>dbstream-driver</artifactId>
7-
<version>1.0.14</version>
7+
<version>1.0.15</version>
88

99
<url>https://github.com/codingapi/dbstream-driver</url>
1010
<name>dbstream-driver</name>
@@ -23,8 +23,9 @@
2323
<maven.javadoc.plugin>3.6.1</maven.javadoc.plugin>
2424
<nexus.staging.maven.plugin>1.6.13</nexus.staging.maven.plugin>
2525
<maven.gpg.plugin>3.1.0</maven.gpg.plugin>
26-
<maven.jacoco.version>0.8.12</maven.jacoco.version>
26+
<maven.jacoco.version>0.8.14</maven.jacoco.version>
2727
<maven.openclover.version>4.5.2</maven.openclover.version>
28+
<maven-surefire-plugin.version>3.2.5</maven-surefire-plugin.version>
2829
<maven.source.version>3.3.1</maven.source.version>
2930
<maven.sonatype.version>0.8.0</maven.sonatype.version>
3031
<maven.javadoc.version>3.6.3</maven.javadoc.version>
@@ -112,6 +113,17 @@
112113

113114
<build>
114115
<plugins>
116+
<plugin>
117+
<groupId>org.apache.maven.plugins</groupId>
118+
<artifactId>maven-surefire-plugin</artifactId>
119+
<version>${maven-surefire-plugin.version}</version>
120+
<configuration>
121+
<forkCount>1</forkCount>
122+
<reuseForks>false</reuseForks>
123+
<argLine>${argLine}</argLine>
124+
</configuration>
125+
</plugin>
126+
115127
<plugin>
116128
<groupId>org.apache.maven.plugins</groupId>
117129
<artifactId>maven-jar-plugin</artifactId>

src/test/java/com/example/dbstream/tests/User1RepositoryTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.example.dbstream.entity.User1;
99
import com.example.dbstream.listener.MySQLListener;
1010
import com.example.dbstream.repository.User1Repository;
11+
import org.junit.jupiter.api.Order;
1112
import org.junit.jupiter.api.Test;
1213
import org.springframework.beans.factory.annotation.Autowired;
1314
import org.springframework.boot.test.context.SpringBootTest;
@@ -36,6 +37,7 @@ class User1RepositoryTest {
3637
@Test
3738
@Transactional
3839
@Rollback(false)
40+
@Order(1)
3941
void test1() {
4042

4143
DBStreamContext.getInstance().addListener(new MySQLListener());
@@ -81,6 +83,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
8183
@Test
8284
@Transactional
8385
@Rollback(false)
86+
@Order(2)
8487
void test2() {
8588
DBStreamContext.getInstance().cleanEventPushers();
8689

@@ -110,6 +113,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
110113
@Test
111114
@Transactional
112115
@Rollback(false)
116+
@Order(3)
113117
void test3() {
114118
DBStreamContext.getInstance().cleanEventPushers();
115119
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -130,6 +134,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
130134
@Test
131135
@Transactional
132136
@Rollback(false)
137+
@Order(4)
133138
void test4() {
134139
DBStreamContext.getInstance().cleanEventPushers();
135140
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -157,6 +162,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
157162
@Test
158163
@Transactional
159164
@Rollback(false)
165+
@Order(5)
160166
void test5() {
161167
DBStreamContext.getInstance().cleanEventPushers();
162168
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -184,6 +190,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
184190
@Test
185191
@Transactional
186192
@Rollback(false)
193+
@Order(6)
187194
void test6() {
188195
DBStreamContext.getInstance().cleanEventPushers();
189196
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -217,8 +224,8 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
217224
*/
218225
@Test
219226
@Transactional
227+
@Order(7)
220228
void test7() {
221-
222229
DBStreamContext.getInstance().cleanEventPushers();
223230
AtomicBoolean running = new AtomicBoolean(false);
224231
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -249,6 +256,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
249256
@Test
250257
@Transactional
251258
@Rollback(value = false)
259+
@Order(8)
252260
void test8() {
253261
DBStreamContext.getInstance().cleanEventPushers();
254262
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -278,9 +286,6 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
278286
}
279287
entityManager.flush();
280288
entityManager.clear();
281-
282-
283289
}
284290

285-
286291
}

src/test/java/com/example/dbstream/tests/User2RepositoryTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
import javax.transaction.Transactional;
1313

14+
import org.junit.jupiter.api.Order;
1415
import org.junit.jupiter.api.Test;
1516
import org.springframework.beans.factory.annotation.Autowired;
1617
import org.springframework.boot.test.context.SpringBootTest;
@@ -35,6 +36,7 @@ class User2RepositoryTest {
3536
@Test
3637
@Transactional
3738
@Rollback(false)
39+
@Order(1)
3840
void test1() {
3941
DBStreamContext.getInstance().addListener(new MySQLListener());
4042

@@ -85,6 +87,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
8587
@Test
8688
@Transactional
8789
@Rollback(false)
90+
@Order(2)
8891
void test2() {
8992
DBStreamContext.getInstance().cleanEventPushers();
9093

@@ -116,6 +119,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
116119
@Test
117120
@Transactional
118121
@Rollback(false)
122+
@Order(3)
119123
void test3() {
120124
DBStreamContext.getInstance().cleanEventPushers();
121125
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -137,6 +141,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
137141
@Test
138142
@Transactional
139143
@Rollback(false)
144+
@Order(4)
140145
void test4() {
141146
DBStreamContext.getInstance().cleanEventPushers();
142147
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -166,6 +171,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
166171
@Test
167172
@Transactional
168173
@Rollback(false)
174+
@Order(5)
169175
void test5() {
170176
DBStreamContext.getInstance().cleanEventPushers();
171177
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -193,6 +199,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
193199
*/
194200
@Test
195201
@Transactional
202+
@Order(6)
196203
void test6() {
197204
DBStreamContext.getInstance().cleanEventPushers();
198205
AtomicBoolean running = new AtomicBoolean(false);
@@ -226,6 +233,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
226233
@Test
227234
@Transactional
228235
@Rollback(false)
236+
@Order(7)
229237
void test7() {
230238
DBStreamContext.getInstance().cleanEventPushers();
231239
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
@@ -256,6 +264,7 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
256264
@Test
257265
@Transactional
258266
@Rollback(false)
267+
@Order(8)
259268
void test8() {
260269
DBStreamContext.getInstance().cleanEventPushers();
261270
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {

src/test/java/com/example/dbstream/tests/User3RepositoryTest.java

Lines changed: 78 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,18 @@
55
import com.codingapi.dbstream.event.DBEvent;
66
import com.codingapi.dbstream.event.DBEventPusher;
77
import com.codingapi.dbstream.query.JdbcQuery;
8+
import com.codingapi.dbstream.scanner.DBMetaData;
9+
import com.example.dbstream.entity.User3;
810
import com.example.dbstream.repository.User3Repository;
11+
import org.junit.jupiter.api.Order;
912
import org.junit.jupiter.api.Test;
1013
import org.springframework.beans.factory.annotation.Autowired;
1114
import org.springframework.boot.test.context.SpringBootTest;
1215
import org.springframework.test.annotation.Rollback;
1316

1417
import javax.transaction.Transactional;
1518
import java.util.List;
19+
import java.util.concurrent.atomic.AtomicBoolean;
1620

1721
import static org.junit.jupiter.api.Assertions.*;
1822

@@ -30,15 +34,16 @@ class User3RepositoryTest {
3034
@Test
3135
@Transactional
3236
@Rollback(value = false)
37+
@Order(1)
3338
void test1() {
3439
DBStreamContext.getInstance().cleanEventPushers();
3540
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
3641
@Override
3742
public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
38-
assertEquals(1,events.size());
39-
for (DBEvent event:events){
43+
assertEquals(1, events.size());
44+
for (DBEvent event : events) {
4045
assertTrue(event.hasPrimaryKeys());
41-
assertEquals("default",event.getData().get("ID"));
46+
assertEquals("default", event.getData().get("ID"));
4247
}
4348
}
4449
});
@@ -47,4 +52,74 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
4752
}
4853

4954

55+
/**
56+
* 测试指定表的 metadata更新
57+
*/
58+
@Test
59+
@Transactional
60+
@Rollback(value = false)
61+
@Order(2)
62+
void test2() {
63+
List<String> jdbcKeys = DBStreamContext.getInstance().loadDbKeys();
64+
assertEquals(1, jdbcKeys.size());
65+
for (String jdbcKey : jdbcKeys) {
66+
DBMetaData dbMetaData = DBStreamContext.getInstance().getMetaData(jdbcKey);
67+
assertNotNull(dbMetaData);
68+
dbMetaData.addUpdateSubscribe("m_user_3");
69+
}
70+
DBStreamContext.getInstance().cleanEventPushers();
71+
72+
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
73+
@Override
74+
public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
75+
assertEquals(1, events.size());
76+
for (DBEvent event : events) {
77+
assertTrue(event.hasPrimaryKeys());
78+
assertTrue(event.isInsert());
79+
}
80+
}
81+
});
82+
83+
User3 user = new User3();
84+
user.setEmail("[email protected]");
85+
user.setUsername("admin");
86+
user.setPassword("123");
87+
user.setNickname("admin");
88+
userRepository.save(user);
89+
90+
}
91+
92+
93+
/**
94+
* 测试清空 metadata
95+
*/
96+
@Test
97+
@Transactional
98+
@Rollback(value = false)
99+
@Order(3)
100+
void test3() {
101+
DBStreamContext.getInstance().clearAll();
102+
DBStreamContext.getInstance().cleanEventPushers();
103+
104+
AtomicBoolean running = new AtomicBoolean(false);
105+
106+
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
107+
@Override
108+
public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
109+
running.set(true);
110+
}
111+
});
112+
113+
User3 user = new User3();
114+
user.setEmail("[email protected]");
115+
user.setUsername("admin");
116+
user.setPassword("123");
117+
user.setNickname("admin");
118+
userRepository.save(user);
119+
120+
assertFalse(running.get());
121+
}
122+
123+
124+
50125
}

0 commit comments

Comments
 (0)