Skip to content

Commit

Permalink
Switch priority in Java from int to short
Browse files Browse the repository at this point in the history
  • Loading branch information
ttiurani committed Nov 24, 2019
1 parent bf2d776 commit 190bace
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,8 @@ private long insertWorkflowInstanceWithCte(WorkflowInstance instance) {
}
}

private int getInstancePriority(WorkflowInstance instance) {
return instance.priority != null ? instance.priority.intValue() : 0;
private short getInstancePriority(WorkflowInstance instance) {
return instance.priority != null ? instance.priority.shortValue() : 0;
}

boolean useBatchUpdate() {
Expand Down Expand Up @@ -768,7 +768,7 @@ public WorkflowInstance.Builder mapRow(ResultSet rs, int rowNum) throws SQLExcep
.setParentActionId(getLong(rs, "parent_action_id")) //
.setStatus(WorkflowInstanceStatus.valueOf(rs.getString("status"))) //
.setType(rs.getString("type")) //
.setPriority(rs.getInt("priority")) //
.setPriority(rs.getShort("priority")) //
.setBusinessKey(rs.getString("business_key")) //
.setExternalId(rs.getString("external_id")) //
.setState(rs.getString("state")) //
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public enum WorkflowInstanceStatus {
/**
* The priority of the workflow instance. Defaults to 0 and can also be negative.
*/
public final Integer priority;
public final Short priority;

/**
* Business key.
Expand Down Expand Up @@ -241,7 +241,7 @@ public static class Builder {
Long parentActionId;
WorkflowInstanceStatus status;
String type;
Integer priority;
Short priority;
String businessKey;
String externalId;
String state;
Expand Down Expand Up @@ -379,11 +379,8 @@ public Builder setType(String type) {
* @param priority The priority.
* @return this.
*/
public Builder setPriority(Integer priority) {
this.priority = Integer.valueOf(priority.shortValue());
if (this.priority != priority) {
throw new IllegalArgumentException("Priority must be between -32768 and 32767");
}
public Builder setPriority(Short priority) {
this.priority = priority;
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,7 @@ public void fakePostgreSQLinsertWorkflowInstance() {
WorkflowInstance wf = new WorkflowInstance.Builder().setStatus(inProgress).setState("updateState").setStateText("update text")
.setRootWorkflowId(9283L).setParentWorkflowId(110L).setParentActionId(421L).setNextActivation(started.plusSeconds(1))
.setRetries(3).setId(43).putStateVariable("A", "B").putStateVariable("C", "D").setSignal(Optional.of(1))
.setStartedIfNotSet(started).setPriority(10).build();
.setStartedIfNotSet(started).setPriority((short)10).build();

d.insertWorkflowInstance(wf);
assertEquals(
Expand Down Expand Up @@ -646,9 +646,9 @@ public void pollNextWorkflowInstances() {

@Test
public void pollNextWorkflowInstancesReturnInstancesInCorrectOrder() {
int olderLowPrio = createInstance(2, 1);
int newerLowPrio = createInstance(1, 1);
int newerHighPrio = createInstance(1, 2);
int olderLowPrio = createInstance(2, (short)1);
int newerLowPrio = createInstance(1, (short)1);
int newerHighPrio = createInstance(1, (short)2);

// high priority comes first
List<Integer> ids = dao.pollNextWorkflowInstanceIds(1);
Expand All @@ -663,7 +663,7 @@ public void pollNextWorkflowInstancesReturnInstancesInCorrectOrder() {
assertThat(ids, is(asList(newerLowPrio)));
}

private int createInstance(int minutesInPast, int priority) {
private int createInstance(int minutesInPast, short priority) {
return dao.insertWorkflowInstance(constructWorkflowInstanceBuilder().setNextActivation(now().minusMinutes(minutesInPast))
.setPriority(priority).setExecutorGroup("junit").build());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class ListWorkflowInstanceResponse extends ModelObject {
public String type;

@ApiModelProperty(value = "Workflow instance priority", required = true)
public Integer priority;
public Short priority;

@ApiModelProperty("Parent workflow instance id for child workflows")
public Long parentWorkflowId;
Expand Down

0 comments on commit 190bace

Please sign in to comment.