use of com.ctrip.platform.dal.dao.configure.LocalDalPropertiesProvider in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testQueryByPkWithEntityImplicitAllShards.
@Test
public void testQueryByPkWithEntityImplicitAllShards() throws SQLException {
// set implicitAllShards on
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(new LocalDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
testQueryByPkWithEntity(new DalHints());
testQueryByPkWithEntity(asyncHints());
testQueryByPkWithEntity(callbackHints());
// set implicitAllShards on
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(DalElementFactory.DEFAULT.getDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
}
use of com.ctrip.platform.dal.dao.configure.LocalDalPropertiesProvider in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testQueryFromWithWhereClauseImplicitAllShards.
@Test
public void testQueryFromWithWhereClauseImplicitAllShards() throws SQLException {
// set implicitAllShards on
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(new LocalDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
List<ClientTestModel> models = null;
String whereClause = "dbIndex=? order by id";
// By parameters
StatementParameters parameters = new StatementParameters();
parameters.set(1, "dbIndex", Types.SMALLINT, 0);
try {
models = dao.queryFrom(whereClause, parameters, new DalHints(), 0, 10);
Assert.assertEquals(10, models.size());
} catch (Exception e) {
Assert.fail();
}
whereClause = "tableIndex=? order by id";
parameters = new StatementParameters();
parameters.set(1, "tableIndex", Types.SMALLINT, 0);
try {
models = dao.queryFrom(whereClause, parameters, new DalHints(), 0, 10);
Assert.assertEquals(2, models.size());
} catch (Exception e) {
Assert.fail();
}
// set implicitAllShards off
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(DalElementFactory.DEFAULT.getDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
}
use of com.ctrip.platform.dal.dao.configure.LocalDalPropertiesProvider in project dal by ctripcorp.
the class DalSqlTaskRequestTest method testImplicitAllShards.
@Test
public void testImplicitAllShards() throws Exception {
// set implicitAllShards on
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(new LocalDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
// implicit in all shards
DalSqlTaskRequest<Integer> testRequest = new DalSqlTaskRequest<>("dao_test_sqlsvr_dbTableShard", new TestTableSqlBuilder(), new DalHints(), new FreeSqlUpdateTask(), new ResultMerger.IntSummary());
Assert.assertTrue(testRequest.isCrossShard());
// implicit in all table shards
testRequest.validateAndPrepare();
Map<String, TaskCallable<Integer>> tasks = testRequest.createTasks();
for (Callable callable : tasks.values()) assertEquals(4, ((DalSqlTaskRequest.SqlTaskCallable) callable).tableShards().size());
// set implicitAllShards off
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(DalElementFactory.DEFAULT.getDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
// not implicit in all shards
try {
testRequest = new DalSqlTaskRequest<>("dao_test_sqlsvr_dbTableShard", new TestTableSqlBuilder(), new DalHints(), new FreeSqlUpdateTask(), new ResultMerger.IntSummary());
Assert.assertFalse(testRequest.isCrossShard());
} catch (Exception e) {
fail();
}
// not implicit in all shards
try {
testRequest = new DalSqlTaskRequest<>("dao_test_sqlsvr_tableShard", new TestTableSqlBuilder(), new DalHints(), new FreeSqlUpdateTask(), new ResultMerger.IntSummary());
testRequest.validateAndPrepare();
Callable<Integer> task = testRequest.createTask();
assertNull(((DalSqlTaskRequest.SqlTaskCallable) task).tableShards());
} catch (Exception e) {
fail();
}
}
use of com.ctrip.platform.dal.dao.configure.LocalDalPropertiesProvider in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testQueryListImplicitInAllDBAndAllTableShards.
@Test
public void testQueryListImplicitInAllDBAndAllTableShards() throws SQLException {
// set implicitAllShards on
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(new LocalDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
SelectSqlBuilder ssb1 = new SelectSqlBuilder();
ssb1.selectAll().from(TABLE_NAME).where(" id = 1 ");
try {
List<ClientTestModel> list = dao.query(ssb1, new DalHints());
Assert.assertEquals(8, list.size());
} catch (Exception e) {
Assert.fail();
}
SelectSqlBuilder ssb2 = new SelectSqlBuilder();
ssb2.selectAll().from(TABLE_NAME);
try {
List<ClientTestModel> list = dao.query(ssb2, new DalHints());
Assert.assertEquals(20, list.size());
} catch (Exception e) {
Assert.fail();
}
SelectSqlBuilder ssb3 = new SelectSqlBuilder();
ssb3.selectAll().from(TABLE_NAME).equal("dbIndex", 0, Types.INTEGER);
try {
List<ClientTestModel> list = dao.query(ssb3, new DalHints());
Assert.assertEquals(10, list.size());
} catch (Exception e) {
Assert.fail();
}
SelectSqlBuilder ssb4 = new SelectSqlBuilder();
ssb4.selectAll().from(TABLE_NAME).equal("tableIndex", 0, Types.INTEGER);
try {
List<ClientTestModel> list = dao.query(ssb4, new DalHints());
Assert.assertEquals(2, list.size());
} catch (Exception e) {
Assert.fail();
}
// set implicitAllShards off
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(DalElementFactory.DEFAULT.getDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
try {
List<ClientTestModel> list = dao.query(ssb1, new DalHints());
Assert.fail();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Can not locate table shard"));
}
SelectSqlBuilder ssb5 = new SelectSqlBuilder();
ssb5.selectAll().from(TABLE_NAME).equal("dbIndex", 0, Types.INTEGER);
try {
List<ClientTestModel> list = dao.query(ssb5, new DalHints());
Assert.fail();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Can not locate table shard"));
}
SelectSqlBuilder ssb6 = new SelectSqlBuilder();
ssb6.selectAll().from(TABLE_NAME).equal("tableIndex", 0, Types.INTEGER);
try {
List<ClientTestModel> list = dao.query(ssb6, new DalHints());
Assert.fail();
} catch (Exception e) {
assertTrue(e.getMessage().contains("Can not locate shard"));
}
}
use of com.ctrip.platform.dal.dao.configure.LocalDalPropertiesProvider in project dal by ctripcorp.
the class BaseDalTableDaoShardByDbTableTest method testInvalidShardid.
@Test
public void testInvalidShardid() throws Exception {
// set implicitAllShards on
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(new LocalDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
List<ClientTestModel> models = null;
String whereClause = "type=? order by id";
StatementParameters parameters = new StatementParameters();
parameters.set(1, Types.SMALLINT, 1);
try {
models = dao.queryFrom(whereClause, parameters, new DalHints().setShardValue("abc").setTableShardValue(1), 0, 10);
} catch (Exception e) {
assertTrue(e.getMessage().contains("For input string: \"abc\""));
}
try {
models = dao.queryFrom(whereClause, parameters, new DalHints().setShardValue(0).setTableShardValue("abc"), 0, 10);
} catch (Exception e) {
assertTrue(e.getMessage().contains("For input string: \"abc\""));
}
// set implicitAllShards off
DalPropertiesManager.getInstance().tearDown();
DalPropertiesManager.getInstance().setDalPropertiesProvider(DalElementFactory.DEFAULT.getDalPropertiesProvider());
DalPropertiesManager.getInstance().setup();
try {
models = dao.queryFrom(whereClause, parameters, new DalHints().setShardValue("abc").setTableShardValue(1), 0, 10);
} catch (Exception e) {
assertTrue(e.getMessage().contains("For input string: \"abc\""));
}
try {
models = dao.queryFrom(whereClause, parameters, new DalHints().setShardValue(0).setTableShardValue("abc"), 0, 10);
} catch (Exception e) {
e.printStackTrace();
assertTrue(e.getCause().getMessage().contains("For input string: \"abc\""));
}
}
Aggregations