ExecutionRampDao { public void updateExecutableRamp(ExecutableRamp executableRamp) throws ExecutorManagerException { String sqlCommand = ""; try { String ramp = executableRamp.getId(); int cachedNumOfTrail = executableRamp.getCachedCount(ExecutableRamp.CountType.TRAIL); int cachedNumOfSuccess = executableRamp.getCachedCount(ExecutableRamp.CountType.SUCCESS); int cachedNumOfFailure = executableRamp.getCachedCount(ExecutableRamp.CountType.FAILURE); int cachedNumOfIgnored = executableRamp.getCachedCount(ExecutableRamp.CountType.IGNORED); int rampStage = executableRamp.getStage(); long endTime = executableRamp.getEndTime(); boolean isPaused = executableRamp.isPaused(); long lastUpdatedTime = executableRamp.getLastUpdatedTime(); StringBuilder sqlCommandStringBuilder = new StringBuilder(); sqlCommandStringBuilder.append("UPDATE ramp SET "); sqlCommandStringBuilder.append(String.format("numOfTrail = numOfTrail + %s, ", cachedNumOfTrail)); sqlCommandStringBuilder.append(String.format("numOfFailure = numOfFailure + %s, ", cachedNumOfFailure)); sqlCommandStringBuilder.append(String.format("numOfSuccess = numOfSuccess + %s, ", cachedNumOfSuccess)); sqlCommandStringBuilder.append(String.format("numOfIgnored = numOfIgnored + %s, ", cachedNumOfIgnored)); sqlCommandStringBuilder.append(String.format("rampStage = CASE WHEN rampStage > %s THEN rampStage ELSE %s END, ", rampStage, rampStage)); sqlCommandStringBuilder.append(String.format("endTime = CASE WHEN endTime > %s THEN endTime ELSE %s END, ", endTime, endTime)); sqlCommandStringBuilder.append(String.format("lastUpdatedTime = CASE WHEN lastUpdatedTime > %s THEN lastUpdatedTime ELSE %s END", lastUpdatedTime, lastUpdatedTime)); if (isPaused) { sqlCommandStringBuilder.append(", isPaused = true"); } sqlCommandStringBuilder.append(String.format(" WHERE rampId = '%s'", ramp)); sqlCommand = sqlCommandStringBuilder.toString(); int rows = this.dbOperator.update(sqlCommand); if (rows <= 0) { throw new ExecutorManagerException( String.format("No record(s) is updated into ramp, by command [%s]", sqlCommand) ); } } catch (final SQLException e) { throw new ExecutorManagerException( String.format("Error on update into ramp, by command [%s]", sqlCommand), e ); } } @Inject  ExecutionRampDao(final DatabaseOperator dbOperator); ExecutableRampMap fetchExecutableRampMap(); ExecutableRampItemsMap fetchExecutableRampItemsMap(); ExecutableRampDependencyMap fetchExecutableRampDependencyMap(); ExecutableRampExceptionalFlowItemsMap fetchExecutableRampExceptionalFlowItemsMap(); ExecutableRampExceptionalJobItemsMap fetchExecutableRampExceptionalJobItemsMap(); void insertAction(final String tableName, Map<String, Object> actionData); void deleteAction(final String tableName, Map<String, Object> constraints); void updateAction(final String tableName, Map<String, Object> actionData, Map<String, Object> constraints); Map<String, String> doRampActions(List<Map<String, Object>> rampActionsMap); void updateExecutableRamp(ExecutableRamp executableRamp); void updateExecutedRampFlows(final String ramp, ExecutableRampExceptionalItems executableRampExceptionalItems);  }
@Test public void testUpdateExecutableRamp() throws ExecutorManagerException { Map<String, Object> data = ImmutableMap.<String, Object>builder() .put("rampId", "dali") .put("isActive", 1) .put("rampPolicy", "SimpleAutoRampPolicy") .put("startTime", 0L) .put("maxFailureToPause", 5) .put("maxFailureToRampDown", 10) .build(); this.executionRampDao.insertAction("ramp", data); final ExecutableRampMap record = this.executionRampDao.fetchExecutableRampMap(); assertThat(record.get("dali").isActive()).isTrue(); assertThat(record.get("dali").getPolicy()).isEqualTo("SimpleAutoRampPolicy"); assertThat(record.get("dali").getMaxFailureToRampDown()).isEqualTo(10); assertThat(record.get("dali").getMaxFailureToPause()).isEqualTo(5); assertThat(record.get("dali").isPercentageScaleForMaxFailure()).isFalse(); assertThat(record.get("dali").getStage()).isEqualTo(0); assertThat(record.get("dali").getStartTime()).isEqualTo(0); assertThat(record.get("dali").getEndTime()).isEqualTo(0); assertThat(record.get("dali").getLastUpdatedTime()).isEqualTo(0); assertThat(record.get("dali").getCount(ExecutableRamp.CountType.FAILURE)).isEqualTo(0); assertThat(record.get("dali").getCount(ExecutableRamp.CountType.SUCCESS)).isEqualTo(0); assertThat(record.get("dali").getCount(ExecutableRamp.CountType.TRAIL)).isEqualTo(0); assertThat(record.get("dali").isPaused()).isFalse(); record.get("dali").cacheResult(ExecutableRamp.Action.FAILED); record.get("dali").cacheResult(ExecutableRamp.Action.SUCCEEDED); record.get("dali").cacheResult(ExecutableRamp.Action.SUCCEEDED); record.get("dali").cacheResult(ExecutableRamp.Action.SUCCEEDED); record.get("dali").cacheResult(ExecutableRamp.Action.IGNORED); this.executionRampDao.updateExecutableRamp(record.get("dali")); final ExecutableRampMap updatedRecord = this.executionRampDao.fetchExecutableRampMap(); assertThat(updatedRecord.get("dali").getCount(ExecutableRamp.CountType.FAILURE)).isEqualTo(1); assertThat(updatedRecord.get("dali").getCount(ExecutableRamp.CountType.SUCCESS)).isEqualTo(3); assertThat(updatedRecord.get("dali").getCount(ExecutableRamp.CountType.TRAIL)).isEqualTo(5); assertThat(updatedRecord.get("dali").getCount(ExecutableRamp.CountType.IGNORED)).isEqualTo(1); assertThat(updatedRecord.get("dali").getLastUpdatedTime()).isGreaterThan(0); }