@Test public void testGetById() { for (int i = 1; i < 10; i++) { long id = i; User user = userDao.getUserById(id); System.out.println(user.getName()); } }
@Test public void testInsert() { for (int i = 1; i < 10; i++) { User user = new User(); long id = i; user.setId(id); user.setName("User" + i); // 插入 userDao.insert(user); System.out.println(user.getName()); } }
/** 测试读写分离 */ @Test public void testWriteMasterReadSlaves() { for (int i = 1; i < 10; i++) { User user = new User(); long id = i; user.setId(id); user.setName("User" + i); // 插入master userDao.insert(user); // 插入成功 RoutingHolder.setCurrentDataSourceKey(null); // Master int count = jdbcTemplate.queryForInt("select count(*) from user where id = " + id); Assert.assertEquals(1, count); System.out.println(user.getName()); // 从slave读 user = userDao.getUserById(id); Assert.assertNotNull(user); System.out.println(user.getName()); } }