Skip to content

Commit fdbf511

Browse files
committed
add test
1 parent f733a9b commit fdbf511

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

src/test/java/com/example/dbstream/repository/User1Repository.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,10 @@ public interface User1Repository extends JpaRepository<User1, Long> {
3232
@Query("insert into User1(email,username,password,nickname) select u.email,u.username,u.password,u.nickname from User1 u")
3333
void insertIntoFromSelect();
3434

35+
36+
@Modifying
37+
@Query("delete from User1")
38+
int deleteAllData();
39+
3540
}
3641

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

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
import javax.persistence.EntityManager;
1818
import javax.transaction.Transactional;
19+
import java.util.ArrayList;
1920
import java.util.List;
2021
import java.util.concurrent.atomic.AtomicBoolean;
2122

@@ -288,4 +289,37 @@ public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
288289
entityManager.clear();
289290
}
290291

292+
/**
293+
* 批量数据插入测试
294+
*/
295+
@Test
296+
@Transactional
297+
@Rollback(value = false)
298+
@Order(9)
299+
void test9() {
300+
DBStreamContext.getInstance().cleanEventPushers();
301+
DBStreamContext.getInstance().addEventPusher(new DBEventPusher() {
302+
@Override
303+
public void push(JdbcQuery jdbcQuery, List<DBEvent> events) {
304+
assertTrue(events.size()>=10);
305+
for (DBEvent event:events){
306+
assertTrue(event.hasPrimaryKeys());
307+
}
308+
}
309+
});
310+
List<User1> list = new ArrayList<>();
311+
for (int i = 0; i < 5; i++) {
312+
User1 user1 = new User1();
313+
user1.setUsername("admin1");
314+
user1.setPassword("admin1");
315+
user1.setEmail("[email protected]");
316+
user1.setNickname("admin1");
317+
list.add(user1);
318+
}
319+
userRepository.saveAll(list);
320+
321+
userRepository.deleteAllData();
322+
323+
}
324+
291325
}

0 commit comments

Comments
 (0)