@Test(expected = RuntimeException.class) public void throwRuntimeExceptionIfInsertFailed() { String appId = "appId"; String detail = "detail"; HeuristicsResultDB db = new HeuristicsResultDB(dbConfiguration); HeuristicResult heuristicResult = new HeuristicResult(appId, "attemptId", GCCause.class, 1, 1); heuristicResult.addDetail(detail, "value", "This is a new detail"); mysqld.stop(); db.createHeuristicResult(heuristicResult); }
public void createHeuristicResult(HeuristicResult heuristicResult) { int resultId = -1; executeUpdate(() -> { createYarnAppResultStat.clearParameters(); createYarnAppResultStat.setString(1, heuristicResult.getAppId()); createYarnAppResultStat.setString(2, heuristicResult.getHeuristicClass().getName()); createYarnAppResultStat.setString(3, heuristicResult.getHeuristicClass().getSimpleName() + "@" + heuristicResult.getAttemptId()); createYarnAppResultStat.setInt(4, heuristicResult.getSeverity()); createYarnAppResultStat.setInt(5, heuristicResult.getScore()); createYarnAppResultStat.setInt(6, 1); return createYarnAppResultStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_TABLENAME + " table"); try { try (ResultSet rsGenKey = createYarnAppResultStat.getGeneratedKeys()) { while (rsGenKey.next()) { resultId = rsGenKey.getInt(1); } } } catch (SQLException ex) { LOGGER.warn("Error reading YarnAppResult key", ex); return; } if (resultId == -1) { LOGGER.warn("No result id retrieve from insertion into {}", HEURISTIC_RESULT_TABLENAME); } for (int i = 0; i < heuristicResult.getDetailCount(); i++) { int finalResultId = resultId; int finalI = i; executeUpdate(() -> { createYarnAppResultDetailsStat.clearParameters(); HeuristicResult.HeuristicResultDetail detail = heuristicResult.getDetail(finalI); createYarnAppResultDetailsStat.setInt(1, finalResultId); createYarnAppResultDetailsStat.setString(2, detail.name); createYarnAppResultDetailsStat.setString(3, detail.value); createYarnAppResultDetailsStat.setString(4, detail.details); return createYarnAppResultDetailsStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_DETAILS_TABLENAME + " table"); } }
HeuristicsResultDB { public void createHeuristicResult(HeuristicResult heuristicResult) { int resultId = -1; executeUpdate(() -> { createYarnAppResultStat.clearParameters(); createYarnAppResultStat.setString(1, heuristicResult.getAppId()); createYarnAppResultStat.setString(2, heuristicResult.getHeuristicClass().getName()); createYarnAppResultStat.setString(3, heuristicResult.getHeuristicClass().getSimpleName() + "@" + heuristicResult.getAttemptId()); createYarnAppResultStat.setInt(4, heuristicResult.getSeverity()); createYarnAppResultStat.setInt(5, heuristicResult.getScore()); createYarnAppResultStat.setInt(6, 1); return createYarnAppResultStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_TABLENAME + " table"); try { try (ResultSet rsGenKey = createYarnAppResultStat.getGeneratedKeys()) { while (rsGenKey.next()) { resultId = rsGenKey.getInt(1); } } } catch (SQLException ex) { LOGGER.warn("Error reading YarnAppResult key", ex); return; } if (resultId == -1) { LOGGER.warn("No result id retrieve from insertion into {}", HEURISTIC_RESULT_TABLENAME); } for (int i = 0; i < heuristicResult.getDetailCount(); i++) { int finalResultId = resultId; int finalI = i; executeUpdate(() -> { createYarnAppResultDetailsStat.clearParameters(); HeuristicResult.HeuristicResultDetail detail = heuristicResult.getDetail(finalI); createYarnAppResultDetailsStat.setInt(1, finalResultId); createYarnAppResultDetailsStat.setString(2, detail.name); createYarnAppResultDetailsStat.setString(3, detail.value); createYarnAppResultDetailsStat.setString(4, detail.details); return createYarnAppResultDetailsStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_DETAILS_TABLENAME + " table"); } } }
HeuristicsResultDB { public void createHeuristicResult(HeuristicResult heuristicResult) { int resultId = -1; executeUpdate(() -> { createYarnAppResultStat.clearParameters(); createYarnAppResultStat.setString(1, heuristicResult.getAppId()); createYarnAppResultStat.setString(2, heuristicResult.getHeuristicClass().getName()); createYarnAppResultStat.setString(3, heuristicResult.getHeuristicClass().getSimpleName() + "@" + heuristicResult.getAttemptId()); createYarnAppResultStat.setInt(4, heuristicResult.getSeverity()); createYarnAppResultStat.setInt(5, heuristicResult.getScore()); createYarnAppResultStat.setInt(6, 1); return createYarnAppResultStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_TABLENAME + " table"); try { try (ResultSet rsGenKey = createYarnAppResultStat.getGeneratedKeys()) { while (rsGenKey.next()) { resultId = rsGenKey.getInt(1); } } } catch (SQLException ex) { LOGGER.warn("Error reading YarnAppResult key", ex); return; } if (resultId == -1) { LOGGER.warn("No result id retrieve from insertion into {}", HEURISTIC_RESULT_TABLENAME); } for (int i = 0; i < heuristicResult.getDetailCount(); i++) { int finalResultId = resultId; int finalI = i; executeUpdate(() -> { createYarnAppResultDetailsStat.clearParameters(); HeuristicResult.HeuristicResultDetail detail = heuristicResult.getDetail(finalI); createYarnAppResultDetailsStat.setInt(1, finalResultId); createYarnAppResultDetailsStat.setString(2, detail.name); createYarnAppResultDetailsStat.setString(3, detail.value); createYarnAppResultDetailsStat.setString(4, detail.details); return createYarnAppResultDetailsStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_DETAILS_TABLENAME + " table"); } } HeuristicsResultDB(DbConfiguration dbConfiguration); }
HeuristicsResultDB { public void createHeuristicResult(HeuristicResult heuristicResult) { int resultId = -1; executeUpdate(() -> { createYarnAppResultStat.clearParameters(); createYarnAppResultStat.setString(1, heuristicResult.getAppId()); createYarnAppResultStat.setString(2, heuristicResult.getHeuristicClass().getName()); createYarnAppResultStat.setString(3, heuristicResult.getHeuristicClass().getSimpleName() + "@" + heuristicResult.getAttemptId()); createYarnAppResultStat.setInt(4, heuristicResult.getSeverity()); createYarnAppResultStat.setInt(5, heuristicResult.getScore()); createYarnAppResultStat.setInt(6, 1); return createYarnAppResultStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_TABLENAME + " table"); try { try (ResultSet rsGenKey = createYarnAppResultStat.getGeneratedKeys()) { while (rsGenKey.next()) { resultId = rsGenKey.getInt(1); } } } catch (SQLException ex) { LOGGER.warn("Error reading YarnAppResult key", ex); return; } if (resultId == -1) { LOGGER.warn("No result id retrieve from insertion into {}", HEURISTIC_RESULT_TABLENAME); } for (int i = 0; i < heuristicResult.getDetailCount(); i++) { int finalResultId = resultId; int finalI = i; executeUpdate(() -> { createYarnAppResultDetailsStat.clearParameters(); HeuristicResult.HeuristicResultDetail detail = heuristicResult.getDetail(finalI); createYarnAppResultDetailsStat.setInt(1, finalResultId); createYarnAppResultDetailsStat.setString(2, detail.name); createYarnAppResultDetailsStat.setString(3, detail.value); createYarnAppResultDetailsStat.setString(4, detail.details); return createYarnAppResultDetailsStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_DETAILS_TABLENAME + " table"); } } HeuristicsResultDB(DbConfiguration dbConfiguration); void createHeuristicResult(HeuristicResult heuristicResult); void updateHeuristicHelp(List<Heuristic> heuristics); void executeUpdate(Callable action, String exceptionStr); }
HeuristicsResultDB { public void createHeuristicResult(HeuristicResult heuristicResult) { int resultId = -1; executeUpdate(() -> { createYarnAppResultStat.clearParameters(); createYarnAppResultStat.setString(1, heuristicResult.getAppId()); createYarnAppResultStat.setString(2, heuristicResult.getHeuristicClass().getName()); createYarnAppResultStat.setString(3, heuristicResult.getHeuristicClass().getSimpleName() + "@" + heuristicResult.getAttemptId()); createYarnAppResultStat.setInt(4, heuristicResult.getSeverity()); createYarnAppResultStat.setInt(5, heuristicResult.getScore()); createYarnAppResultStat.setInt(6, 1); return createYarnAppResultStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_TABLENAME + " table"); try { try (ResultSet rsGenKey = createYarnAppResultStat.getGeneratedKeys()) { while (rsGenKey.next()) { resultId = rsGenKey.getInt(1); } } } catch (SQLException ex) { LOGGER.warn("Error reading YarnAppResult key", ex); return; } if (resultId == -1) { LOGGER.warn("No result id retrieve from insertion into {}", HEURISTIC_RESULT_TABLENAME); } for (int i = 0; i < heuristicResult.getDetailCount(); i++) { int finalResultId = resultId; int finalI = i; executeUpdate(() -> { createYarnAppResultDetailsStat.clearParameters(); HeuristicResult.HeuristicResultDetail detail = heuristicResult.getDetail(finalI); createYarnAppResultDetailsStat.setInt(1, finalResultId); createYarnAppResultDetailsStat.setString(2, detail.name); createYarnAppResultDetailsStat.setString(3, detail.value); createYarnAppResultDetailsStat.setString(4, detail.details); return createYarnAppResultDetailsStat.executeUpdate(); }, "Error inserting into " + HEURISTIC_RESULT_DETAILS_TABLENAME + " table"); } } HeuristicsResultDB(DbConfiguration dbConfiguration); void createHeuristicResult(HeuristicResult heuristicResult); void updateHeuristicHelp(List<Heuristic> heuristics); void executeUpdate(Callable action, String exceptionStr);  }