use of com.ctrip.platform.dal.dao.DalResultSetExtractor in project dal by ctripcorp.
the class HATest method testFirstRetrySecondeFailOver.
@Test
public void testFirstRetrySecondeFailOver() {
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 the third slave
while (rs.next()) {
return rs.getInt(1);
}
}
return 0;
}
});
} catch (SQLException e) {
}
Assert.assertEquals(3, count == null ? 0 : count.intValue());
}
use of com.ctrip.platform.dal.dao.DalResultSetExtractor in project dal by ctripcorp.
the class DalDirectClient method query.
@Override
public List<?> query(String sql, StatementParameters parameters, final DalHints hints, final List<DalResultSetExtractor<?>> extractors) throws SQLException {
ConnectionAction<List<?>> action = new ConnectionAction<List<?>>() {
@Override
public List<?> execute() throws Exception {
conn = getConnection(hints, this);
preparedStatement = createPreparedStatement(conn, sql, parameters, hints);
List<Object> result = new ArrayList<>();
DalWatcher.beginExecute();
preparedStatement.execute();
for (DalResultSetExtractor<?> extractor : extractors) {
ResultSet resultSet = preparedStatement.getResultSet();
Object partResult;
if (extractor instanceof HintsAwareExtractor)
partResult = ((DalResultSetExtractor) ((HintsAwareExtractor) extractor).extractWith(hints)).extract(resultSet);
else
partResult = extractor.extract(resultSet);
result.add(partResult);
preparedStatement.getMoreResults();
}
DalWatcher.endExectue();
return result;
}
};
action.populate(DalEventEnum.QUERY, sql, parameters);
return doInConnection(action, hints);
}
use of com.ctrip.platform.dal.dao.DalResultSetExtractor in project dal by ctripcorp.
the class HATest method testNotRetryNotFailOver.
@Test
public void testNotRetryNotFailOver() {
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 {
throw createException(-100);
}
});
} catch (SQLException e) {
}
Assert.assertEquals(0, 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 testAllRetryFailed.
@Test
public void testAllRetryFailed() {
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 {
mockRetryThrows(hints.getHA());
return 0;
}
});
} catch (SQLException e) {
}
Assert.assertEquals(0, count == null ? 0 : count.intValue());
Assert.assertEquals(DalStatusManager.getHaStatus().getRetryCount(), hints.getHA().getRetryCount());
}
use of com.ctrip.platform.dal.dao.DalResultSetExtractor in project dal by ctripcorp.
the class HATest method testAllFailOverFailed.
@Test
public void testAllFailOverFailed() {
hints = new DalHints();
Integer count = 0;
try {
count = database3.query(sql, new StatementParameters(), hints, new DalResultSetExtractor<Integer>() {
@Override
public Integer extract(ResultSet rs) throws SQLException {
mockFailOverThrow(hints.getHA());
return 0;
}
});
} catch (SQLException e) {
}
Assert.assertEquals(0, count == null ? 0 : count.intValue());
Assert.assertEquals(3, hints.getHA().getRetryCount());
}
Aggregations