From b63bc5152bb779eb1c783c4fb244199f4f1aeeaa Mon Sep 17 00:00:00 2001 From: c7ch23en Date: Mon, 16 Nov 2020 15:55:54 +0800 Subject: [PATCH] fix tests --- .../dal/dao/datasource/_AllTests.java | 4 - .../dal/dao/datasource/jdbc/DalDaoTest.java | 81 ------------- .../dao/datasource/jdbc/DalStatementTest.java | 106 ------------------ 3 files changed, 191 deletions(-) delete mode 100644 dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalDaoTest.java delete mode 100644 dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalStatementTest.java diff --git a/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/_AllTests.java b/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/_AllTests.java index d32ee4d0f..d2a0e025c 100644 --- a/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/_AllTests.java +++ b/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/_AllTests.java @@ -1,8 +1,6 @@ package com.ctrip.platform.dal.dao.datasource; import com.ctrip.platform.dal.dao.datasource.jdbc.DalConnectionTest; -import com.ctrip.platform.dal.dao.datasource.jdbc.DalDaoTest; -import com.ctrip.platform.dal.dao.datasource.jdbc.DalStatementTest; import com.ctrip.platform.dal.dao.datasource.log.ClusterDbSqlContextTest; import com.ctrip.platform.dal.dao.datasource.log.KeyedDbSqlContextTest; import com.ctrip.platform.dal.dao.datasource.monitor.DefaultDataSourceMonitorTest; @@ -17,8 +15,6 @@ ForceSwitchableDataSourceTest.class, LocalizedDataSourceTest.class, DalConnectionTest.class, - DalDaoTest.class, - DalStatementTest.class, ClusterDbSqlContextTest.class, KeyedDbSqlContextTest.class, DefaultDataSourceMonitorTest.class diff --git a/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalDaoTest.java b/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalDaoTest.java deleted file mode 100644 index a4eb7c42b..000000000 --- a/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalDaoTest.java +++ /dev/null @@ -1,81 +0,0 @@ -package com.ctrip.platform.dal.dao.datasource.jdbc; - -import com.ctrip.platform.dal.dao.*; -import com.ctrip.platform.dal.dao.datasource.DataSourceLocator; -import com.ctrip.platform.dal.dao.datasource.RefreshableDataSource; -import com.ctrip.platform.dal.dao.helper.FixedValueRowMapper; -import com.ctrip.platform.dal.dao.sqlbuilder.FreeUpdateSqlBuilder; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import java.sql.SQLException; - -/** - * Created by taochen on 2020/1/19. - */ -public class DalDaoTest { - private static final String dbName = "dao_test"; - private static final String KEY_NAME = "dao_test"; - - @Before - public void setUp() throws Exception { - DalClientFactory.initClientFactory(); - } - - @Test - public void testDalDaoExecuteSql() throws Exception { - //TestTableDao testTableDao = new TestTableDao(); - DalQueryDao client = new DalQueryDao(dbName); - - client.query("select 1", new StatementParameters(), new DalHints(), new FixedValueRowMapper<>()); - RefreshableDataSource dataSource = getDataSource(); - Assert.assertEquals(0, dataSource.getFirstAppearContinuousErrorTime()); - Assert.assertEquals(0, dataSource.getLastReportContinuousErrorTime()); - - try { - client.query("select * from noTable", new StatementParameters(), new DalHints(), new FixedValueRowMapper<>()); - } catch (SQLException e) { - } - Assert.assertNotEquals(0, dataSource.getFirstAppearContinuousErrorTime()); - Assert.assertEquals(1, dataSource.getContinuousErrorCount()); - Assert.assertEquals(0, dataSource.getLastReportContinuousErrorTime()); - - Thread.sleep(60*1000); - try { - client.query("select * from noTable", new StatementParameters(), new DalHints(), new FixedValueRowMapper<>()); - } catch (SQLException e) { - } - Assert.assertNotEquals(0, dataSource.getFirstAppearContinuousErrorTime()); - Assert.assertEquals(2, dataSource.getContinuousErrorCount()); - Assert.assertEquals(0, dataSource.getLastReportContinuousErrorTime()); - - try { - client.query("select * from noTable", new StatementParameters(), new DalHints(), new FixedValueRowMapper<>()); - } catch (SQLException e) { - } - Assert.assertNotEquals(0, dataSource.getFirstAppearContinuousErrorTime()); - Assert.assertEquals(3, dataSource.getContinuousErrorCount()); - Assert.assertNotEquals(0, dataSource.getLastReportContinuousErrorTime()); - - client.query("select 1", new StatementParameters(), new DalHints(), new FixedValueRowMapper<>()); - Assert.assertNotEquals(0, dataSource.getFirstAppearContinuousErrorTime()); - Assert.assertEquals(3, dataSource.getContinuousErrorCount()); - Assert.assertNotEquals(0, dataSource.getLastReportContinuousErrorTime()); - - try { - FreeUpdateSqlBuilder builder = new FreeUpdateSqlBuilder(); - builder.setTemplate("update noTable set id = 1 where id > 1"); - client.update(builder, new DalHints()); - } catch (SQLException e) { - } - Assert.assertNotEquals(0, dataSource.getFirstAppearContinuousErrorTime()); - Assert.assertEquals(4, dataSource.getContinuousErrorCount()); - Assert.assertNotEquals(0, dataSource.getLastReportContinuousErrorTime()); - } - - private RefreshableDataSource getDataSource() { - DataSourceLocator dataSourceLocator = new DataSourceLocator(); - return (RefreshableDataSource) dataSourceLocator.getDataSource(KEY_NAME); - } -} diff --git a/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalStatementTest.java b/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalStatementTest.java deleted file mode 100644 index f0bd441ae..000000000 --- a/dal-client/src/test/java/com/ctrip/platform/dal/dao/datasource/jdbc/DalStatementTest.java +++ /dev/null @@ -1,106 +0,0 @@ -package com.ctrip.platform.dal.dao.datasource.jdbc; - -import com.ctrip.platform.dal.dao.configure.DataSourceConfigure; -import com.ctrip.platform.dal.dao.datasource.RefreshableDataSource; -import org.junit.Assert; -import org.junit.Test; - -import java.sql.Connection; -import java.sql.SQLException; -import java.sql.Statement; -import java.util.Properties; - -import static com.ctrip.platform.dal.dao.configure.DataSourceConfigureConstants.*; - -public class DalStatementTest { - private Properties properties = new Properties(); - private RefreshableDataSource dataSource = null; - private Connection connection = null; - - { - properties.setProperty(USER_NAME, "root"); - properties.setProperty(PASSWORD, "123456"); - properties.setProperty(CONNECTION_URL, "jdbc:mysql://localhost:3306/test"); - properties.setProperty(DRIVER_CLASS_NAME, "com.mysql.jdbc.Driver"); - DataSourceConfigure configure = new DataSourceConfigure("DalService2DB_w", properties); - try { - dataSource = new RefreshableDataSource("DalService2DB_w", configure); - connection = dataSource.getConnection(); - } catch (SQLException e) { - - } - } - - @Test - public void testStatementExecuteQuery() throws Exception { - Statement statement = connection.createStatement(); - statement.executeQuery("select 1"); - - Assert.assertEquals(dataSource.getFirstAppearContinuousErrorTime(), 0); - Assert.assertEquals(dataSource.getLastReportContinuousErrorTime(), 0); - - try { - statement.executeQuery("select *from noTable"); - } catch (SQLException e) { - - } - Assert.assertNotEquals(dataSource.getFirstAppearContinuousErrorTime(), 0); - Assert.assertEquals(dataSource.getLastReportContinuousErrorTime(), 0); - - Thread.sleep(1000*60); - try { - statement.executeQuery("select *from noTable"); - } catch (SQLException e) { - - } - - Assert.assertNotEquals(dataSource.getFirstAppearContinuousErrorTime(), 0); - Assert.assertNotEquals(dataSource.getLastReportContinuousErrorTime(), 0); - - try { - statement.executeQuery("select 1"); - } catch (SQLException e) { - - } - - Assert.assertEquals(dataSource.getFirstAppearContinuousErrorTime(), 0); - Assert.assertEquals(dataSource.getLastReportContinuousErrorTime(), 0); - } - - @Test - public void testStatementExecuteUpdate() throws Exception { - Statement statement = connection.createStatement(); -// statement.executeUpdate("update noTable set id = 1"); -// TimeErrorLog timeErrorLog1 = dataSource.getSingleDataSource().getTimeErrorLog(); -// Assert.assertEquals(timeErrorLog1.getFirstErrorTime(), 0); -// Assert.assertEquals(timeErrorLog1.getLastReportErrorTime(), 0); - - try { - statement.executeUpdate("update noTable set id=2"); - } catch (SQLException e) { - - } - - Assert.assertNotEquals(dataSource.getFirstAppearContinuousErrorTime(), 0); - Assert.assertEquals(dataSource.getLastReportContinuousErrorTime(), 0); - - Thread.sleep(1000*60); - try { - statement.executeQuery("select *from noTable"); - } catch (SQLException e) { - - } - - Assert.assertNotEquals(dataSource.getFirstAppearContinuousErrorTime(), 0); - Assert.assertNotEquals(dataSource.getLastReportContinuousErrorTime(), 0); - - try { - statement.execute("select 1"); - } catch (SQLException e) { - - } - - Assert.assertEquals(dataSource.getFirstAppearContinuousErrorTime(), 0); - Assert.assertEquals(dataSource.getLastReportContinuousErrorTime(), 0); - } -}