mirror of
https://github.com/Kingsrook/qqq.git
synced 2025-07-18 13:10:44 +00:00
Add method to let some lower-level actions try to generically update counts, but not to go lower than original counts were.
This commit is contained in:
@ -95,6 +95,23 @@ public class AsyncJobCallback
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
** Update the current and total fields, but ONLY if the new values are
|
||||||
|
** both >= the previous values.
|
||||||
|
*******************************************************************************/
|
||||||
|
public void updateStatusOnlyUpwards(int current, int total)
|
||||||
|
{
|
||||||
|
boolean currentIsOkay = (this.asyncJobStatus.getCurrent() == null || this.asyncJobStatus.getCurrent() <= current);
|
||||||
|
boolean totalIsOkay = (this.asyncJobStatus.getTotal() == null || this.asyncJobStatus.getTotal() <= total);
|
||||||
|
|
||||||
|
if(currentIsOkay && totalIsOkay)
|
||||||
|
{
|
||||||
|
updateStatus(current, total);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
** Increase the 'current' value in the '1 of 2' sense.
|
** Increase the 'current' value in the '1 of 2' sense.
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
|
@ -84,4 +84,36 @@ class AsyncJobCallbackTest extends BaseTest
|
|||||||
assertEquals(3, asyncJobStatus.getCurrent());
|
assertEquals(3, asyncJobStatus.getCurrent());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*******************************************************************************
|
||||||
|
**
|
||||||
|
*******************************************************************************/
|
||||||
|
@Test
|
||||||
|
void testUpdateStatusOnlyUpwards()
|
||||||
|
{
|
||||||
|
AsyncJobStatus asyncJobStatus = new AsyncJobStatus();
|
||||||
|
AsyncJobCallback asyncJobCallback = new AsyncJobCallback(UUID.randomUUID(), asyncJobStatus);
|
||||||
|
|
||||||
|
asyncJobCallback.updateStatusOnlyUpwards(10, 100);
|
||||||
|
assertEquals(10, asyncJobStatus.getCurrent());
|
||||||
|
assertEquals(100, asyncJobStatus.getTotal());
|
||||||
|
|
||||||
|
asyncJobCallback.updateStatusOnlyUpwards(5, 100);
|
||||||
|
assertEquals(10, asyncJobStatus.getCurrent());
|
||||||
|
assertEquals(100, asyncJobStatus.getTotal());
|
||||||
|
|
||||||
|
asyncJobCallback.updateStatusOnlyUpwards(11, 99);
|
||||||
|
assertEquals(10, asyncJobStatus.getCurrent());
|
||||||
|
assertEquals(100, asyncJobStatus.getTotal());
|
||||||
|
|
||||||
|
asyncJobCallback.updateStatusOnlyUpwards(11, 100);
|
||||||
|
assertEquals(11, asyncJobStatus.getCurrent());
|
||||||
|
assertEquals(100, asyncJobStatus.getTotal());
|
||||||
|
|
||||||
|
asyncJobCallback.updateStatusOnlyUpwards(11, 101);
|
||||||
|
assertEquals(11, asyncJobStatus.getCurrent());
|
||||||
|
assertEquals(101, asyncJobStatus.getTotal());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue
Block a user