Skip to content

Commit

Permalink
Merge pull request #951 from ashitsalesforce/master
Browse files Browse the repository at this point in the history
show load/extract rates in minutes and seconds
  • Loading branch information
ashitsalesforce authored Jan 20, 2024
2 parents a26e4bb + 5a2401b commit fee014c
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public class NihilistProgressAdapter implements ILoaderProgress {
private int numRowsWithError = 0;
private int numberBatchesTotal = 0;
private final Logger logger = LogManager.getLogger(getClass());
private String taskName;
private int workDone;
private int totalWork;
private final List<String> subTasksInOrder = new ArrayList<String>();
Expand All @@ -60,7 +59,6 @@ public NihilistProgressAdapter() {
}

public void beginTask(String name, int totalWork) {
this.taskName = name;
this.totalWork = totalWork;
}

Expand All @@ -80,18 +78,10 @@ public void worked(int worked) {
this.workDone += worked;
}

public void setTaskName(String name) {
this.taskName = name;
}

public void setSubTask(String name) {
this.subTasksInOrder.add(name);
logger.info(name);
}

public String getTaskName() {
return this.taskName;
}

public int getTotalWork() {
return this.totalWork;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,6 @@ public void worked(int worked) {
monitor.worked(worked);
}

/*
* (non-Javadoc)
*
* @see com.sfdc.action.progress.ILoaderProgress#setTaskName(java.lang.String)
*/
public void setTaskName(String name) {
super.setTaskName(name);
monitor.setTaskName(name);
}

/*
* (non-Javadoc)
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public String calculateSubTask(long processedRecordsInJob, long numErrorsInJob)
long hourlyProcessingRate;

final long totalElapsedTimeInSec = (currentLoadTime.getTime() - this.startTime.getTime())/1000;
final long elapsedTimeInMinutes = totalElapsedTimeInSec / 60;
if (totalElapsedTimeInSec == 0) {
hourlyProcessingRate = 0;
} else {
Expand All @@ -89,7 +90,7 @@ public String calculateSubTask(long processedRecordsInJob, long numErrorsInJob)
numSuccessInJob, // {2}
numErrorsInJob); // {3}
}
// LoadRateCalculator.processed=Processed {0} of {1} total records in {7} seconds.
// LoadRateCalculator.processed=Processed {0} of {1} total records in {8} minutes, {7} seconds.
// There are {5} successes and {6} errors. \nRate: {2} records per hour.
// Estimated time to complete: {3} minutes and {4} seconds.
return Messages.getMessage(getClass(), "processed",
Expand All @@ -100,7 +101,8 @@ public String calculateSubTask(long processedRecordsInJob, long numErrorsInJob)
remainingSeconds, // {4}
numSuccessInJob, // {5}
numErrorsInJob, // {6}
totalElapsedTimeInSec // {7}
totalElapsedTimeInSec - (60 * elapsedTimeInMinutes), // {7}
elapsedTimeInMinutes // {8}
);
}
}
10 changes: 5 additions & 5 deletions src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ Process.aboutPerform=About to perform: {0}
Process.missingRequiredArg=Missing required argument: {0}
Action.loading=Loading: {0}
Action.logCanceled=Load was canceled.
Action.exception=Exception occured during loading
Action.exception=Exception occurred during loading
Action.logSuccess=Load completed successfully.
Action.success=The operation has fully completed. There were {0} successful {1}s and {2} errors.
AbstractExtractAction.success=The operation has fully completed. There were {0} successful extractions and {2} errors.
Action.cancel=The operation was cancelled. There were {0} successful {1}s and {2} errors.
Action.error=Load finished with an error. Please check the log.
Action.errorDaoStartRow=Can't read from dao when calulating start row
Action.errorDaoStartRow=Can't read from DAO when calculating start row
Action.errorLastRun=Can't save last run info
RowToStartUtil.errorDaoStartRow=Can't read from dao when calculating start row
RowToStartUtil.errorDaoStartRow=Can't read from DAO when calculating start row
RowToStartUtil.errorLastRun=Can't save last run info
Action.errorOpeningErrorFile=Error opening error status file: {0}
Action.errorOpeningSuccessFile=Error opening success status file: {0}
Expand Down Expand Up @@ -63,8 +63,8 @@ AbstractExtractAction.errorMissingFrom=Error in query: missing [ from ]: {0}
AbstractExtractAction.errorInvalidFieldName=Error in query: invalid field name [{0}] in query string: {1}
AbstractExtractAction.errorMalformedQuery=Error in query: Malformed query string: {0}
AbstractExtractAction.errorEmptyQuery=Error in query: query is empty
LoadRateCalculator.processed=Processed {0} of {1} total records in {7} seconds. There are {5} successes and {6} errors. \nRate: {2} records per hour. Estimated time to complete: {3} minutes and {4} seconds.
LoadRateCalculator.processedTimeUnknown=Processed {0} of {1} total records. There are {2} successes and {3} errors.
LoadRateCalculator.processed=Processed {0} of {1} records in {8} minutes, {7} seconds with {5} successes and {6} errors. \nRate: {2} records per hour. Estimated remaining time to complete: {3} minutes and {4} seconds.
LoadRateCalculator.processedTimeUnknown=Processed {0} of {1} records with {2} successes and {3} errors.
Visitor.emptyRowIgnored=Item #: {0} will not be loaded due to the empty input data
Visitor.conversionException=Conversion Exception, writing to errors.csv
Visitor.conversionErrorMsg=Error converting value to correct data type: {0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void testRateCalculatorZeroCompletion() {
rateCalculator.start(3600);
String message = rateCalculator.calculateSubTask(0, 0);
assertEquals("incorrect rate calculation: ",
"Processed 0 of 3,600 total records. There are 0 successes and 0 errors.",
"Processed 0 of 3,600 records with 0 successes and 0 errors.",
message);

}
Expand All @@ -55,7 +55,8 @@ public void testRateCalculatorFirstBatchCompletion() {
e.printStackTrace();
}
message = rateCalculator.calculateSubTask(1, 0);
boolean success = message.contains("There are 1 successes and 0 errors. \nRate: 3,600 records per hour.");
boolean success = message.contains("1 successes and 0 errors")
&& message.contains("Rate: 3,600 records per hour");
assertTrue("incorrect rate calculation: ", success);
}

Expand All @@ -79,8 +80,8 @@ public void testRateCalculatorMultiBatchCompletion() {
e.printStackTrace();
}
message = rateCalculator.calculateSubTask(2, 1);
boolean success = message.contains("Processed 2 of 3,600 total records in 2 seconds. There are 1 successes and 1 errors. \nRate: 3,600 records per hour.");
assertTrue("incorrect rate calculation: ", success);
boolean success = message.contains("Processed 2 of 3,600 records in 0 minutes, 2 seconds with 1 successes and 1 errors. \nRate: 3,600 records per hour.");
assertTrue("incorrect rate calculation - " + message, success);

rateCalculator.start(3600);
try {
Expand All @@ -90,8 +91,11 @@ public void testRateCalculatorMultiBatchCompletion() {
e.printStackTrace();
}
message = rateCalculator.calculateSubTask(3, 1);
success = message.contains("Processed 3 of 3,600 total records in 3 seconds. There are 2 successes and 1 errors. \nRate: 3,600 records per hour.");
assertTrue("incorrect rate calculation: ", success);
success = message.contains("Processed 3 of 3,600 records")
&& message.contains("0 minutes, 3 seconds")
&& message.contains("2 successes and 1 errors")
&& message.contains("Rate: 3,600 records per hour");
assertTrue("incorrect rate calculation - " + message, success);

rateCalculator.start(3600);
try {
Expand All @@ -101,19 +105,26 @@ public void testRateCalculatorMultiBatchCompletion() {
e.printStackTrace();
}
message = rateCalculator.calculateSubTask(4, 1);
success = message.contains("Processed 4 of 3,600 total records in 4 seconds. There are 3 successes and 1 errors. \nRate: 3,600 records per hour.");
assertTrue("incorrect rate calculation: ", success);
success = message.contains("Processed 4 of 3,600 records")
&& message.contains("0 minutes, 4 seconds")
&& message.contains("3 successes and 1 errors")
&& message.contains("Rate: 3,600 records per hour");
assertTrue("incorrect rate calculation - " + message, success);

rateCalculator.start(3600);
try {
Thread.sleep(3000);
Thread.sleep(63000); // sleep for a minute
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
message = rateCalculator.calculateSubTask(7, 2);
success = message.contains("Processed 7 of 3,600 total records in 7 seconds. There are 5 successes and 2 errors. \nRate: 3,600 records per hour.");
assertTrue("incorrect rate calculation: ", success);
success = message.contains("Processed 7 of 3,600 records in 1 minutes, 7 seconds with 5 successes and 2 errors. \nRate: 376 records per hour.");
success = message.contains("Processed 7 of 3,600 records")
&& message.contains("1 minutes, 7 seconds")
&& message.contains("5 successes and 2 errors")
&& message.contains("Rate: 376 records per hour");
assertTrue("incorrect rate calculation - " + message, success);
}

@Test
Expand All @@ -129,8 +140,8 @@ public void testRateCalculatorLongTimeForCompletion() {
}
message = rateCalculator.calculateSubTask(1, 0);
assertEquals("incorrect rate calculation: ",
"Processed 1 of 999,999,999 total records. "
+ "There are 1 successes and 0 errors.",
"Processed 1 of 999,999,999 records with 1 successes and 0 errors.",
message);
}

}

0 comments on commit fee014c

Please sign in to comment.