From 8bd21ac227b8dfa12bc2dc213a639d856a4d6db8 Mon Sep 17 00:00:00 2001 From: Mikko Tiihonen Date: Fri, 22 Nov 2019 10:39:23 +0200 Subject: [PATCH] Refactor workflow and workflow action id from int to long --- .../nflow/engine/internal/dao/ArchiveDao.java | 12 +- .../io/nflow/engine/internal/dao/DaoUtil.java | 5 + .../internal/dao/WorkflowInstanceDao.java | 136 ++++++++-------- .../internal/executor/InstanceInfo.java | 2 +- .../internal/executor/WorkflowDispatcher.java | 6 +- .../executor/WorkflowStateProcessor.java | 8 +- .../WorkflowStateProcessorFactory.java | 4 +- .../internal/workflow/StateExecutionImpl.java | 4 +- .../nflow/engine/service/ArchiveService.java | 2 +- .../service/WorkflowInstanceService.java | 12 +- .../workflow/definition/StateExecution.java | 4 +- .../instance/QueryWorkflowInstances.java | 18 +-- .../workflow/instance/WorkflowInstance.java | 28 ++-- .../instance/WorkflowInstanceAction.java | 12 +- .../engine/internal/dao/ArchiveDaoTest.java | 102 ++++++------ .../internal/dao/StatisticsDaoTest.java | 6 +- .../internal/dao/WorkflowInstanceDaoTest.java | 149 +++++++++--------- .../internal/executor/BaseNflowTest.java | 4 +- .../executor/WorkflowDispatcherTest.java | 20 +-- .../WorkflowStateProcessorFactoryTest.java | 4 +- .../executor/WorkflowStateProcessorTest.java | 10 +- .../workflow/StateExecutionImplTest.java | 14 +- .../engine/service/ArchiveServiceTest.java | 4 +- .../service/WorkflowInstanceServiceTest.java | 14 +- .../WorkflowLogContextListenerTest.java | 4 +- 25 files changed, 291 insertions(+), 293 deletions(-) diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ArchiveDao.java b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ArchiveDao.java index 377e63373..800904a04 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ArchiveDao.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/ArchiveDao.java @@ -40,7 +40,7 @@ public void ensureValidArchiveTablesExist() { tableMetadataChecker.ensureCopyingPossible("nflow_workflow_state", "nflow_archive_workflow_state"); } - public List listArchivableWorkflows(DateTime before, int maxRows) { + public List listArchivableWorkflows(DateTime before, int maxRows) { return jdbc.query( "select w.id id from nflow_workflow w, " + "(" + sqlVariants.limit( @@ -58,7 +58,7 @@ public List listArchivableWorkflows(DateTime before, int maxRows) { } @Transactional - public int archiveWorkflows(Collection workflowIds) { + public int archiveWorkflows(Collection workflowIds) { String workflowIdParams = params(workflowIds); int archivedWorkflows = archiveWorkflowTable(workflowIdParams); @@ -99,14 +99,14 @@ private String columnsFromMetadata(String tableName) { return join(columnNames, ","); } - private String params(Collection workflowIds) { + private String params(Collection workflowIds) { return "(" + join(workflowIds, ",") + ")"; } - static class ArchivableWorkflowsRowMapper implements RowMapper { + static class ArchivableWorkflowsRowMapper implements RowMapper { @Override - public Integer mapRow(ResultSet rs, int rowNum) throws SQLException { - return rs.getInt("id"); + public Long mapRow(ResultSet rs, int rowNum) throws SQLException { + return rs.getLong("id"); } } } diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/DaoUtil.java b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/DaoUtil.java index 32a318dc0..05b7eeb39 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/DaoUtil.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/DaoUtil.java @@ -39,6 +39,11 @@ public static Integer getInt(ResultSet rs, String columnLabel) throws SQLExcepti return rs.wasNull() ? null : value; } + public static Long getLong(ResultSet rs, String columnLabel) throws SQLException { + long value = rs.getLong(columnLabel); + return rs.wasNull() ? null : value; + } + public static final class ColumnNamesExtractor implements ResultSetExtractor> { static final ColumnNamesExtractor columnNamesExtractor = new ColumnNamesExtractor(); diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/WorkflowInstanceDao.java b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/WorkflowInstanceDao.java index 3854dd3a2..f7eeb0446 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/dao/WorkflowInstanceDao.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/dao/WorkflowInstanceDao.java @@ -1,8 +1,6 @@ package io.nflow.engine.internal.dao; -import static io.nflow.engine.internal.dao.DaoUtil.firstColumnLengthExtractor; -import static io.nflow.engine.internal.dao.DaoUtil.getInt; -import static io.nflow.engine.internal.dao.DaoUtil.toTimestamp; +import static io.nflow.engine.internal.dao.DaoUtil.*; import static io.nflow.engine.workflow.instance.WorkflowInstance.WorkflowInstanceStatus.created; import static io.nflow.engine.workflow.instance.WorkflowInstance.WorkflowInstanceStatus.executing; import static io.nflow.engine.workflow.instance.WorkflowInstance.WorkflowInstanceStatus.inProgress; @@ -85,7 +83,7 @@ public class WorkflowInstanceDao { private static final Logger logger = getLogger(WorkflowInstanceDao.class); - static final Map> EMPTY_ACTION_STATE_MAP = Collections.> emptyMap(); + static final Map> EMPTY_ACTION_STATE_MAP = Collections.emptyMap(); final JdbcTemplate jdbc; private final NamedParameterJdbcTemplate namedJdbc; @@ -149,8 +147,8 @@ int getActionStateTextLength() { return actionStateTextLength; } - public int insertWorkflowInstance(WorkflowInstance instance) { - int id; + public long insertWorkflowInstance(WorkflowInstance instance) { + long id; if (sqlVariants.hasUpdateableCTE()) { id = insertWorkflowInstanceWithCte(instance); } else { @@ -162,7 +160,7 @@ public int insertWorkflowInstance(WorkflowInstance instance) { return id; } - private int insertWorkflowInstanceWithCte(WorkflowInstance instance) { + private long insertWorkflowInstanceWithCte(WorkflowInstance instance) { try { StringBuilder sqlb = new StringBuilder(256); sqlb.append("with wf as (").append(insertWorkflowInstanceSql()).append(" returning id)"); @@ -179,7 +177,7 @@ private int insertWorkflowInstanceWithCte(WorkflowInstance instance) { args[pos++] = variable.getValue(); } sqlb.append(" select wf.id from wf"); - return jdbc.queryForObject(sqlb.toString(), Integer.class, args); + return jdbc.queryForObject(sqlb.toString(), Long.class, args); } catch (DuplicateKeyException e) { logger.warn("Failed to insert workflow instance", e); return -1; @@ -202,7 +200,7 @@ String insertWorkflowInstanceStateSql() { @SuppressFBWarnings(value = { "OBL_UNSATISFIED_OBLIGATION_EXCEPTION_EDGE", "SQL_PREPARED_STATEMENT_GENERATED_FROM_NONCONSTANT_STRING" }, justification = "findbugs does not trust jdbctemplate, sql string is practically constant") - private int insertWorkflowInstanceWithTransaction(final WorkflowInstance instance) { + private long insertWorkflowInstanceWithTransaction(final WorkflowInstance instance) { return transaction.execute(status -> { KeyHolder keyHolder = new GeneratedKeyHolder(); try { @@ -229,15 +227,15 @@ private int insertWorkflowInstanceWithTransaction(final WorkflowInstance instanc }, keyHolder); } catch (DuplicateKeyException e) { logger.warn("Failed to insert workflow instance", e); - return -1; + return -1L; } - int id = keyHolder.getKey().intValue(); + long id = keyHolder.getKey().longValue(); insertVariables(id, 0, instance.stateVariables); return id; }); } - void insertVariables(final int id, final int actionId, Map changedStateVariables) { + void insertVariables(final long id, final long actionId, Map changedStateVariables) { if (changedStateVariables.isEmpty()) { return; } @@ -248,7 +246,7 @@ void insertVariables(final int id, final int actionId, Map chang } } - private void insertVariablesWithMultipleUpdates(final int id, final int actionId, Map changedStateVariables) { + private void insertVariablesWithMultipleUpdates(final long id, final long actionId, Map changedStateVariables) { for (Entry entry : changedStateVariables.entrySet()) { int updated = jdbc.update(insertWorkflowInstanceStateSql() + " values (?,?,?,?)", id, actionId, entry.getKey(), entry.getValue()); @@ -258,7 +256,7 @@ private void insertVariablesWithMultipleUpdates(final int id, final int actionId } } - private void insertVariablesWithBatchUpdate(final int id, final int actionId, Map changedStateVariables) { + private void insertVariablesWithBatchUpdate(final long id, final long actionId, Map changedStateVariables) { final Iterator> variables = changedStateVariables.entrySet().iterator(); int[] updateStatus = jdbc.batchUpdate(insertWorkflowInstanceStateSql() + " values (?,?,?,?)", new AbstractInterruptibleBatchPreparedStatementSetter() { @@ -268,8 +266,8 @@ protected boolean setValuesIfAvailable(PreparedStatement ps, int i) throws SQLEx return false; } Entry variable = variables.next(); - ps.setInt(1, id); - ps.setInt(2, actionId); + ps.setLong(1, id); + ps.setLong(2, actionId); ps.setString(3, variable.getKey()); ps.setString(4, variable.getValue()); return true; @@ -332,10 +330,10 @@ private void updateWorkflowInstanceWithTransaction(final WorkflowInstance instan @Override protected void doInTransactionWithoutResult(TransactionStatus status) { updateWorkflowInstance(instance); - int parentActionId = insertWorkflowInstanceAction(action); + long parentActionId = insertWorkflowInstanceAction(action); insertVariables(action.workflowInstanceId, parentActionId, changedStateVariables); for (WorkflowInstance childTemplate : childWorkflows) { - Integer rootWorkflowId = instance.rootWorkflowId == null ? instance.id : instance.rootWorkflowId; + Long rootWorkflowId = instance.rootWorkflowId == null ? instance.id : instance.rootWorkflowId; WorkflowInstance childWorkflow = new WorkflowInstance.Builder(childTemplate).setRootWorkflowId(rootWorkflowId) .setParentWorkflowId(instance.id).setParentActionId(parentActionId).build(); insertWorkflowInstance(childWorkflow); @@ -364,14 +362,14 @@ private List getRecoverableInstances() { @Override public InstanceInfo mapRow(ResultSet rs, int rowNum) throws SQLException { InstanceInfo instance = new InstanceInfo(); - instance.id = rs.getInt("id"); + instance.id = rs.getLong("id"); instance.state = rs.getString("state"); return instance; } }); } - private void recoverWorkflowInstance(final int instanceId, final WorkflowInstanceAction action) { + private void recoverWorkflowInstance(final long instanceId, final WorkflowInstanceAction action) { transaction.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus status) { @@ -411,7 +409,7 @@ private void updateWorkflowInstanceWithCTE(WorkflowInstance instance, final Work args[pos++] = variable.getValue(); } sqlb.append(" select act.id from act"); - jdbc.queryForObject(sqlb.toString(), Integer.class, args); + jdbc.queryForObject(sqlb.toString(), Long.class, args); } String insertWorkflowActionSql() { @@ -451,7 +449,7 @@ public boolean updateNotRunningWorkflowInstance(WorkflowInstance instance) { } @Transactional - public boolean wakeUpWorkflowExternally(int workflowInstanceId, List expectedStates) { + public boolean wakeUpWorkflowExternally(long workflowInstanceId, List expectedStates) { StringBuilder sql = new StringBuilder("update nflow_workflow set next_activation = (case when executor_id is null then ") .append("case when ").append(sqlVariants.dateLtEqDiff("next_activation", "current_timestamp")) .append(" then next_activation else current_timestamp end else next_activation end), ") @@ -482,7 +480,7 @@ private boolean addExpectedStatesToQueryAndUpdate(StringBuilder sql, long workfl return jdbc.update(sql.toString(), args) == 1; } - public WorkflowInstance getWorkflowInstance(int id, Set includes, Long maxActions) { + public WorkflowInstance getWorkflowInstance(long id, Set includes, Long maxActions) { String sql = "select * from nflow_workflow where id = ?"; WorkflowInstance instance = jdbc.queryForObject(sql, new WorkflowInstanceRowMapper(), id).build(); if (includes.contains(WorkflowInstanceInclude.CURRENT_STATE_VARIABLES)) { @@ -510,7 +508,7 @@ public void processRow(ResultSet rs) throws SQLException { instance.originalStateVariables.putAll(instance.stateVariables); } - public List pollNextWorkflowInstanceIds(final int batchSize) { + public List pollNextWorkflowInstanceIds(final int batchSize) { if (sqlVariants.hasUpdateReturning()) { return pollNextWorkflowInstanceIdsWithUpdateReturning(batchSize); } @@ -528,25 +526,25 @@ String whereConditionForInstanceUpdate() { + " and " + executorInfo.getExecutorGroupCondition() + " order by next_activation asc"; } - private List pollNextWorkflowInstanceIdsWithUpdateReturning(int batchSize) { + private List pollNextWorkflowInstanceIdsWithUpdateReturning(int batchSize) { String sql = updateInstanceForExecutionQuery() + " where id in (" + sqlVariants.limit("select id from nflow_workflow " + whereConditionForInstanceUpdate(), batchSize) + ") and executor_id is null returning id"; - return jdbc.queryForList(sql, Integer.class); + return jdbc.queryForList(sql, Long.class); } - private List pollNextWorkflowInstanceIdsWithTransaction(final int batchSize) { - return transaction.execute(new TransactionCallback>() { + private List pollNextWorkflowInstanceIdsWithTransaction(final int batchSize) { + return transaction.execute(new TransactionCallback>() { @Override - public List doInTransaction(TransactionStatus transactionStatus) { + public List doInTransaction(TransactionStatus transactionStatus) { String sql = sqlVariants.limit("select id, modified from nflow_workflow " + whereConditionForInstanceUpdate(), batchSize); List instances = jdbc.query(sql, - (rs, rowNum) -> new OptimisticLockKey(rs.getInt("id"), sqlVariants.getTimestamp(rs, "modified"))); + (rs, rowNum) -> new OptimisticLockKey(rs.getLong("id"), sqlVariants.getTimestamp(rs, "modified"))); if (instances.isEmpty()) { return emptyList(); } sort(instances); - List ids = new ArrayList<>(instances.size()); + List ids = new ArrayList<>(instances.size()); if (useBatchUpdate()) { updateNextWorkflowInstancesWithBatchUpdate(instances, ids); } else { @@ -555,7 +553,7 @@ public List doInTransaction(TransactionStatus transactionStatus) { return ids; } - private void updateNextWorkflowInstancesWithMultipleUpdates(List instances, List ids) { + private void updateNextWorkflowInstancesWithMultipleUpdates(List instances, List ids) { boolean raceConditionDetected = false; for (OptimisticLockKey instance : instances) { int updated = jdbc.update(updateInstanceForExecutionQuery() + " where id = ? and modified = ? and executor_id is null", @@ -572,7 +570,7 @@ private void updateNextWorkflowInstancesWithMultipleUpdates(List instances, List ids) { + private void updateNextWorkflowInstancesWithBatchUpdate(List instances, List ids) { List batchArgs = new ArrayList<>(instances.size()); for (OptimisticLockKey instance : instances) { batchArgs.add(new Object[] { instance.id, sqlVariants.tuneTimestampForDb(instance.modified) }); @@ -580,7 +578,7 @@ private void updateNextWorkflowInstancesWithBatchUpdate(List } int[] updateStatuses = jdbc .batchUpdate(updateInstanceForExecutionQuery() + " where id = ? and modified = ? and executor_id is null", batchArgs); - Iterator idIt = ids.iterator(); + Iterator idIt = ids.iterator(); for (int status : updateStatuses) { idIt.next(); if (status == 0) { @@ -601,10 +599,10 @@ private void updateNextWorkflowInstancesWithBatchUpdate(List } private static class OptimisticLockKey extends ModelObject implements Comparable { - public final int id; + public final long id; public final Object modified; - public OptimisticLockKey(int id, Object modified) { + public OptimisticLockKey(long id, Object modified) { this.id = id; this.modified = modified; } @@ -612,7 +610,7 @@ public OptimisticLockKey(int id, Object modified) { @Override @SuppressFBWarnings(value = "EQ_COMPARETO_USE_OBJECT_EQUALS", justification = "This class has a natural ordering that is inconsistent with equals") public int compareTo(OptimisticLockKey other) { - return this.id - other.id; + return Long.compare(this.id, other.id); } } @@ -680,9 +678,9 @@ private void fillChildWorkflowIds(final WorkflowInstance instance) { jdbc.query("select parent_action_id, id from nflow_workflow where parent_workflow_id = ?", new RowCallbackHandler() { @Override public void processRow(ResultSet rs) throws SQLException { - int parentActionId = rs.getInt(1); - int childWorkflowInstanceId = rs.getInt(2); - List children = instance.childWorkflows.computeIfAbsent(parentActionId, k -> new ArrayList<>()); + long parentActionId = rs.getLong(1); + long childWorkflowInstanceId = rs.getLong(2); + List children = instance.childWorkflows.computeIfAbsent(parentActionId, k -> new ArrayList<>()); children.add(childWorkflowInstanceId); } }, instance.id); @@ -696,7 +694,7 @@ private long getMaxResults(Long maxResults) { } private void fillActions(WorkflowInstance instance, boolean includeStateVariables, Long maxActions) { - Map> actionStates = includeStateVariables ? fetchActionStateVariables(instance) + Map> actionStates = includeStateVariables ? fetchActionStateVariables(instance) : EMPTY_ACTION_STATE_MAP; String sql = sqlVariants.limit( "select nflow_workflow_action.* from nflow_workflow_action where workflow_id = ? order by id desc", @@ -711,19 +709,19 @@ private long getMaxActions(Long maxActions) { return min(maxActions.longValue(), workflowInstanceQueryMaxActions); } - private Map> fetchActionStateVariables(WorkflowInstance instance) { + private Map> fetchActionStateVariables(WorkflowInstance instance) { return jdbc.query("select * from nflow_workflow_state where workflow_id = ? order by action_id, state_key asc", new WorkflowActionStateRowMapper(), instance.id); } @Transactional(propagation = MANDATORY) - public int insertWorkflowInstanceAction(final WorkflowInstance instance, final WorkflowInstanceAction action) { - int actionId = insertWorkflowInstanceAction(action); + public long insertWorkflowInstanceAction(final WorkflowInstance instance, final WorkflowInstanceAction action) { + long actionId = insertWorkflowInstanceAction(action); insertVariables(action.workflowInstanceId, actionId, instance.getChangedStateVariables()); return actionId; } - public int insertWorkflowInstanceAction(final WorkflowInstanceAction action) { + public long insertWorkflowInstanceAction(final WorkflowInstanceAction action) { KeyHolder keyHolder = new GeneratedKeyHolder(); jdbc.update(new PreparedStatementCreator() { @Override @@ -733,7 +731,7 @@ public PreparedStatement createPreparedStatement(Connection con) throws SQLExcep PreparedStatement p = con.prepareStatement( insertWorkflowActionSql() + " values (?, ?, " + sqlVariants.actionType() + ", ?, ?, ?, ?, ?)", new String[] { "id" }); int field = 1; - p.setInt(field++, action.workflowInstanceId); + p.setLong(field++, action.workflowInstanceId); p.setInt(field++, executorInfo.getExecutorId()); p.setString(field++, action.type.name()); p.setString(field++, action.state); @@ -744,10 +742,10 @@ public PreparedStatement createPreparedStatement(Connection con) throws SQLExcep return p; } }, keyHolder); - return keyHolder.getKey().intValue(); + return keyHolder.getKey().longValue(); } - public String getWorkflowInstanceState(int workflowInstanceId) { + public String getWorkflowInstanceState(long workflowInstanceId) { return jdbc.queryForObject("select state from nflow_workflow where id = ?", String.class, workflowInstanceId); } @@ -755,11 +753,11 @@ class WorkflowInstanceRowMapper implements RowMapper { @Override public WorkflowInstance.Builder mapRow(ResultSet rs, int rowNum) throws SQLException { return workflowInstanceFactory.newWorkflowInstanceBuilder() // - .setId(rs.getInt("id")) // + .setId(rs.getLong("id")) // .setExecutorId(getInt(rs, "executor_id")) // - .setRootWorkflowId(getInt(rs, "root_workflow_id")) // - .setParentWorkflowId(getInt(rs, "parent_workflow_id")) // - .setParentActionId(getInt(rs, "parent_action_id")) // + .setRootWorkflowId(getLong(rs, "root_workflow_id")) // + .setParentWorkflowId(getLong(rs, "parent_workflow_id")) // + .setParentActionId(getLong(rs, "parent_action_id")) // .setStatus(WorkflowInstanceStatus.valueOf(rs.getString("status"))) // .setType(rs.getString("type")) // .setBusinessKey(rs.getString("business_key")) // @@ -779,20 +777,20 @@ public WorkflowInstance.Builder mapRow(ResultSet rs, int rowNum) throws SQLExcep static class WorkflowInstanceActionRowMapper implements RowMapper { private final SQLVariants sqlVariants; - private final Map> actionStates; + private final Map> actionStates; - public WorkflowInstanceActionRowMapper(SQLVariants sqlVariants, Map> actionStates) { + public WorkflowInstanceActionRowMapper(SQLVariants sqlVariants, Map> actionStates) { this.sqlVariants = sqlVariants; this.actionStates = actionStates; } @Override public WorkflowInstanceAction mapRow(ResultSet rs, int rowNum) throws SQLException { - int actionId = rs.getInt("id"); + long actionId = rs.getLong("id"); Map actionState = actionStates.getOrDefault(actionId, emptyMap()); return new WorkflowInstanceAction.Builder() // .setId(actionId) // - .setWorkflowInstanceId(rs.getInt("workflow_id")) // + .setWorkflowInstanceId(rs.getLong("workflow_id")) // .setExecutorId(rs.getInt("executor_id")) // .setType(WorkflowActionType.valueOf(rs.getString("type"))) // .setState(rs.getString("state")) // @@ -804,13 +802,13 @@ public WorkflowInstanceAction mapRow(ResultSet rs, int rowNum) throws SQLExcepti } } - static class WorkflowActionStateRowMapper implements ResultSetExtractor>> { - private final Map> actionStates = new LinkedHashMap<>(); + static class WorkflowActionStateRowMapper implements ResultSetExtractor>> { + private final Map> actionStates = new LinkedHashMap<>(); @Override - public Map> extractData(ResultSet rs) throws SQLException { + public Map> extractData(ResultSet rs) throws SQLException { while (rs.next()) { - int actionId = rs.getInt("action_id"); + long actionId = rs.getLong("action_id"); String stateKey = rs.getString("state_key"); String stateValue = rs.getString("state_value"); if (!actionStates.containsKey(actionId)) { @@ -823,13 +821,13 @@ public Map> extractData(ResultSet rs) throws SQLExc } } - public Optional getSignal(Integer workflowInstanceId) { + public Optional getSignal(long workflowInstanceId) { return ofNullable( jdbc.queryForObject("select workflow_signal from nflow_workflow where id = ?", Integer.class, workflowInstanceId)); } @Transactional - public boolean setSignal(Integer workflowInstanceId, Optional signal, String reason, WorkflowActionType actionType) { + public boolean setSignal(long workflowInstanceId, Optional signal, String reason, WorkflowActionType actionType) { boolean updated = jdbc.update("update nflow_workflow set workflow_signal = ? where id = ?", signal.orElse(null), workflowInstanceId) > 0; if (updated) { @@ -846,24 +844,24 @@ public boolean setSignal(Integer workflowInstanceId, Optional signal, S return updated; } - public String getWorkflowInstanceType(Integer workflowInstanceId) { + public String getWorkflowInstanceType(long workflowInstanceId) { return jdbc.queryForObject("select type from nflow_workflow where id = ?", String.class, workflowInstanceId); } @Transactional - public int deleteWorkflowInstanceHistory(Integer workflowInstanceId, Integer historyDeletableAfterHours) { + public int deleteWorkflowInstanceHistory(long workflowInstanceId, Integer historyDeletableAfterHours) { MapSqlParameterSource params = new MapSqlParameterSource(); params.addValue("workflowId", workflowInstanceId); params.addValue("deleteUpToTime", sqlVariants.toTimestampObject(now().minusHours(historyDeletableAfterHours))); - Integer maxActionId = namedJdbc + Long maxActionId = namedJdbc .queryForObject("select max(id) from nflow_workflow_action where workflow_id = :workflowId and " - + sqlVariants.dateLtEqDiff("execution_end", ":deleteUpToTime"), params, Integer.class); + + sqlVariants.dateLtEqDiff("execution_end", ":deleteUpToTime"), params, Long.class); int deletedActions = 0; if (maxActionId != null) { params.addValue("maxActionId", maxActionId); - List referredActionIds = namedJdbc.queryForList( + List referredActionIds = namedJdbc.queryForList( "select distinct(max(action_id)) from nflow_workflow_state where workflow_id = :workflowId group by state_key", params, - Integer.class); + Long.class); if (referredActionIds.isEmpty()) { namedJdbc.update("delete from nflow_workflow_state where workflow_id = :workflowId and action_id <= :maxActionId", params); @@ -874,7 +872,7 @@ public int deleteWorkflowInstanceHistory(Integer workflowInstanceId, Integer his params); } referredActionIds.addAll(namedJdbc.queryForList( - "select distinct parent_action_id from nflow_workflow where parent_workflow_id = :workflowId", params, Integer.class)); + "select distinct parent_action_id from nflow_workflow where parent_workflow_id = :workflowId", params, Long.class)); if (referredActionIds.isEmpty()) { deletedActions = namedJdbc .update("delete from nflow_workflow_action where workflow_id = :workflowId and id <= :maxActionId", params); diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/InstanceInfo.java b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/InstanceInfo.java index a8eda7ec2..df48bf449 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/InstanceInfo.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/InstanceInfo.java @@ -1,6 +1,6 @@ package io.nflow.engine.internal.executor; public class InstanceInfo { - public int id; + public long id; public String state; } \ No newline at end of file diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowDispatcher.java b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowDispatcher.java index fc187c78c..10cbb1803 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowDispatcher.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowDispatcher.java @@ -141,19 +141,19 @@ private void shutdownPool() { } } - private void dispatch(List nextInstanceIds) { + private void dispatch(List nextInstanceIds) { if (nextInstanceIds.isEmpty()) { logger.debug("Found no workflow instances, sleeping."); sleep(false); return; } logger.debug("Found {} workflow instances, dispatching executors.", nextInstanceIds.size()); - for (Integer instanceId : nextInstanceIds) { + for (Long instanceId : nextInstanceIds) { executor.execute(stateProcessorFactory.createProcessor(instanceId)); } } - private List getNextInstanceIds() { + private List getNextInstanceIds() { int nextBatchSize = executor.getQueueRemainingCapacity(); logger.debug("Polling next {} workflow instances.", nextBatchSize); return workflowInstances.pollNextWorkflowInstanceIds(nextBatchSize); diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessor.java b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessor.java index 41e1aa095..2fdd7c27c 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessor.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessor.java @@ -62,7 +62,7 @@ class WorkflowStateProcessor implements Runnable { private static final PeriodicLogger threadStuckLogger = new PeriodicLogger(logger, 60); private static final String MDC_KEY = "workflowInstanceId"; - private final int instanceId; + private final long instanceId; private final WorkflowDefinitionService workflowDefinitions; private final WorkflowInstanceService workflowInstances; private final WorkflowInstancePreProcessor workflowInstancePreProcessor; @@ -75,14 +75,14 @@ class WorkflowStateProcessor implements Runnable { private final int stateProcessingRetryDelay; private final int stateSaveRetryDelay; private boolean internalRetryEnabled = true; - private final Map processingInstances; + private final Map processingInstances; private long startTimeSeconds; private Thread thread; - WorkflowStateProcessor(int instanceId, ObjectStringMapper objectMapper, WorkflowDefinitionService workflowDefinitions, + WorkflowStateProcessor(long instanceId, ObjectStringMapper objectMapper, WorkflowDefinitionService workflowDefinitions, WorkflowInstanceService workflowInstances, WorkflowInstanceDao workflowInstanceDao, WorkflowInstancePreProcessor workflowInstancePreProcessor, Environment env, - Map processingInstances, WorkflowExecutorListener... executorListeners) { + Map processingInstances, WorkflowExecutorListener... executorListeners) { this.instanceId = instanceId; this.objectMapper = objectMapper; this.workflowDefinitions = workflowDefinitions; diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactory.java b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactory.java index d20c19ffd..11e3013ae 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactory.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactory.java @@ -28,7 +28,7 @@ public class WorkflowStateProcessorFactory { private final Environment env; @Autowired(required = false) protected WorkflowExecutorListener[] listeners = new WorkflowExecutorListener[0]; - final Map processingInstances = new ConcurrentHashMap<>(); + final Map processingInstances = new ConcurrentHashMap<>(); private final int stuckThreadThresholdSeconds; @Inject @@ -44,7 +44,7 @@ public WorkflowStateProcessorFactory(WorkflowDefinitionService workflowDefinitio this.env = env; } - public WorkflowStateProcessor createProcessor(int instanceId) { + public WorkflowStateProcessor createProcessor(long instanceId) { return new WorkflowStateProcessor(instanceId, objectMapper, workflowDefinitions, workflowInstances, workflowInstanceDao, workflowInstancePreProcessor, env, processingInstances, listeners); } diff --git a/nflow-engine/src/main/java/io/nflow/engine/internal/workflow/StateExecutionImpl.java b/nflow-engine/src/main/java/io/nflow/engine/internal/workflow/StateExecutionImpl.java index e3bec8d10..d1bb88a58 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/internal/workflow/StateExecutionImpl.java +++ b/nflow-engine/src/main/java/io/nflow/engine/internal/workflow/StateExecutionImpl.java @@ -72,7 +72,7 @@ public String getCurrentStateName() { } @Override - public int getWorkflowInstanceId() { + public long getWorkflowInstanceId() { return instance.id; } @@ -254,7 +254,7 @@ public void setSignal(Optional signal, String reason) { } @Override - public Optional getParentId() { + public Optional getParentId() { return Optional.ofNullable(instance.parentWorkflowId); } diff --git a/nflow-engine/src/main/java/io/nflow/engine/service/ArchiveService.java b/nflow-engine/src/main/java/io/nflow/engine/service/ArchiveService.java index 63e6c5c1d..02ecf13c0 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/service/ArchiveService.java +++ b/nflow-engine/src/main/java/io/nflow/engine/service/ArchiveService.java @@ -49,7 +49,7 @@ public int archiveWorkflows(DateTime olderThan, int batchSize) { log.info("Archiving starting. Archiving passive workflows older than {}, in batches of {}.", olderThan, batchSize); StopWatch stopWatch = new StopWatch(); stopWatch.start(); - List workflowIds; + List workflowIds; PeriodicLogger periodicLogger = new PeriodicLogger(log, 60); int archivedWorkflowsTotal = 0; do { diff --git a/nflow-engine/src/main/java/io/nflow/engine/service/WorkflowInstanceService.java b/nflow-engine/src/main/java/io/nflow/engine/service/WorkflowInstanceService.java index 225b23eec..2b9c1caab 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/service/WorkflowInstanceService.java +++ b/nflow-engine/src/main/java/io/nflow/engine/service/WorkflowInstanceService.java @@ -51,7 +51,7 @@ public WorkflowInstanceService(WorkflowInstanceDao workflowInstanceDao, Workflow * @param maxActions Maximum number of actions to be loaded. * @return The workflow instance, or null if not found. */ - public WorkflowInstance getWorkflowInstance(int id, Set includes, Long maxActions) { + public WorkflowInstance getWorkflowInstance(long id, Set includes, Long maxActions) { return workflowInstanceDao.getWorkflowInstance(id, includes, maxActions); } @@ -63,10 +63,10 @@ public WorkflowInstance getWorkflowInstance(int id, Set * @return The id of the inserted or existing workflow instance. */ @SuppressFBWarnings(value = "BC_UNCONFIRMED_CAST_OF_RETURN_VALUE", justification = "getInitialState().toString() has no cast") - public int insertWorkflowInstance(WorkflowInstance instance) { + public long insertWorkflowInstance(WorkflowInstance instance) { Assert.notNull(workflowInstancePreProcessor, "workflowInstancePreProcessor can not be null"); WorkflowInstance processedInstance = workflowInstancePreProcessor.process(instance); - int id = workflowInstanceDao.insertWorkflowInstance(processedInstance); + long id = workflowInstanceDao.insertWorkflowInstance(processedInstance); if (id == -1 && !isEmpty(instance.externalId)) { QueryWorkflowInstances query = new QueryWorkflowInstances.Builder().addTypes(instance.type).setExternalId(instance.externalId).build(); id = workflowInstanceDao.queryWorkflowInstances(query).get(0).id; @@ -131,7 +131,7 @@ public Collection listWorkflowInstances(QueryWorkflowInstances * @param workflowInstanceId Workflow instance id. * @return Current signal value. */ - public Optional getSignal(Integer workflowInstanceId) { + public Optional getSignal(long workflowInstanceId) { return workflowInstanceDao.getSignal(workflowInstanceId); } @@ -143,7 +143,7 @@ public Optional getSignal(Integer workflowInstanceId) { * @param actionType The type of workflow action that is stored to instance actions. * @return True when signal was set, false otherwise. */ - public boolean setSignal(Integer workflowInstanceId, Optional signal, String reason, WorkflowActionType actionType) { + public boolean setSignal(long workflowInstanceId, Optional signal, String reason, WorkflowActionType actionType) { Assert.notNull(workflowDefinitionService, "workflowDefinitionService cannot be null"); signal.ifPresent(signalValue -> { AbstractWorkflowDefinition definition = getDefinition(workflowInstanceId); @@ -154,7 +154,7 @@ public boolean setSignal(Integer workflowInstanceId, Optional signal, S return workflowInstanceDao.setSignal(workflowInstanceId, signal, reason, actionType); } - private AbstractWorkflowDefinition getDefinition(Integer workflowInstanceId) { + private AbstractWorkflowDefinition getDefinition(Long workflowInstanceId) { return workflowDefinitionService.getWorkflowDefinition(workflowInstanceDao.getWorkflowInstanceType(workflowInstanceId)); } diff --git a/nflow-engine/src/main/java/io/nflow/engine/workflow/definition/StateExecution.java b/nflow-engine/src/main/java/io/nflow/engine/workflow/definition/StateExecution.java index d72694a80..72d0b59c4 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/workflow/definition/StateExecution.java +++ b/nflow-engine/src/main/java/io/nflow/engine/workflow/definition/StateExecution.java @@ -18,7 +18,7 @@ public interface StateExecution { * * @return The workflow instance id. */ - int getWorkflowInstanceId(); + long getWorkflowInstanceId(); /** * Return the business key associated to the workflow instance. @@ -175,6 +175,6 @@ public interface StateExecution { * * @return The parent workflow instance id or empty. */ - Optional getParentId(); + Optional getParentId(); } diff --git a/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/QueryWorkflowInstances.java b/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/QueryWorkflowInstances.java index 3f7934013..e4711ba14 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/QueryWorkflowInstances.java +++ b/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/QueryWorkflowInstances.java @@ -16,7 +16,7 @@ public class QueryWorkflowInstances extends ModelObject { /** * Workflow instance identifiers. */ - public final List ids; + public final List ids; /** * Workflow instance definition type. @@ -26,12 +26,12 @@ public class QueryWorkflowInstances extends ModelObject { /** * Parent workflow instance id. */ - public Integer parentWorkflowId; + public Long parentWorkflowId; /** * Parent workflow action id. */ - public Integer parentActionId; + public Long parentActionId; /** * Workflow instance states. @@ -106,10 +106,10 @@ public class QueryWorkflowInstances extends ModelObject { * Builder for workflow instance queries. */ public static class Builder { - List ids = new ArrayList<>(); + List ids = new ArrayList<>(); List types = new ArrayList<>(); - Integer parentWorkflowId; - Integer parentActionId; + Long parentWorkflowId; + Long parentActionId; List states = new ArrayList<>(); List statuses = new ArrayList<>(); String businessKey; @@ -148,7 +148,7 @@ public Builder(QueryWorkflowInstances copy) { * @param newIds The identifiers. * @return this. */ - public Builder addIds(Integer ... newIds) { + public Builder addIds(Long ... newIds) { this.ids.addAll(asList(newIds)); return this; } @@ -168,7 +168,7 @@ public Builder addTypes(String ... newTypes) { * @param parentWorkflowId The parent workflow instance id. * @return this. */ - public Builder setParentWorkflowId(Integer parentWorkflowId) { + public Builder setParentWorkflowId(Long parentWorkflowId) { this.parentWorkflowId = parentWorkflowId; return this; } @@ -178,7 +178,7 @@ public Builder setParentWorkflowId(Integer parentWorkflowId) { * @param parentActionId The parent action id. * @return this. */ - public Builder setParentActionId(Integer parentActionId) { + public Builder setParentActionId(Long parentActionId) { this.parentActionId = parentActionId; return this; } diff --git a/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstance.java b/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstance.java index b76d94eb9..73ccc3cac 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstance.java +++ b/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstance.java @@ -42,7 +42,7 @@ public enum WorkflowInstanceStatus { /** * The workflow instance identifier. */ - public final Integer id; + public final Long id; /** * The id of executor that is currently processing this workflow. May be null. @@ -53,17 +53,17 @@ public enum WorkflowInstanceStatus { * The id of the workflow that created the hierarchy of workflow where this sub workflow belongs to. * Null for workflows that are the root of hierarchy. */ - public final Integer rootWorkflowId; + public final Long rootWorkflowId; /** * The id of the workflow that created this sub workflow. Is null for root workflows. */ - public final Integer parentWorkflowId; + public final Long parentWorkflowId; /** * The id of the workflow action that created this sub workflow. Is null for root workflows. */ - public final Integer parentActionId; + public final Long parentActionId; /** * The current status of the workflow instance. @@ -149,7 +149,7 @@ public enum WorkflowInstanceStatus { /** * Child workflow instance IDs created by this workflow instance, grouped by instance action ID. */ - public Map> childWorkflows; + public Map> childWorkflows; ObjectStringMapper mapper; @@ -228,11 +228,11 @@ public String getStateVariable(String name, String defaultValue) { */ public static class Builder { - Integer id; + Long id; Integer executorId; - Integer rootWorkflowId; - Integer parentWorkflowId; - Integer parentActionId; + Long rootWorkflowId; + Long parentWorkflowId; + Long parentActionId; WorkflowInstanceStatus status; String type; String businessKey; @@ -243,7 +243,7 @@ public static class Builder { final Map originalStateVariables = new LinkedHashMap<>(); final Map stateVariables = new LinkedHashMap<>(); List actions = new ArrayList<>(); - final Map> childWorkflows = new LinkedHashMap<>(); + final Map> childWorkflows = new LinkedHashMap<>(); int retries; DateTime created; DateTime started; @@ -301,7 +301,7 @@ public Builder(WorkflowInstance copy) { * @param id The identifier. * @return this. */ - public Builder setId(Integer id) { + public Builder setId(Long id) { this.id = id; return this; } @@ -321,7 +321,7 @@ public Builder setExecutorId(Integer executorId) { * @param rootWorkflowId The identifier. * @return this */ - public Builder setRootWorkflowId(Integer rootWorkflowId) { + public Builder setRootWorkflowId(Long rootWorkflowId) { this.rootWorkflowId = rootWorkflowId; return this; } @@ -331,7 +331,7 @@ public Builder setRootWorkflowId(Integer rootWorkflowId) { * @param parentWorkflowId The identifier. * @return this. */ - public Builder setParentWorkflowId(Integer parentWorkflowId) { + public Builder setParentWorkflowId(Long parentWorkflowId) { this.parentWorkflowId = parentWorkflowId; return this; } @@ -341,7 +341,7 @@ public Builder setParentWorkflowId(Integer parentWorkflowId) { * @param parentActionId The identifier. * @return this. */ - public Builder setParentActionId(Integer parentActionId) { + public Builder setParentActionId(Long parentActionId) { this.parentActionId = parentActionId; return this; } diff --git a/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstanceAction.java b/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstanceAction.java index a1f673b10..0177fd533 100644 --- a/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstanceAction.java +++ b/nflow-engine/src/main/java/io/nflow/engine/workflow/instance/WorkflowInstanceAction.java @@ -41,12 +41,12 @@ public enum WorkflowActionType { /** * The action id (generated by database). */ - public int id; + public long id; /** * The workflow instance identifier. */ - public final int workflowInstanceId; + public final long workflowInstanceId; /** * The id for executor that processed this state. @@ -106,8 +106,8 @@ public enum WorkflowActionType { */ public static class Builder { - int id; - int workflowInstanceId; + long id; + long workflowInstanceId; int executorId; WorkflowActionType type; String state; @@ -156,7 +156,7 @@ public Builder(WorkflowInstance instance) { * @param id Action id * @return this. */ - public Builder setId(int id) { + public Builder setId(long id) { this.id = id; return this; } @@ -166,7 +166,7 @@ public Builder setId(int id) { * @param workflowInstanceId The workflow instance identifier. * @return this. */ - public Builder setWorkflowInstanceId(int workflowInstanceId) { + public Builder setWorkflowInstanceId(long workflowInstanceId) { this.workflowInstanceId = workflowInstanceId; return this; } diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/dao/ArchiveDaoTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/dao/ArchiveDaoTest.java index cb799faea..8b27f940f 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/dao/ArchiveDaoTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/dao/ArchiveDaoTest.java @@ -44,7 +44,7 @@ public class ArchiveDaoTest extends BaseDaoTest { @Test public void listingArchivableWorkflows() { - List expectedArchive = new ArrayList<>(); + List expectedArchive = new ArrayList<>(); storeActiveWorkflow(archiveTime1); storeActiveWorkflow(prodTime1); @@ -53,15 +53,15 @@ public void listingArchivableWorkflows() { expectedArchive.add(storePassiveWorkflow(archiveTime1)); expectedArchive.add(storePassiveWorkflow(archiveTime2)); - List archivableIds = archiveDao.listArchivableWorkflows(archiveTimeLimit, 10); + List archivableIds = archiveDao.listArchivableWorkflows(archiveTimeLimit, 10); assertEqualsInAnyOrder(expectedArchive, archivableIds); } @Test public void listingReturnsOldestRowsAndMaxBatchSizeRows() { - List expectedArchive = new ArrayList<>(); + List expectedArchive = new ArrayList<>(); - int eleventh = storePassiveWorkflow(archiveTime2); + long eleventh = storePassiveWorkflow(archiveTime2); for (int i = 0; i < 9; i++) { expectedArchive.add(storePassiveWorkflow(archiveTime4)); @@ -72,7 +72,7 @@ public void listingReturnsOldestRowsAndMaxBatchSizeRows() { storeActiveWorkflow(prodTime3); storePassiveWorkflow(prodTime4); - List archivableIds = archiveDao.listArchivableWorkflows(archiveTimeLimit, 10); + List archivableIds = archiveDao.listArchivableWorkflows(archiveTimeLimit, 10); Collections.sort(archivableIds); assertEquals(expectedArchive, archivableIds); @@ -83,7 +83,7 @@ public void listingReturnsOldestRowsAndMaxBatchSizeRows() { @Test public void archivingSimpleWorkflowsWorks() { - List archivableWorkflows = new ArrayList<>(); + List archivableWorkflows = new ArrayList<>(); storeActiveWorkflow(archiveTime1); storeActiveWorkflow(prodTime1); @@ -105,15 +105,15 @@ public void archivingSimpleWorkflowsWorks() { @Test public void archivingWorkflowsWithActionsWorks() { - List archivableWorkflows = new ArrayList<>(); - List archivableActions = new ArrayList<>(); + List archivableWorkflows = new ArrayList<>(); + List archivableActions = new ArrayList<>(); storeActions(storeActiveWorkflow(archiveTime1), 3); storeActions(storeActiveWorkflow(prodTime1), 1); storeActions(storePassiveWorkflow(prodTime1), 2); - int archivable1 = storePassiveWorkflow(archiveTime1); - int archivable2 = storePassiveWorkflow(archiveTime2); + long archivable1 = storePassiveWorkflow(archiveTime1); + long archivable2 = storePassiveWorkflow(archiveTime2); archivableActions.addAll(storeActions(archivable1, 1)); archivableActions.addAll(storeActions(archivable2, 3)); @@ -135,23 +135,23 @@ public void archivingWorkflowsWithActionsWorks() { @Test public void archivingWorkflowsWithActionsAndStatesWorks() { - List archivableWorkflows = new ArrayList<>(); - List archivableActions = new ArrayList<>(); + List archivableWorkflows = new ArrayList<>(); + List archivableActions = new ArrayList<>(); List archivableStates = new ArrayList<>(); - int nonArchivableWorkflow1 = storeActiveWorkflow(archiveTime1); + long nonArchivableWorkflow1 = storeActiveWorkflow(archiveTime1); storeStateVariables(nonArchivableWorkflow1, storeActions(nonArchivableWorkflow1, 3), 1); - int nonArchivableWorkflow2 = storeActiveWorkflow(prodTime1); + long nonArchivableWorkflow2 = storeActiveWorkflow(prodTime1); storeStateVariables(nonArchivableWorkflow2, storeActions(nonArchivableWorkflow2, 1), 3); - int nonArchivableWorkflow3 = storePassiveWorkflow(prodTime1); + long nonArchivableWorkflow3 = storePassiveWorkflow(prodTime1); storeStateVariables(nonArchivableWorkflow3, storeActions(nonArchivableWorkflow3, 2), 2); - int archivable1 = storePassiveWorkflow(archiveTime1); - int archivable2 = storePassiveWorkflow(archiveTime2); - List actions1 = storeActions(archivable1, 1); - List actions2 = storeActions(archivable2, 2); + long archivable1 = storePassiveWorkflow(archiveTime1); + long archivable2 = storePassiveWorkflow(archiveTime2); + List actions1 = storeActions(archivable1, 1); + List actions2 = storeActions(archivable2, 2); archivableActions.addAll(actions1); archivableActions.addAll(actions2); @@ -181,8 +181,8 @@ public void archivingWorkflowsWithActionsAndStatesWorks() { assertEquals(variablesCountAfter, variablesCountBefore - archivableStates.size() - requestDataVariableCount); } - private void assertActiveWorkflowsRemoved(List workflowIds) { - for (int id : workflowIds) { + private void assertActiveWorkflowsRemoved(List workflowIds) { + for (long id : workflowIds) { try { workflowInstanceDao.getWorkflowInstance(id, emptySet(), null); fail("Expected workflow " + id + " to be removed"); @@ -192,22 +192,22 @@ private void assertActiveWorkflowsRemoved(List workflowIds) { } } - private void assertArchiveWorkflowsExist(List workflowIds) { - for (int workflowId : workflowIds) { + private void assertArchiveWorkflowsExist(List workflowIds) { + for (long workflowId : workflowIds) { Map archived = getArchivedWorkflow(workflowId); assertEquals(workflowId, archived.get("id")); } } - private void assertActiveActionsRemoved(List actionIds) { - for (int actionId : actionIds) { + private void assertActiveActionsRemoved(List actionIds) { + for (long actionId : actionIds) { int found = rowCount("select 1 from nflow_workflow_action where id = ?", actionId); assertEquals(0, found, "Found unexpected action " + actionId + " in nflow_workflow_action"); } } - private void assertArchiveActionsExist(List actionIds) { - for (int actionId : actionIds) { + private void assertArchiveActionsExist(List actionIds) { + for (long actionId : actionIds) { int found = rowCount("select 1 from nflow_archive_workflow_action where id = ?", actionId); assertEquals(1, found, "Action " + actionId + " not found in nflow_archive_workflow_action"); } @@ -234,40 +234,40 @@ private int rowCount(String sql, Object... params) { return jdbc.queryForList(sql, params).size(); } - private Map getArchivedWorkflow(int workflowId) { - return jdbc.queryForMap("select * from nflow_archive_workflow where id = ?", new Object[] { workflowId }); + private Map getArchivedWorkflow(long workflowId) { + return jdbc.queryForMap("select * from nflow_archive_workflow where id = ?", workflowId); } - private int storePassiveWorkflow(DateTime modified) { + private long storePassiveWorkflow(DateTime modified) { WorkflowInstance instance = constructWorkflowInstanceBuilder().setStatus(created).setNextActivation(null) .setModified(modified).build(); - int id = insert(instance); + long id = insert(instance); return id; } - private int storeActiveWorkflow(DateTime modified) { + private long storeActiveWorkflow(DateTime modified) { WorkflowInstance instance = constructWorkflowInstanceBuilder().setStatus(created).setModified(modified).build(); - int id = insert(instance); + long id = insert(instance); return id; } - private List storeActions(int workflowId, int actionCount) { - List actionIds = new ArrayList<>(); + private List storeActions(long workflowId, int actionCount) { + List actionIds = new ArrayList<>(); for (int i = 0; i < actionCount; i++) { actionIds.add(storeAction(workflowId)); } return actionIds; } - private List storeStateVariables(int workflowId, List actionIds, int count) { + private List storeStateVariables(long workflowId, List actionIds, int count) { List stateKeys = new ArrayList<>(); - for (int actionId : actionIds) { + for (long actionId : actionIds) { stateKeys.addAll(storeStateVariables(workflowId, actionId, count)); } return stateKeys; } - private List storeStateVariables(int workflowId, int actionId, int stateCount) { + private List storeStateVariables(long workflowId, long actionId, int stateCount) { List stateKeys = new ArrayList<>(); int index = 1; for (int i = 0; i < stateCount; i++) { @@ -276,7 +276,7 @@ private List storeStateVariables(int workflowId, int actionId, int sta return stateKeys; } - private StateKey storeStateVariable(int workflowId, int actionId, String key) { + private StateKey storeStateVariable(long workflowId, long actionId, String key) { String value = key + "_value"; int updated = jdbc.update( "insert into nflow_workflow_state (workflow_id, action_id, state_key, state_value) values (?, ?, ?, ?)", workflowId, @@ -285,19 +285,19 @@ private StateKey storeStateVariable(int workflowId, int actionId, String key) { return new StateKey(workflowId, actionId, key); } - private int storeAction(int workflowId) { + private long storeAction(long workflowId) { WorkflowInstanceAction action = actionBuilder(workflowId).build(); return workflowInstanceDao.insertWorkflowInstanceAction(action); } - private WorkflowInstanceAction.Builder actionBuilder(int workflowId) { + private WorkflowInstanceAction.Builder actionBuilder(long workflowId) { return new WorkflowInstanceAction.Builder().setState("dummyState") .setType(WorkflowInstanceAction.WorkflowActionType.stateExecution).setExecutionStart(DateTime.now()) .setExecutionEnd(DateTime.now()).setWorkflowInstanceId(workflowId); } - private int insert(WorkflowInstance instance) { - int id = workflowInstanceDao.insertWorkflowInstance(instance); + private long insert(WorkflowInstance instance) { + long id = workflowInstanceDao.insertWorkflowInstance(instance); assertTrue(id > 0); DateTime modified = instance.modified; updateModified(id, modified); @@ -306,26 +306,26 @@ private int insert(WorkflowInstance instance) { return id; } - private void updateModified(int workflowId, DateTime modified) { + private void updateModified(long workflowId, DateTime modified) { int updateCount = jdbc.update("update nflow_workflow set modified = ? where id = ?", - new Object[] { DaoUtil.toTimestamp(modified), workflowId }); + DaoUtil.toTimestamp(modified), workflowId); assertEquals(1, updateCount); } - private void assertEqualsInAnyOrder(List expected, List actual) { - List expectedCopy = new ArrayList<>(expected); - List actualCopy = new ArrayList<>(actual); + private > void assertEqualsInAnyOrder(List expected, List actual) { + List expectedCopy = new ArrayList<>(expected); + List actualCopy = new ArrayList<>(actual); Collections.sort(expectedCopy); Collections.sort(actualCopy); assertEquals(expectedCopy, actualCopy); } private static class StateKey extends ModelObject { - public final int workflowId; - public final int actionId; + public final long workflowId; + public final long actionId; public final String stateKey; - public StateKey(int workflowId, int actionId, String stateKey) { + public StateKey(long workflowId, long actionId, String stateKey) { this.workflowId = workflowId; this.actionId = actionId; this.stateKey = stateKey; diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/dao/StatisticsDaoTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/dao/StatisticsDaoTest.java index faf774ec2..289017098 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/dao/StatisticsDaoTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/dao/StatisticsDaoTest.java @@ -50,17 +50,17 @@ public void getQueueStatisticsReasonableResults() { assertThat(queued.minAgeMillis, greaterThanOrEqualTo(0L)); } - private int createInstance() { + private long createInstance() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().build(); i1.stateVariables.put("a", "1"); - int id = instanceDao.insertWorkflowInstance(i1); + long id = instanceDao.insertWorkflowInstance(i1); return id; } @Test public void getWorkflowDefinitionStatisticsWorks() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(null).setStatus(created).build(); - int id = instanceDao.insertWorkflowInstance(i1); + long id = instanceDao.insertWorkflowInstance(i1); Map> stats = statisticsDao.getWorkflowDefinitionStatistics(i1.type, null, null, null, null); diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/dao/WorkflowInstanceDaoTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/dao/WorkflowInstanceDaoTest.java index b67616cf5..0351e5b53 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/dao/WorkflowInstanceDaoTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/dao/WorkflowInstanceDaoTest.java @@ -75,7 +75,7 @@ public class WorkflowInstanceDaoTest extends BaseDaoTest { public void roundTripTest() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().build(); i1.stateVariables.put("a", "1"); - int id = dao.insertWorkflowInstance(i1); + long id = dao.insertWorkflowInstance(i1); WorkflowInstance i2 = dao.getWorkflowInstance(id, EnumSet.allOf(WorkflowInstanceInclude.class), null); assertThat(i2.id, notNullValue()); assertThat(i2.created, notNullValue()); @@ -87,15 +87,15 @@ public void roundTripTest() { public void queryWorkflowInstanceWithAllConditions() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().build(); i1.stateVariables.put("b", "2"); - int workflowId = dao.insertWorkflowInstance(i1); + long workflowId = dao.insertWorkflowInstance(i1); assertThat(workflowId, not(equalTo(-1))); WorkflowInstanceAction action = constructActionBuilder(workflowId).build(); - int actionId = dao.insertWorkflowInstanceAction(action); + long actionId = dao.insertWorkflowInstanceAction(action); WorkflowInstance child = constructWorkflowInstanceBuilder().setParentWorkflowId(workflowId).setParentActionId(actionId) .build(); - int childId = dao.insertWorkflowInstance(child); + long childId = dao.insertWorkflowInstance(child); assertThat(childId, not(equalTo(-1))); dao.insertWorkflowInstanceAction(constructActionBuilder(childId).build()); dao.insertWorkflowInstanceAction(constructActionBuilder(childId).build()); @@ -124,7 +124,7 @@ public void queryWorkflowInstanceWithAllConditions() { @Test public void queryWorkflowInstanceWithMinimalConditions() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().build(); - int id = dao.insertWorkflowInstance(i1); + long id = dao.insertWorkflowInstance(i1); assertThat(id, not(equalTo(-1))); QueryWorkflowInstances q = new QueryWorkflowInstances.Builder().build(); List createdInstances = dao.queryWorkflowInstances(q); @@ -137,8 +137,8 @@ public void queryWorkflowInstanceWithMinimalConditions() { @Test public void updateWorkflowInstance() throws InterruptedException { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setStatus(created).build(); - int id = dao.insertWorkflowInstance(i1); - List ids = dao.pollNextWorkflowInstanceIds(1); + long id = dao.insertWorkflowInstance(i1); + List ids = dao.pollNextWorkflowInstanceIds(1); assertThat(ids, contains(id)); DateTime started = now(); final WorkflowInstance i2 = new WorkflowInstance.Builder( @@ -229,7 +229,7 @@ public void updateWorkflowInstanceCreatesActionWhenStateVariablesAreModified() { private WorkflowInstance.Builder updateInstanceBuilder() { WorkflowInstance instance = constructWorkflowInstanceBuilder().setStatus(created).setBusinessKey("updatedKey").build(); - int id = dao.insertWorkflowInstance(instance); + long id = dao.insertWorkflowInstance(instance); return new WorkflowInstance.Builder( dao.getWorkflowInstance(id, EnumSet.of(WorkflowInstanceInclude.CURRENT_STATE_VARIABLES), null)) // .setStatus(inProgress) // @@ -254,10 +254,10 @@ public void updateWorkflowInstanceWithRootWorkflowAndChildWorkflowsWorks() { dao.updateWorkflowInstanceAfterExecution(instance, action, asList(childWorkflow), emptyWorkflows, false); - Map> childWorkflows = dao.getWorkflowInstance(instance.id, + Map> childWorkflows = dao.getWorkflowInstance(instance.id, EnumSet.of(WorkflowInstanceInclude.CHILD_WORKFLOW_IDS), null).childWorkflows; assertThat(childWorkflows.size(), is(1)); - for (List childIds : childWorkflows.values()) { + for (List childIds : childWorkflows.values()) { assertThat(childIds.size(), is(1)); WorkflowInstance childInstance = dao.getWorkflowInstance(childIds.get(0), emptySet(), null); assertThat(childInstance.rootWorkflowId, is(instance.id)); @@ -269,7 +269,7 @@ public void updateWorkflowInstanceWithRootWorkflowAndChildWorkflowsWorks() { @Test public void updateWorkflowInstanceWithChildWorkflowHavingExistinExternalIdWorks() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setStatus(created).build(); - int id = dao.insertWorkflowInstance(i1); + long id = dao.insertWorkflowInstance(i1); WorkflowInstance i2 = new WorkflowInstance.Builder( dao.getWorkflowInstance(id, EnumSet.of(WorkflowInstanceInclude.CURRENT_STATE_VARIABLES), null)) // .setStatus(inProgress) // @@ -297,10 +297,10 @@ public void updateWorkflowInstanceWithChildWorkflowHavingExistinExternalIdWorks( dao.updateWorkflowInstanceAfterExecution(i2, a1, asList(childWorkflow1, childWorkflow2), emptyWorkflows, false); - Map> childWorkflows = dao.getWorkflowInstance(id, + Map> childWorkflows = dao.getWorkflowInstance(id, EnumSet.of(WorkflowInstanceInclude.CHILD_WORKFLOW_IDS), null).childWorkflows; assertThat(childWorkflows.size(), is(1)); - for (List childIds : childWorkflows.values()) { + for (List childIds : childWorkflows.values()) { assertThat(childIds.size(), is(1)); WorkflowInstance childInstance = dao.getWorkflowInstance(childIds.get(0), EnumSet.of(WorkflowInstanceInclude.CURRENT_STATE_VARIABLES), null); @@ -317,7 +317,7 @@ public void updateWorkflowInstanceWithChildWorkflowHavingExistinExternalIdWorks( public void updateWorkflowInstanceWithNonRootWorkflowAndChildWorkflowsWorks() { // create 3 level hierarchy of workflows WorkflowInstance i1 = constructWorkflowInstanceBuilder().setStatus(created).build(); - int id = dao.insertWorkflowInstance(i1); + long id = dao.insertWorkflowInstance(i1); WorkflowInstance i2 = new WorkflowInstance.Builder( dao.getWorkflowInstance(id, EnumSet.of(WorkflowInstanceInclude.CURRENT_STATE_VARIABLES), null)).setStatus(inProgress) .setState("updateState").setStateText("update text").build(); @@ -330,8 +330,8 @@ public void updateWorkflowInstanceWithNonRootWorkflowAndChildWorkflowsWorks() { dao.updateWorkflowInstanceAfterExecution(i2, a1, asList(middleWorkflow), emptyWorkflows, false); - int middleWorkflowId = -1; - for (List childIds : dao.getWorkflowInstance(id, EnumSet.of(WorkflowInstanceInclude.CHILD_WORKFLOW_IDS), + long middleWorkflowId = -1; + for (List childIds : dao.getWorkflowInstance(id, EnumSet.of(WorkflowInstanceInclude.CHILD_WORKFLOW_IDS), null).childWorkflows.values()) { middleWorkflowId = childIds.get(0); } @@ -347,10 +347,10 @@ public void updateWorkflowInstanceWithNonRootWorkflowAndChildWorkflowsWorks() { WorkflowInstance childWorkflow = constructWorkflowInstanceBuilder().setBusinessKey("childKey").build(); dao.updateWorkflowInstanceAfterExecution(middleWorkflow, middleAction, asList(childWorkflow), emptyWorkflows, false); - Map> childWorkflows = dao.getWorkflowInstance(middleWorkflowId, + Map> childWorkflows = dao.getWorkflowInstance(middleWorkflowId, EnumSet.of(WorkflowInstanceInclude.CHILD_WORKFLOW_IDS), null).childWorkflows; assertThat(childWorkflows.size(), is(1)); - for (List childIds : childWorkflows.values()) { + for (List childIds : childWorkflows.values()) { assertThat(childIds.size(), is(1)); WorkflowInstance childInstance = dao.getWorkflowInstance(childIds.get(0), emptySet(), null); assertThat(childInstance.rootWorkflowId, is(id)); @@ -362,7 +362,7 @@ public void updateWorkflowInstanceWithNonRootWorkflowAndChildWorkflowsWorks() { @Test public void updateNotRunningWorkflowInstanceUpdatesStatusForNotRunningInstance() { final WorkflowInstance instance = constructWorkflowInstanceBuilder().build(); - int id = dao.insertWorkflowInstance(instance); + long id = dao.insertWorkflowInstance(instance); WorkflowInstance modifiedInstance = new WorkflowInstance.Builder(instance).setId(id).setState(null).setNextActivation(null) .setStatus(manual).setStateText("modified").build(); boolean updated = dao.updateNotRunningWorkflowInstance(modifiedInstance); @@ -381,7 +381,7 @@ public void processRow(ResultSet rs) throws SQLException { @Test public void updateNotRunningWorkflowInstanceUpdatesStateForNotRunningInstance() { final WorkflowInstance instance = constructWorkflowInstanceBuilder().build(); - int id = dao.insertWorkflowInstance(instance); + long id = dao.insertWorkflowInstance(instance); WorkflowInstance modifiedInstance = new WorkflowInstance.Builder(instance).setId(id).setState("manualState") .setNextActivation(null).setStatus(null).setStateText("modified").build(); boolean updated = dao.updateNotRunningWorkflowInstance(modifiedInstance); @@ -400,7 +400,7 @@ public void processRow(ResultSet rs) throws SQLException { @Test public void updateNotRunningWorkflowInstanceUpdatesNextActivationForNotRunningInstance() { final WorkflowInstance instance = constructWorkflowInstanceBuilder().build(); - int id = dao.insertWorkflowInstance(instance); + long id = dao.insertWorkflowInstance(instance); final DateTime tomorrow = now().plusDays(1); WorkflowInstance modifiedInstance = new WorkflowInstance.Builder(instance).setId(id).setState(null) .setNextActivation(tomorrow).setStatus(null).setStateText("modified").build(); @@ -420,7 +420,7 @@ public void processRow(ResultSet rs) throws SQLException { @Test public void updateNotRunningWorkflowInstanceDoesNotUpdateRunningInstance() { WorkflowInstance instance = constructWorkflowInstanceBuilder().build(); - int id = dao.insertWorkflowInstance(instance); + long id = dao.insertWorkflowInstance(instance); assertThat(jdbc.update("update nflow_workflow set executor_id = ? where id = ?", executorDao.getExecutorId(), id), is(1)); final DateTime tomorrow = now().plusDays(1); WorkflowInstance modifiedInstance = new WorkflowInstance.Builder(instance).setId(id).setState("manualState") @@ -432,7 +432,7 @@ public void updateNotRunningWorkflowInstanceDoesNotUpdateRunningInstance() { @Test public void updatingNextActivationToNullWhileExternalNextActivationIsNotNull() { WorkflowInstance instance = constructWorkflowInstanceBuilder().setNextActivation(null).build(); - int workflowId = dao.insertWorkflowInstance(instance); + long workflowId = dao.insertWorkflowInstance(instance); assertTrue(workflowId > -1); jdbc.update("update nflow_workflow set executor_id = ? where id = ?", executorDao.getExecutorId(), workflowId); assertThat(jdbc.update("update nflow_workflow set external_next_activation = ? where id = ?", @@ -453,7 +453,7 @@ public void updatingNextActivationWhenExternalNextActivationIsEarlier() { WorkflowInstance instance = constructWorkflowInstanceBuilder().setNextActivation(future).build(); - final int workflowId = dao.insertWorkflowInstance(instance); + final long workflowId = dao.insertWorkflowInstance(instance); jdbc.update("update nflow_workflow set executor_id = ? where id = ?", executorDao.getExecutorId(), workflowId); assertTrue(workflowId > -1); @@ -472,7 +472,7 @@ public void updatingNextActivationWhenExternalNextActivationIsLater() { DateTime future = now.plusDays(1); WorkflowInstance instance = constructWorkflowInstanceBuilder().setNextActivation(now).build(); - int workflowId = dao.insertWorkflowInstance(instance); + long workflowId = dao.insertWorkflowInstance(instance); jdbc.update("update nflow_workflow set executor_id = ? where id = ?", executorDao.getExecutorId(), workflowId); assertTrue(workflowId > -1); @@ -486,8 +486,8 @@ public void updatingNextActivationWhenExternalNextActivationIsLater() { @Test public void postgreSQLUpdateWithoutActionIsNotAllowed() throws InterruptedException { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setStatus(created).build(); - int id = dao.insertWorkflowInstance(i1); - List ids = dao.pollNextWorkflowInstanceIds(1); + long id = dao.insertWorkflowInstance(i1); + List ids = dao.pollNextWorkflowInstanceIds(1); assertThat(ids, contains(id)); final WorkflowInstance i2 = new WorkflowInstance.Builder( dao.getWorkflowInstance(id, EnumSet.of(CURRENT_STATE_VARIABLES), null)).setStatus(inProgress) @@ -503,11 +503,11 @@ public void fakePostgreSQLupdateWorkflowInstance() { WorkflowInstanceDao d = preparePostgreSQLDao(j); ArgumentCaptor sql = ArgumentCaptor.forClass(String.class); ArgumentCaptor args = ArgumentCaptor.forClass(Object.class); - when(j.queryForObject(sql.capture(), eq(Integer.class), args.capture())).thenReturn(42); + when(j.queryForObject(sql.capture(), eq(Long.class), args.capture())).thenReturn(42L); DateTime started = now(); WorkflowInstance i2 = new WorkflowInstance.Builder().setState("updateState").setStateText("update text") - .setNextActivation(started.plusSeconds(1)).setStatus(executing).setRetries(3).setId(43).putStateVariable("A", "B") + .setNextActivation(started.plusSeconds(1)).setStatus(executing).setRetries(3).setId(43L).putStateVariable("A", "B") .build(); WorkflowInstanceAction a1 = new WorkflowInstanceAction.Builder().setExecutionStart(started).setExecutorId(4) .setExecutionEnd(started.plusMillis(100)).setRetryNo(1).setType(externalChange).setState("test") @@ -532,11 +532,11 @@ public void fakePostgreSQLupdateWorkflowInstance() { assertThat(args.getAllValues().get(i++), is((Object) new Timestamp(i2.nextActivation.getMillis()))); assertThat(args.getAllValues().get(i++), is((Object) new Timestamp(i2.nextActivation.getMillis()))); assertThat(args.getAllValues().get(i++), is((Object) new Timestamp(i2.nextActivation.getMillis()))); - assertThat(args.getAllValues().get(i++), is((Object) 42)); + assertThat(args.getAllValues().get(i++), is((Object) 42L)); assertThat(args.getAllValues().get(i++), is((Object) i2.retries)); assertThat(args.getAllValues().get(i++), is((Object) new Timestamp(a1.executionStart.getMillis()))); assertThat(args.getAllValues().get(i++), is((Object) i2.id)); - assertThat(args.getAllValues().get(i++), is((Object) 42)); + assertThat(args.getAllValues().get(i++), is((Object) 42L)); assertThat(args.getAllValues().get(i++), is((Object) a1.type.name())); assertThat(args.getAllValues().get(i++), is((Object) a1.state)); assertThat(args.getAllValues().get(i++), is((Object) a1.stateText)); @@ -553,12 +553,12 @@ public void fakePostgreSQLinsertWorkflowInstance() { WorkflowInstanceDao d = preparePostgreSQLDao(j); ArgumentCaptor sql = ArgumentCaptor.forClass(String.class); ArgumentCaptor args = ArgumentCaptor.forClass(Object.class); - when(j.queryForObject(sql.capture(), eq(Integer.class), args.capture())).thenReturn(42); + when(j.queryForObject(sql.capture(), eq(Long.class), args.capture())).thenReturn(42L); DateTime started = now(); WorkflowInstance wf = new WorkflowInstance.Builder().setStatus(inProgress).setState("updateState").setStateText("update text") - .setRootWorkflowId(9283).setParentWorkflowId(110).setParentActionId(421).setNextActivation(started.plusSeconds(1)) - .setRetries(3).setId(43).putStateVariable("A", "B").putStateVariable("C", "D").setSignal(Optional.of(1)) + .setRootWorkflowId(9283L).setParentWorkflowId(110L).setParentActionId(421L).setNextActivation(started.plusSeconds(1)) + .setRetries(3).setId(43L).putStateVariable("A", "B").putStateVariable("C", "D").setSignal(Optional.of(1)) .setStartedIfNotSet(started).build(); d.insertWorkflowInstance(wf); @@ -596,7 +596,7 @@ public void insertWorkflowInstanceActionWorks() { DateTime started = now(); final WorkflowInstance i1 = constructWorkflowInstanceBuilder().build(); i1.stateVariables.put("a", "1"); - int id = dao.insertWorkflowInstance(i1); + long id = dao.insertWorkflowInstance(i1); final WorkflowInstanceAction a1 = new WorkflowInstanceAction.Builder().setExecutionStart(started).setExecutorId(42) .setExecutionEnd(started.plusMillis(100)).setRetryNo(1).setType(stateExecution).setState("test") .setStateText("state text").setWorkflowInstanceId(id).build(); @@ -616,9 +616,9 @@ public Void doInTransaction(TransactionStatus status) { public void pollNextWorkflowInstances() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(now().minusMinutes(1)).setExecutorGroup("junit") .build(); - int id = dao.insertWorkflowInstance(i1); - List firstBatch = dao.pollNextWorkflowInstanceIds(100); - List secondBatch = dao.pollNextWorkflowInstanceIds(100); + long id = dao.insertWorkflowInstance(i1); + List firstBatch = dao.pollNextWorkflowInstanceIds(100); + List secondBatch = dao.pollNextWorkflowInstanceIds(100); assertThat(firstBatch.size(), equalTo(1)); assertThat(firstBatch.get(0), equalTo(id)); assertThat(secondBatch.size(), equalTo(0)); @@ -629,8 +629,8 @@ public void fakePostgreSQLpollNextWorkflowInstances() { JdbcTemplate j = mock(JdbcTemplate.class); WorkflowInstanceDao d = preparePostgreSQLDao(j); ArgumentCaptor sql = ArgumentCaptor.forClass(String.class); - when(j.queryForList(sql.capture(), eq(Integer.class))).thenReturn(asList(1, 2, 3)); - assertThat(d.pollNextWorkflowInstanceIds(5), is(asList(1, 2, 3))); + when(j.queryForList(sql.capture(), eq(Long.class))).thenReturn(asList(1L, 2L, 3L)); + assertThat(d.pollNextWorkflowInstanceIds(5), is(asList(1L, 2L, 3L))); assertEquals( "update nflow_workflow set executor_id = 42, status = 'executing'::workflow_status, external_next_activation = null where id in (select id from nflow_workflow where executor_id is null and status in ('created'::workflow_status, 'inProgress'::workflow_status) and next_activation <= current_timestamp and group matches order by next_activation asc limit 5) and executor_id is null returning id", sql.getValue()); @@ -679,7 +679,7 @@ public void pollNextWorkflowInstancesWithPartialRaceCondition() throws Interrupt @Test public void wakesUpSleepingWorkflow() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(null).build(); - int id = dao.insertWorkflowInstance(i1); + long id = dao.insertWorkflowInstance(i1); assertThat(dao.getWorkflowInstance(id, emptySet(), null).nextActivation, nullValue()); dao.wakeupWorkflowInstanceIfNotExecuting(id, new ArrayList()); assertThat(dao.getWorkflowInstance(id, emptySet(), null).nextActivation, notNullValue()); @@ -689,8 +689,8 @@ public void wakesUpSleepingWorkflow() { public void doesNotWakeUpRunningWorkflow() { DateTime past = now().minusDays(1); WorkflowInstance i1 = constructWorkflowInstanceBuilder().setExecutorGroup("junit").setNextActivation(past).build(); - int id = dao.insertWorkflowInstance(i1); - List ids = dao.pollNextWorkflowInstanceIds(1); + long id = dao.insertWorkflowInstance(i1); + List ids = dao.pollNextWorkflowInstanceIds(1); assertThat(ids, contains(id)); assertThat(dao.getWorkflowInstance(id, emptySet(), null).nextActivation, is(past)); dao.wakeupWorkflowInstanceIfNotExecuting(id, asList(i1.state)); @@ -700,7 +700,7 @@ public void doesNotWakeUpRunningWorkflow() { @Test public void wakesUpWorkflowInMatchingState() { WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(null).build(); - int id = dao.insertWorkflowInstance(i1); + long id = dao.insertWorkflowInstance(i1); assertThat(dao.getWorkflowInstance(id, emptySet(), null).nextActivation, nullValue()); dao.wakeupWorkflowInstanceIfNotExecuting(id, asList("otherState", i1.state)); assertThat(dao.getWorkflowInstance(id, emptySet(), null).nextActivation, notNullValue()); @@ -709,7 +709,7 @@ public void wakesUpWorkflowInMatchingState() { @Test public void getWorkflowInstanceStateWorks() { WorkflowInstance instance = constructWorkflowInstanceBuilder().build(); - int workflowInstanceId = dao.insertWorkflowInstance(instance); + long workflowInstanceId = dao.insertWorkflowInstance(instance); String state = dao.getWorkflowInstanceState(workflowInstanceId); @@ -721,18 +721,18 @@ public void insertingSubWorkflowWorks() { DateTime started = now(); final WorkflowInstance i1 = constructWorkflowInstanceBuilder().build(); i1.stateVariables.put("b", "2"); - int parentWorkflowId = dao.insertWorkflowInstance(i1); + long parentWorkflowId = dao.insertWorkflowInstance(i1); assertThat(parentWorkflowId, not(equalTo(-1))); - int parentActionId = addWorkflowAction(parentWorkflowId, i1, started, started.plusMillis(100)); + long parentActionId = addWorkflowAction(parentWorkflowId, i1, started, started.plusMillis(100)); WorkflowInstance createdInstance = dao.getWorkflowInstance(parentWorkflowId, EnumSet.allOf(WorkflowInstanceInclude.class), null); checkSameWorkflowInfo(i1, createdInstance); - int subWorkflowId1 = addSubWorkflow(parentWorkflowId, parentActionId); + long subWorkflowId1 = addSubWorkflow(parentWorkflowId, parentActionId); assertThat(subWorkflowId1, not(equalTo(-1))); - int subWorkflowId2 = addSubWorkflow(parentWorkflowId, parentActionId); + long subWorkflowId2 = addSubWorkflow(parentWorkflowId, parentActionId); assertThat(subWorkflowId2, not(equalTo(-1))); WorkflowInstance i2 = dao.getWorkflowInstance(subWorkflowId1, emptySet(), null); @@ -748,16 +748,16 @@ public void wakeUpWorkflowExternallyWorksWithEmptyExpectedStates() { DateTime now = now(); DateTime scheduled = now.plusDays(1); WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(scheduled).build(); - int parentWorkflowId = dao.insertWorkflowInstance(i1); + long parentWorkflowId = dao.insertWorkflowInstance(i1); assertThat(parentWorkflowId, not(equalTo(-1))); WorkflowInstance createdWorkflow = dao.getWorkflowInstance(parentWorkflowId, emptySet(), null); assertThat(createdWorkflow.nextActivation, equalTo(scheduled)); - int parentActionId = addWorkflowAction(parentWorkflowId, i1, now, now.plusMillis(100)); + long parentActionId = addWorkflowAction(parentWorkflowId, i1, now, now.plusMillis(100)); assertThat(parentActionId, not(equalTo(-1))); - int subWorkflowId = addSubWorkflow(parentWorkflowId, parentActionId); + long subWorkflowId = addSubWorkflow(parentWorkflowId, parentActionId); WorkflowInstance i2 = dao.getWorkflowInstance(subWorkflowId, emptySet(), null); assertThat(subWorkflowId, not(equalTo(-1))); assertThat(i2.parentWorkflowId, equalTo(parentWorkflowId)); @@ -773,16 +773,16 @@ public void wakeUpWorkflowExternallyWorksWithExpectedStates() { DateTime now = now(); DateTime scheduled = now.plusDays(1); WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(scheduled).build(); - int parentWorkflowId = dao.insertWorkflowInstance(i1); + long parentWorkflowId = dao.insertWorkflowInstance(i1); assertThat(parentWorkflowId, not(equalTo(-1))); WorkflowInstance createdWorkflow = dao.getWorkflowInstance(parentWorkflowId, emptySet(), null); assertThat(createdWorkflow.nextActivation, equalTo(scheduled)); - int parentActionId = addWorkflowAction(parentWorkflowId, i1, now, now.plusMillis(100)); + long parentActionId = addWorkflowAction(parentWorkflowId, i1, now, now.plusMillis(100)); assertThat(parentActionId, not(equalTo(-1))); - int subWorkflowId = addSubWorkflow(parentWorkflowId, parentActionId); + long subWorkflowId = addSubWorkflow(parentWorkflowId, parentActionId); WorkflowInstance i2 = dao.getWorkflowInstance(subWorkflowId, emptySet(), null); assertThat(subWorkflowId, not(equalTo(-1))); assertThat(i2.parentWorkflowId, equalTo(parentWorkflowId)); @@ -798,16 +798,16 @@ public void wakeUpWorkflowExternallyDoesNotWakeUpWorkflowInUnexpectedState() { DateTime now = now(); DateTime scheduled = now.plusDays(1); WorkflowInstance i1 = constructWorkflowInstanceBuilder().setNextActivation(scheduled).setState("unexpected").build(); - int parentWorkflowId = dao.insertWorkflowInstance(i1); + long parentWorkflowId = dao.insertWorkflowInstance(i1); assertThat(parentWorkflowId, not(equalTo(-1))); WorkflowInstance createdWorkflow = dao.getWorkflowInstance(parentWorkflowId, emptySet(), null); assertThat(createdWorkflow.nextActivation, equalTo(scheduled)); - int parentActionId = addWorkflowAction(parentWorkflowId, i1, now, now.plusMillis(100)); + long parentActionId = addWorkflowAction(parentWorkflowId, i1, now, now.plusMillis(100)); assertThat(parentActionId, not(equalTo(-1))); - int subWorkflowId = addSubWorkflow(parentWorkflowId, parentActionId); + long subWorkflowId = addSubWorkflow(parentWorkflowId, parentActionId); WorkflowInstance i2 = dao.getWorkflowInstance(subWorkflowId, emptySet(), null); assertThat(subWorkflowId, not(equalTo(-1))); assertThat(i2.parentWorkflowId, equalTo(parentWorkflowId)); @@ -822,9 +822,9 @@ public void wakeUpWorkflowExternallyDoesNotWakeUpWorkflowInUnexpectedState() { public void recoverWorkflowInstancesFromDeadNodesSetsExecutorIdToNullAndStatusToInProgressAndInsertsAction() { int crashedExecutorId = 999; insertCrashedExecutor(crashedExecutorId, executorDao.getExecutorGroup()); - int id = dao.insertWorkflowInstance(new WorkflowInstance.Builder().setType("test").setExternalId("extId") + long id = dao.insertWorkflowInstance(new WorkflowInstance.Builder().setType("test").setExternalId("extId") .setExecutorGroup(executorDao.getExecutorGroup()).setStatus(executing).setState("processing").build()); - int updated = jdbc.update("update nflow_workflow set executor_id = ? where id = ?", crashedExecutorId, id); + long updated = jdbc.update("update nflow_workflow set executor_id = ? where id = ?", crashedExecutorId, id); assertThat(updated, is(1)); dao.recoverWorkflowInstancesFromDeadNodes(); @@ -835,7 +835,7 @@ public void recoverWorkflowInstancesFromDeadNodesSetsExecutorIdToNullAndStatusTo assertThat(status, is(inProgress.name())); List actions = jdbc.query("select * from nflow_workflow_action where workflow_id = ?", - new WorkflowInstanceActionRowMapper(sqlVariant, Collections.> emptyMap()), id); + new WorkflowInstanceActionRowMapper(sqlVariant, Collections.emptyMap()), id); assertThat(actions.size(), is(1)); WorkflowInstanceAction workflowInstanceAction = actions.get(0); assertThat(workflowInstanceAction.executorId, is(executorDao.getExecutorId())); @@ -848,7 +848,7 @@ public void recoverWorkflowInstancesFromDeadNodesSetsExecutorIdToNullAndStatusTo assertThat(executorId, is(nullValue())); actions = jdbc.query("select * from nflow_workflow_action where workflow_id = ?", - new WorkflowInstanceActionRowMapper(sqlVariant, Collections.> emptyMap()), id); + new WorkflowInstanceActionRowMapper(sqlVariant, Collections.emptyMap()), id); assertThat(actions.size(), is(1)); assertThat(workflowInstanceAction.executorId, is(executorDao.getExecutorId())); assertThat(workflowInstanceAction.type, is(recovery)); @@ -858,7 +858,7 @@ public void recoverWorkflowInstancesFromDeadNodesSetsExecutorIdToNullAndStatusTo @Test public void settingSignalInsertsAction() { WorkflowInstance i = constructWorkflowInstanceBuilder().setBusinessKey("setSignalTest").build(); - int instanceId = dao.insertWorkflowInstance(i); + long instanceId = dao.insertWorkflowInstance(i); dao.setSignal(instanceId, Optional.of(42), "testing", WorkflowActionType.externalChange); @@ -876,7 +876,7 @@ public void settingSignalInsertsAction() { @Test public void clearingSignalInsertsAction() { WorkflowInstance i = constructWorkflowInstanceBuilder().setBusinessKey("clearSignalTest").build(); - int instanceId = dao.insertWorkflowInstance(i); + long instanceId = dao.insertWorkflowInstance(i); dao.setSignal(instanceId, Optional.of(42), "testing", WorkflowActionType.externalChange); @@ -902,12 +902,12 @@ public void clearingSignalInsertsAction() { @Test public void deleteExpiredWorkflowHistory() { WorkflowInstance parentWorkflow = constructWorkflowInstanceBuilder().build(); - int parentWorkflowId = dao.insertWorkflowInstance(parentWorkflow); - int addChildActionId = addWorkflowAction(parentWorkflowId, new WorkflowInstance.Builder(parentWorkflow).build(), now(), + long parentWorkflowId = dao.insertWorkflowInstance(parentWorkflow); + long addChildActionId = addWorkflowAction(parentWorkflowId, new WorkflowInstance.Builder(parentWorkflow).build(), now(), now()); WorkflowInstance childWorkflow = constructWorkflowInstanceBuilder().setParentWorkflowId(parentWorkflowId) .setParentActionId(addChildActionId).build(); - int childWorkflowId = dao.insertWorkflowInstance(childWorkflow); + long childWorkflowId = dao.insertWorkflowInstance(childWorkflow); addWorkflowAction(parentWorkflowId, new WorkflowInstance.Builder(parentWorkflow).putStateVariable("variable", "deletedValue").build(), now(), now().minusDays(1)); @@ -936,8 +936,8 @@ private static void checkSameWorkflowInfo(WorkflowInstance i1, WorkflowInstance assertTrue(i2.stateVariables.containsKey(entry.getKey())); assertThat(i2.stateVariables.get(entry.getKey()), equalTo(entry.getValue())); } - for (Entry> entry : i1.childWorkflows.entrySet()) { - Integer key = entry.getKey(); + for (Entry> entry : i1.childWorkflows.entrySet()) { + Long key = entry.getKey(); assertTrue(i2.childWorkflows.containsKey(key)); assertThat(i2.childWorkflows.get(key), is(entry.getValue())); } @@ -945,20 +945,15 @@ private static void checkSameWorkflowInfo(WorkflowInstance i1, WorkflowInstance assertThat(i1.started, equalTo(i2.started)); } - private int addWorkflowAction(int workflowId, final WorkflowInstance instance, DateTime started, DateTime ended) { + private long addWorkflowAction(long workflowId, final WorkflowInstance instance, DateTime started, DateTime ended) { final WorkflowInstanceAction action = new WorkflowInstanceAction.Builder().setExecutionStart(started).setExecutorId(42) .setExecutionEnd(ended).setRetryNo(1).setType(stateExecution).setState("test").setStateText("state text") .setWorkflowInstanceId(workflowId).build(); - int actionId = transaction.execute(new TransactionCallback() { - @Override - public Integer doInTransaction(TransactionStatus status) { - return dao.insertWorkflowInstanceAction(instance, action); - } - }); + long actionId = transaction.execute((TransactionCallback) status -> dao.insertWorkflowInstanceAction(instance, action)); return actionId; } - private int addSubWorkflow(int parentWorkflowId, int parentActionId) { + private long addSubWorkflow(long parentWorkflowId, long parentActionId) { final WorkflowInstance subWorkflow = constructWorkflowInstanceBuilder().setParentWorkflowId(parentWorkflowId) .setParentActionId(parentActionId).build(); return dao.insertWorkflowInstance(subWorkflow); diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/BaseNflowTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/BaseNflowTest.java index 1c3d6d0a7..a42bce86d 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/BaseNflowTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/BaseNflowTest.java @@ -37,7 +37,7 @@ protected WorkflowInstance.Builder constructWorkflowInstanceBuilder() { .setSignal(Optional.of(42)); } - protected WorkflowInstanceAction.Builder constructActionBuilder(int workflowInstanceID) { + protected WorkflowInstanceAction.Builder constructActionBuilder(long workflowInstanceID) { return new WorkflowInstanceAction.Builder() // .setExecutionStart(DateTime.now()) // .setExecutorId(42) // @@ -50,6 +50,6 @@ protected WorkflowInstanceAction.Builder constructActionBuilder(int workflowInst } protected WorkflowInstance.Builder executingInstanceBuilder() { - return constructWorkflowInstanceBuilder().setId(1).setStatus(executing); + return constructWorkflowInstanceBuilder().setId(1L).setStatus(executing); } } diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowDispatcherTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowDispatcherTest.java index ec14d1bc1..9eb85ad7a 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowDispatcherTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowDispatcherTest.java @@ -106,9 +106,9 @@ public void exceptionDuringDispatcherExecutionCausesRetry() throws Throwable { @SuppressWarnings("unused") class ExceptionDuringDispatcherExecutionCausesRetry extends MultithreadedTestCase { public void threadDispatcher() { - when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())).thenReturn(ids(1)) + when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())).thenReturn(ids(1L)) .thenThrow(new RuntimeException("Expected: exception during dispatcher execution")) - .thenAnswer(waitForTickAndAnswer(2, ids(2), this)); + .thenAnswer(waitForTickAndAnswer(2, ids(2L), this)); WorkflowStateProcessor fakeWorkflowExecutor = fakeWorkflowExecutor(1, noOpRunnable()); when(executorFactory.createProcessor(1)).thenReturn(fakeWorkflowExecutor); WorkflowStateProcessor fakeWorkflowExecutor2 = fakeWorkflowExecutor(2, noOpRunnable()); @@ -137,7 +137,7 @@ public void errorDuringDispatcherExecutionStopsDispatcher() throws Throwable { @SuppressWarnings("unused") class ErrorDuringDispatcherExecutionStopsDispatcher extends MultithreadedTestCase { public void threadDispatcher() { - when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())).thenThrow(new AssertionError()).thenReturn(ids(1)); + when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())).thenThrow(new AssertionError()).thenReturn(ids(1L)); try { dispatcher.run(); Assertions.fail("Error should stop the dispatcher"); @@ -185,7 +185,7 @@ public void shutdownBlocksUntilPoolShutdown() throws Throwable { @SuppressWarnings("unused") class ShutdownBlocksUntilPoolShutdown extends MultithreadedTestCase { public void threadDispatcher() { - when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())).thenAnswer(waitForTickAndAnswer(2, ids(1), this)); + when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())).thenAnswer(waitForTickAndAnswer(2, ids(1L), this)); WorkflowStateProcessor fakeWorkflowExecutor = fakeWorkflowExecutor(1, waitForTickRunnable(3, this)); when(executorFactory.createProcessor(anyInt())).thenReturn(fakeWorkflowExecutor); dispatcher.run(); @@ -224,7 +224,7 @@ public void threadDispatcher() { public Object answer(InvocationOnMock invocation) throws Throwable { waitForTick(2); getThreadByName("threadShutdown").interrupt(); - return ids(1); + return ids(1L); } }); WorkflowStateProcessor fakeWorkflowExecutor = fakeWorkflowExecutor(1, waitForTickRunnable(3, this)); @@ -303,7 +303,7 @@ public void dispatcherLogsWarningWhenAllThreadsArePotentiallyStuck() throws Thro class DispatcherLogsWarning extends MultithreadedTestCase { public void threadDispatcher() throws InterruptedException { when(workflowInstances.pollNextWorkflowInstanceIds(anyInt())) - .thenAnswer(waitForTickAndAnswer(2, Collections. emptyList(), this)); + .thenAnswer(waitForTickAndAnswer(2, Collections.emptyList(), this)); when(executorFactory.getPotentiallyStuckProcessors()).thenReturn(executor.getThreadCount()); dispatcher.run(); } @@ -358,9 +358,9 @@ public void run() { }; } - WorkflowStateProcessor fakeWorkflowExecutor(int instanceId, final Runnable fakeCommand) { + WorkflowStateProcessor fakeWorkflowExecutor(long instanceId, final Runnable fakeCommand) { return new WorkflowStateProcessor(instanceId, null, null, null, null, null, env, - new ConcurrentHashMap(), (WorkflowExecutorListener) null) { + new ConcurrentHashMap<>(), (WorkflowExecutorListener) null) { @Override public void run() { fakeCommand.run(); @@ -368,7 +368,7 @@ public void run() { }; } - Answer> waitForTickAndAnswer(final int tick, final List answer, final MultithreadedTestCase mtc) { + Answer> waitForTickAndAnswer(final int tick, final List answer, final MultithreadedTestCase mtc) { return invocation -> { mtc.waitForTick(tick); return answer; @@ -383,7 +383,7 @@ protected BlockingQueue createQueue(int queueCapacity) { } } - static List ids(Integer... ids) { + static List ids(Long... ids) { return asList(ids); } } diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactoryTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactoryTest.java index c54c00a3d..e48af1268 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactoryTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorFactoryTest.java @@ -73,8 +73,8 @@ public void checkIfStateProcessorsAreStuckLogsLongRunningInstance() { WorkflowStateProcessor executor2 = mock(WorkflowStateProcessor.class); when(executor1.getStartTimeSeconds()).thenReturn(currentTimeMillis() / 1000 - STUCK_THREAD_THRESHOLD - 1); when(executor2.getStartTimeSeconds()).thenReturn(currentTimeMillis() / 1000 - STUCK_THREAD_THRESHOLD); - factory.processingInstances.put(111, executor1); - factory.processingInstances.put(222, executor2); + factory.processingInstances.put(111L, executor1); + factory.processingInstances.put(222L, executor2); int potentiallyStuckProcessors = factory.getPotentiallyStuckProcessors(); diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorTest.java index 191d3f3c3..22b0a78b8 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/executor/WorkflowStateProcessorTest.java @@ -158,7 +158,7 @@ public class WorkflowStateProcessorTest extends BaseNflowTest { static WorkflowInstance newWorkflow = mock(WorkflowInstance.class); - static Map processingInstances; + static Map processingInstances; private final TestWorkflow testWorkflowDef = new TestWorkflow(); @@ -421,12 +421,12 @@ public void doNothingWhenNotifyingParentWithoutParentWorkflowId() { executor.run(); - verify(workflowInstanceDao, never()).wakeUpWorkflowExternally(any(Integer.class), any(List.class)); + verify(workflowInstanceDao, never()).wakeUpWorkflowExternally(any(Long.class), any(List.class)); } @Test public void whenWakingUpParentWorkflowSucceeds() { - WorkflowInstance instance = executingInstanceBuilder().setParentWorkflowId(999).setType("wake-test").setState("wakeParent") + WorkflowInstance instance = executingInstanceBuilder().setParentWorkflowId(999L).setType("wake-test").setState("wakeParent") .build(); when(workflowInstances.getWorkflowInstance(instance.id, INCLUDES, null)).thenReturn(instance); when(workflowInstanceDao.getWorkflowInstanceType(instance.parentWorkflowId)).thenReturn("parentType"); @@ -443,7 +443,7 @@ public void whenWakingUpParentWorkflowSucceeds() { @Test public void whenWakingUpParentWorkflowFails() { - WorkflowInstance instance = executingInstanceBuilder().setParentWorkflowId(999).setType("wake-test").setState("wakeParent") + WorkflowInstance instance = executingInstanceBuilder().setParentWorkflowId(999L).setType("wake-test").setState("wakeParent") .build(); when(workflowInstances.getWorkflowInstance(instance.id, INCLUDES, null)).thenReturn(instance); when(workflowInstanceDao.getWorkflowInstanceType(instance.parentWorkflowId)).thenReturn("parentType"); @@ -460,7 +460,7 @@ public void whenWakingUpParentWorkflowFails() { @Test public void finishingChildWakesParentAutomaticallyWhenParentIsInWaitState() { - WorkflowInstance instance = executingInstanceBuilder().setParentWorkflowId(999).setType("simple-test").setState("processing") + WorkflowInstance instance = executingInstanceBuilder().setParentWorkflowId(999L).setType("simple-test").setState("processing") .build(); when(workflowInstances.getWorkflowInstance(instance.id, INCLUDES, null)).thenReturn(instance); when(workflowInstanceDao.getWorkflowInstanceType(instance.parentWorkflowId)).thenReturn(BulkWorkflow.BULK_WORKFLOW_TYPE); diff --git a/nflow-engine/src/test/java/io/nflow/engine/internal/workflow/StateExecutionImplTest.java b/nflow-engine/src/test/java/io/nflow/engine/internal/workflow/StateExecutionImplTest.java index fa1ea3364..1a9a8a8c6 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/internal/workflow/StateExecutionImplTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/internal/workflow/StateExecutionImplTest.java @@ -58,7 +58,7 @@ public class StateExecutionImplTest { @BeforeEach public void setup() { - instance = new WorkflowInstance.Builder().setId(99).setExternalId("ext").setRetries(88).setState("myState") + instance = new WorkflowInstance.Builder().setId(99L).setExternalId("ext").setRetries(88).setState("myState") .setBusinessKey("business").build(); execution = createExecution(instance); executionInterface = execution; @@ -101,8 +101,8 @@ public void addWorkflows() { @Test public void wakeUpParentWorkflowSetsWakeUpStates() { - instance = new WorkflowInstance.Builder().setId(99).setExternalId("ext").setRetries(88).setState("myState") - .setBusinessKey("business").setParentWorkflowId(123).build(); + instance = new WorkflowInstance.Builder().setId(99L).setExternalId("ext").setRetries(88).setState("myState") + .setBusinessKey("business").setParentWorkflowId(123L).build(); execution = createExecution(instance); assertThat(execution.getWakeUpParentWorkflowStates().isPresent(), is(false)); execution.wakeUpParentWorkflow(); @@ -120,7 +120,7 @@ public void nonChildWorkflowCannotWakeUpParent() { @Test public void queryChildWorkflowsIsRestrictedToChildsOfCurrentWorkflow() { QueryWorkflowInstances query = new QueryWorkflowInstances.Builder() - .setParentActionId(42).addTypes("a","b") + .setParentActionId(42L).addTypes("a","b") .setBusinessKey("123").build(); List result = singletonList(mock(WorkflowInstance.class)); @@ -254,7 +254,7 @@ public void getParentIdReturnsEmptyWhenParentWorkflowIdIsNull() { @Test public void getParentIdReturnsParentWorkflowId() { - instance = new WorkflowInstance.Builder().setParentWorkflowId(42).build(); + instance = new WorkflowInstance.Builder().setParentWorkflowId(42L).build(); execution = createExecution(instance); assertThat(execution.getParentId(), is(Optional.of(42))); @@ -291,7 +291,7 @@ public void exceedingMaxRetriesInErrorStateStopsProcessing() { @Test public void handleRetryAfterSetsActivationWhenMaxRetriesIsNotExceeded() { TestWorkflow def = new TestWorkflow(); - instance = new WorkflowInstance.Builder().setId(99).setExternalId("ext") + instance = new WorkflowInstance.Builder().setId(99L).setExternalId("ext") .setState(TestWorkflow.State.startWithoutFailure.name()).setBusinessKey("business").build(); execution = createExecution(instance); @@ -303,7 +303,7 @@ public void handleRetryAfterSetsActivationWhenMaxRetriesIsNotExceeded() { private void handleRetryMaxRetriesExceeded(TestDefinition.TestState initialState, TestDefinition.TestState currentState) { TestDefinition def = new TestDefinition("x", initialState); - instance = new WorkflowInstance.Builder().setId(99).setExternalId("ext").setRetries(88).setState(currentState.name()) + instance = new WorkflowInstance.Builder().setId(99L).setExternalId("ext").setRetries(88).setState(currentState.name()) .setBusinessKey("business").build(); execution = createExecution(instance); execution.handleRetryAfter(tomorrow, def); diff --git a/nflow-engine/src/test/java/io/nflow/engine/service/ArchiveServiceTest.java b/nflow-engine/src/test/java/io/nflow/engine/service/ArchiveServiceTest.java index 98fbd054c..a0734ca83 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/service/ArchiveServiceTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/service/ArchiveServiceTest.java @@ -29,8 +29,8 @@ public class ArchiveServiceTest { @Mock private ArchiveDao dao; private final DateTime limit = new DateTime(2015, 7, 10, 19, 57, 0, 0); - private final List emptyList = Collections.emptyList(); - private final List dataList = Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + private final List emptyList = Collections.emptyList(); + private final List dataList = Arrays.asList(1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L); @BeforeEach public void setup() { diff --git a/nflow-engine/src/test/java/io/nflow/engine/service/WorkflowInstanceServiceTest.java b/nflow-engine/src/test/java/io/nflow/engine/service/WorkflowInstanceServiceTest.java index d0c76a505..834e7da57 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/service/WorkflowInstanceServiceTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/service/WorkflowInstanceServiceTest.java @@ -88,7 +88,7 @@ public void getWorkflowInstance() { public void insertWorkflowInstanceWorks() { WorkflowInstance i = constructWorkflowInstanceBuilder().setStatus(created).setExternalId("123").setState(null).build(); when(workflowInstancePreProcessor.process(i)).thenReturn(i); - when(workflowInstanceDao.insertWorkflowInstance(stored.capture())).thenReturn(42); + when(workflowInstanceDao.insertWorkflowInstance(stored.capture())).thenReturn(42L); assertThat(service.insertWorkflowInstance(i), is(42)); assertThat(stored.getValue().externalId, is("123")); assertThat(stored.getValue().status, is(created)); @@ -104,11 +104,11 @@ public void insertWorkflowInstanceWhenPreprocessorThrowsCausesException() { @Test public void updateWorkflowInstanceWorks() { - WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42).build(); + WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42L).build(); WorkflowInstanceAction a = new WorkflowInstanceAction.Builder().setType(externalChange).setWorkflowInstanceId(i.id).build(); when(workflowInstanceDao.getWorkflowInstanceState(i.id)).thenReturn("currentState"); when(workflowInstanceDao.updateNotRunningWorkflowInstance(any(WorkflowInstance.class))).thenReturn(true); - when(workflowInstanceDao.getWorkflowInstanceType(42)).thenReturn(i.type); + when(workflowInstanceDao.getWorkflowInstanceType(42L)).thenReturn(i.type); assertThat(service.updateWorkflowInstance(i, a), is(true)); verify(workflowInstanceDao).updateNotRunningWorkflowInstance(stored.capture()); assertThat(stored.getValue().status, is(inProgress)); @@ -118,7 +118,7 @@ public void updateWorkflowInstanceWorks() { @Test public void updateWorkflowInstanceThrowsExceptionWhenActionIsNull() { - WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42).build(); + WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42L).build(); WorkflowInstanceAction a = null; IllegalArgumentException thrown = assertThrows(IllegalArgumentException.class, () -> service.updateWorkflowInstance(i, a)); assertThat(thrown.getMessage(), is("Workflow instance action can not be null")); @@ -126,7 +126,7 @@ public void updateWorkflowInstanceThrowsExceptionWhenActionIsNull() { @Test public void updateWorkflowInstanceWorksWhenStateIsNull() { - WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42).setState(null).build(); + WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42L).setState(null).build(); WorkflowInstanceAction a = new WorkflowInstanceAction.Builder().setType(externalChange).setWorkflowInstanceId(i.id).build(); when(workflowInstanceDao.getWorkflowInstanceState(i.id)).thenReturn("currentState"); when(workflowInstanceDao.updateNotRunningWorkflowInstance(any(WorkflowInstance.class))).thenReturn(true); @@ -139,10 +139,10 @@ public void updateWorkflowInstanceWorksWhenStateIsNull() { @Test public void updateRunningWorkflowInstanceFails() { - WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42).build(); + WorkflowInstance i = constructWorkflowInstanceBuilder().setId(42L).build(); WorkflowInstanceAction a = new WorkflowInstanceAction.Builder().setType(externalChange).build(); when(workflowInstanceDao.updateNotRunningWorkflowInstance(i)).thenReturn(false); - when(workflowInstanceDao.getWorkflowInstanceType(42)).thenReturn(i.type); + when(workflowInstanceDao.getWorkflowInstanceType(42L)).thenReturn(i.type); assertThat(service.updateWorkflowInstance(i, a), is(false)); verify(workflowInstanceDao, never()).insertWorkflowInstanceAction(any(WorkflowInstance.class), any(WorkflowInstanceAction.class)); diff --git a/nflow-engine/src/test/java/io/nflow/engine/workflow/executor/WorkflowLogContextListenerTest.java b/nflow-engine/src/test/java/io/nflow/engine/workflow/executor/WorkflowLogContextListenerTest.java index 397736c75..c2b9fa58e 100644 --- a/nflow-engine/src/test/java/io/nflow/engine/workflow/executor/WorkflowLogContextListenerTest.java +++ b/nflow-engine/src/test/java/io/nflow/engine/workflow/executor/WorkflowLogContextListenerTest.java @@ -46,7 +46,7 @@ void beforeProcessingWithStateVariables() { Map vars = new HashMap<>(); vars.put("foo", "bar"); Map stateVariables = spy(vars); - WorkflowInstance instance = new WorkflowInstance.Builder().setType("type").setId(1).setExternalId("extId") + WorkflowInstance instance = new WorkflowInstance.Builder().setType("type").setId(1L).setExternalId("extId") .setBusinessKey("businessKey").setStateVariables(stateVariables).build(); ListenerContext context = new ListenerContext(definition, instance, stateExecution); @@ -60,7 +60,7 @@ void beforeProcessingWithStateVariables() { void beforeProcessingWithoutStateVariables() { MDC.clear(); Map stateVariables = spy(new HashMap()); - WorkflowInstance instance = new WorkflowInstance.Builder().setType("type").setId(1).setExternalId("extId") + WorkflowInstance instance = new WorkflowInstance.Builder().setType("type").setId(1L).setExternalId("extId") .setBusinessKey("businessKey").setStateVariables(stateVariables).build(); ListenerContext context = new ListenerContext(definition, instance, stateExecution);