use of com.ctrip.platform.dal.dao.DalResultSetExtractor in project dal by ctripcorp.
the class HATest method testHAWithMarkdowns.
@Test
public void testHAWithMarkdowns() throws Exception {
DalStatusManager.getDataSourceStatus("MySqlShard_1").setManualMarkdown(true);
hints = new DalHints();
Integer count = 0;
try {
count = database2.query(sql, new StatementParameters(), hints, new DalResultSetExtractor<Integer>() {
@Override
public Integer extract(ResultSet rs) throws SQLException {
if (0 == markCount) {
markCount++;
mockRetryThrows(hints.getHA());
}
if (1 == markCount) {
markCount++;
mockFailOverThrow(hints.getHA());
} else {
//Here fail over to master
while (rs.next()) {
return rs.getInt(1);
}
}
return 0;
}
});
} catch (SQLException e) {
}
Assert.assertEquals(3, count == null ? 0 : count.intValue());
DalStatusManager.getDataSourceStatus("MySqlShard_1").setManualMarkdown(false);
}
use of com.ctrip.platform.dal.dao.DalResultSetExtractor in project dal by ctripcorp.
the class HATest method testTheSecondFailOverSuccess.
@Test
public void testTheSecondFailOverSuccess() throws SQLException {
hints = new DalHints();
Integer count = 0;
try {
count = database2.query(sql, new StatementParameters(), hints, new DalResultSetExtractor<Integer>() {
@Override
public Integer extract(ResultSet rs) throws SQLException {
if (1 == markCount) {
markCount++;
while (rs.next()) {
return rs.getInt(1);
}
} else {
markCount++;
mockFailOverThrow(hints.getHA());
}
return 0;
}
});
} catch (SQLException e) {
}
Assert.assertEquals(3, count == null ? 0 : count.intValue());
Assert.assertEquals(1, hints.getHA().getRetryCount());
}
use of com.ctrip.platform.dal.dao.DalResultSetExtractor in project dal by ctripcorp.
the class HATest method testTheSecondRetrySuccess.
@Test
public void testTheSecondRetrySuccess() {
hints = new DalHints();
Integer count = 0;
try {
count = database.query(sql, new StatementParameters(), hints, new DalResultSetExtractor<Integer>() {
@Override
public Integer extract(ResultSet rs) throws SQLException {
if (1 == markCount++) {
while (rs.next()) {
return rs.getInt(1);
}
}
mockRetryThrows(hints.getHA());
return 0;
}
});
} catch (SQLException e) {
}
Assert.assertEquals(3, count == null ? 0 : count.intValue());
}
Aggregations