git push origin develop

This commit is contained in:
Vishwas Babu A J
2015-03-16 02:26:49 +05:30
parent 2a800bf367
commit 7fcdb77f36
2 changed files with 37 additions and 24 deletions
@@ -61,7 +61,7 @@ public class ConcurrencyIntegrationTest {
Calendar date = Calendar.getInstance(); Calendar date = Calendar.getInstance();
date.set(2011, 9, 20); date.set(2011, 9, 20);
Float repaymentAmount = 100.0f; Float repaymentAmount = 100.0f;
for (int i = 0; i < 5; i++) { for (int i = 0; i < 10; i++) {
System.out.println("Starting concurrent transaction number " + i); System.out.println("Starting concurrent transaction number " + i);
date.add(Calendar.DAY_OF_MONTH, 1); date.add(Calendar.DAY_OF_MONTH, 1);
repaymentAmount = repaymentAmount + 100; repaymentAmount = repaymentAmount + 100;
@@ -20,6 +20,8 @@ import org.mifosplatform.infrastructure.core.serialization.FromJsonHelper;
import org.mifosplatform.infrastructure.jobs.service.SchedulerJobRunnerReadService; import org.mifosplatform.infrastructure.jobs.service.SchedulerJobRunnerReadService;
import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext; import org.mifosplatform.infrastructure.security.service.PlatformSecurityContext;
import org.mifosplatform.useradministration.domain.AppUser; import org.mifosplatform.useradministration.domain.AppUser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.CannotAcquireLockException; import org.springframework.dao.CannotAcquireLockException;
import org.springframework.orm.ObjectOptimisticLockingFailureException; import org.springframework.orm.ObjectOptimisticLockingFailureException;
@@ -36,6 +38,7 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
private final FromJsonHelper fromApiJsonHelper; private final FromJsonHelper fromApiJsonHelper;
private final CommandProcessingService processAndLogCommandService; private final CommandProcessingService processAndLogCommandService;
private final SchedulerJobRunnerReadService schedulerJobRunnerReadService; private final SchedulerJobRunnerReadService schedulerJobRunnerReadService;
private final static Logger logger = LoggerFactory.getLogger(PortfolioCommandSourceWritePlatformServiceImpl.class);
@Autowired @Autowired
public PortfolioCommandSourceWritePlatformServiceImpl(final PlatformSecurityContext context, public PortfolioCommandSourceWritePlatformServiceImpl(final PlatformSecurityContext context,
@@ -71,22 +74,29 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
JsonCommand command = null; JsonCommand command = null;
Integer numberOfRetries = 1; Integer numberOfRetries = 1;
Integer maxNumberOfRetries = 10; Integer maxNumberOfRetries = 10;
try {
final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json); final JsonElement parsedCommand = this.fromApiJsonHelper.parse(json);
command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(), command = JsonCommand.from(json, parsedCommand, this.fromApiJsonHelper, wrapper.getEntityName(), wrapper.getEntityId(),
wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getSavingsId(), wrapper.getSubentityId(), wrapper.getGroupId(), wrapper.getClientId(), wrapper.getLoanId(), wrapper.getSavingsId(),
wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId()); wrapper.getTransactionId(), wrapper.getHref(), wrapper.getProductId());
while (numberOfRetries < maxNumberOfRetries) {
try {
result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker); result = this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker);
} catch (final RollbackTransactionAsCommandIsNotApprovedByCheckerException e) { numberOfRetries = maxNumberOfRetries;
result = this.processAndLogCommandService.logCommand(e.getCommandSourceResult());
} catch (CannotAcquireLockException | ObjectOptimisticLockingFailureException exception) { } catch (CannotAcquireLockException | ObjectOptimisticLockingFailureException exception) {
System.out.println("Number of times this transaction has been retried " + numberOfRetries); logger.warn("The following command " + command.json() + " has been retried for the " + numberOfRetries + " time");
/***
* Fail if the transaction has been retired for
* maxNumberOfRetries
**/
if (numberOfRetries >= maxNumberOfRetries) { if (numberOfRetries >= maxNumberOfRetries) {
System.out.println("This transaction is done for"); logger.warn("The following command " + command.json() + " has been retried for the max allowed attempts of "
+ numberOfRetries + " and will be rolled back");
throw (exception); throw (exception);
} }
/***
* Else sleep for a random time (between 1 to 10 seconds) and
* continue
**/
try { try {
Random random = new Random(); Random random = new Random();
int randomNum = random.nextInt(10) + 1; int randomNum = random.nextInt(10) + 1;
@@ -95,7 +105,10 @@ public class PortfolioCommandSourceWritePlatformServiceImpl implements Portfolio
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw (exception); throw (exception);
} }
this.processAndLogCommandService.processAndLogCommand(wrapper, command, isApprovedByChecker); } catch (final RollbackTransactionAsCommandIsNotApprovedByCheckerException e) {
result = this.processAndLogCommandService.logCommand(e.getCommandSourceResult());
}
} }
return result; return result;