use of com.ctrip.platform.dal.dao.DalQueryDao in project dal by ctripcorp.
the class DalWatcherTest method testQueryObjectWhenStarup.
@Test
public void testQueryObjectWhenStarup() throws Exception {
final AtomicReference<Boolean> done = new AtomicReference<>();
final AtomicReference<Boolean> p = new AtomicReference<>();
done.set(false);
p.set(false);
final DalQueryDao client = new DalQueryDao(DATABASE_NAME);
Runnable query = new Runnable() {
public void run() {
while (!done.get() && true) {
String sql = "SELECT quantity FROM " + TABLE_NAME;
StatementParameters param = new StatementParameters();
DalHints hints = new DalHints();
try {
client.queryFrom(sql, param, hints, Integer.class, 0, 10);
} catch (SQLException e) {
if (!p.get() && !e.getMessage().contains("Invalid object name 'dal_client_test'.")) {
e.printStackTrace();
p.set(true);
}
break;
}
if (done.get())
break;
}
}
};
DalClientFactory.shutdownFactory();
System.out.println("Factory is down");
int j = 3000;
while (j-- > 0) {
new Thread(query).start();
}
System.out.println("start threads...");
int i = 3;
while (i-- > 0) {
System.out.println("tic");
Thread.sleep(1 * 10000);
}
System.out.println("done main");
DalClientFactory.shutdownFactory();
done.set(true);
System.out.println("cool down");
Thread.sleep(2 * 1000);
}
use of com.ctrip.platform.dal.dao.DalQueryDao in project dal by ctripcorp.
the class SlaveFreshnessScannerMysqlTest method setUpBeforeClass.
@BeforeClass
public static void setUpBeforeClass() throws Exception {
freshnessMap.put("shard_0", 3);
freshnessMap.put("shard_1", 5);
freshnessMap.put("dal_shard_0", 7);
freshnessMap.put("dal_shard_1", 9);
Map<String, Integer> shardMap = new HashMap<>();
shardMap.put("shard_0", 3);
shardMap.put("shard_1", 5);
freshnessShardMap.put(0, shardMap);
shardMap = new HashMap<>();
shardMap.put("dal_shard_0", 7);
shardMap.put("dal_shard_1", 9);
freshnessShardMap.put(1, shardMap);
DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
String id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints(), String.class);
// make sure warmup is done.
Thread.sleep(1 * 1000);
}
use of com.ctrip.platform.dal.dao.DalQueryDao in project dal by ctripcorp.
the class SlaveFreshnessScannerMysqlTest method testShardBelow.
private void testShardBelow(int shardId, int freshness) throws SQLException {
DalQueryDao dao = new DalQueryDao(SHARD_DATABASE_NAME);
for (int i = 0; i < 100; i++) {
String id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints().freshness(freshness).inShard(shardId), String.class);
Assert.assertTrue(freshnessShardMap.get(shardId).get(id) <= freshness);
}
}
use of com.ctrip.platform.dal.dao.DalQueryDao in project dal by ctripcorp.
the class SlaveFreshnessScannerMysqlTest method testShardMaster.
private void testShardMaster(int freshness) throws SQLException {
DalQueryDao dao = new DalQueryDao(SHARD_DATABASE_NAME);
int shardId = 0;
while (shardId < 2) {
for (int i = 0; i < 100; i++) {
String id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints().freshness(freshness).inShard(shardId), String.class);
Assert.assertEquals(masterShard[shardId], id);
}
shardId++;
}
}
use of com.ctrip.platform.dal.dao.DalQueryDao in project dal by ctripcorp.
the class SlaveFreshnessScannerMysqlTest method testMaster.
private void testMaster(int freshness) throws SQLException {
DalQueryDao dao = new DalQueryDao(DATABASE_NAME);
for (int i = 0; i < 100; i++) {
String id = dao.queryForObject(GET_DB_NAME, new StatementParameters(), new DalHints().freshness(freshness), String.class);
Assert.assertEquals(master, id);
}
}
Aggregations