mirror of
https://github.com/valitydev/liminator.git
synced 2024-11-06 01:15:21 +00:00
EMP-99: Fix duplicate values for limits (#25)
Some checks are pending
Deploy Docker Image / build-and-deploy (push) Waiting to run
Some checks are pending
Deploy Docker Image / build-and-deploy (push) Waiting to run
This commit is contained in:
parent
ebe67e383c
commit
d9c14074e8
@ -22,7 +22,6 @@ public class OperationStateHistoryConverterImpl implements OperationStateHistory
|
||||
.map(change -> {
|
||||
OperationStateHistory history = new OperationStateHistory();
|
||||
history.setOperationId(request.getOperationId());
|
||||
history.setLimitName(change.getLimitName());
|
||||
history.setLimitDataId(limitNamesMap.get(change.getLimitName()));
|
||||
history.setOperationValue(change.getValue());
|
||||
history.setState(state);
|
||||
|
@ -124,6 +124,7 @@ public class OperationStateHistoryDaoImpl implements OperationStateHistoryDao {
|
||||
.leftJoin(commitOps)
|
||||
.on(
|
||||
commitOps.OPERATION_ID.eq(holdOps.OPERATION_ID)
|
||||
.and(commitOps.LIMIT_DATA_ID.eq(holdOps.LIMIT_DATA_ID))
|
||||
.and(commitOps.STATE.in(OperationState.COMMIT))
|
||||
.and(operationId == null
|
||||
? DSL.trueCondition()
|
||||
@ -132,6 +133,7 @@ public class OperationStateHistoryDaoImpl implements OperationStateHistoryDao {
|
||||
.leftJoin(rollbackOps)
|
||||
.on(
|
||||
rollbackOps.OPERATION_ID.eq(holdOps.OPERATION_ID)
|
||||
.and(rollbackOps.LIMIT_DATA_ID.eq(holdOps.LIMIT_DATA_ID))
|
||||
.and(rollbackOps.STATE.in(OperationState.ROLLBACK))
|
||||
.and(operationId == null
|
||||
? DSL.trueCondition()
|
||||
|
@ -15,7 +15,7 @@ public class LimitValueMapper implements RecordMapper<Record, LimitValue> {
|
||||
@Override
|
||||
public LimitValue map(Record opsDataRecord) {
|
||||
String limitId = opsDataRecord.get(LIMIT_DATA.LIMIT_ID);
|
||||
String limitName = opsDataRecord.get(OPERATION_STATE_HISTORY.LIMIT_NAME);
|
||||
String limitName = opsDataRecord.get(LIMIT_DATA.NAME);
|
||||
Long operationValue = opsDataRecord.get(OPERATION_STATE_HISTORY.OPERATION_VALUE);
|
||||
OperationState state = OperationState.valueOf(opsDataRecord.get("state", String.class));
|
||||
return new LimitValue(limitId, limitName, state, operationValue);
|
||||
|
@ -0,0 +1 @@
|
||||
ALTER TABLE lim.operation_state_history drop COLUMN limit_name;
|
@ -211,7 +211,6 @@ class DaoTests {
|
||||
LocalDateTime createdAt,
|
||||
OperationState state) {
|
||||
OperationStateHistory operation = new OperationStateHistory();
|
||||
operation.setLimitName(limitName);
|
||||
operation.setLimitDataId(id);
|
||||
operation.setOperationId(operationId);
|
||||
operation.setState(state);
|
||||
|
@ -253,6 +253,62 @@ class LiminatorServiceTest {
|
||||
assertEquals(limitName, limitResponseAfterAllForFourthHold.get(0).getLimitName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void holdCommitFewValueTest() throws TException {
|
||||
String limitNameFirst = "TestLimitHold";
|
||||
String limitNameSecond = "TestLimitHold2";
|
||||
String limitNameThird = "TestLimitHold3";
|
||||
String operationId = "OpHold";
|
||||
LimitRequest holdRequest = new LimitRequest()
|
||||
.setOperationId(operationId)
|
||||
.setLimitChanges(List.of(
|
||||
new LimitChange(limitNameFirst, 500L),
|
||||
new LimitChange(limitNameSecond, 500L),
|
||||
new LimitChange(limitNameThird, 500L))
|
||||
);
|
||||
|
||||
List<LimitResponse> holdResponse = liminatorService.hold(holdRequest);
|
||||
|
||||
assertEquals(3, holdResponse.size());
|
||||
LimitResponse limitResponseFirst = getLimitResponseByLimitName(holdResponse, limitNameFirst);
|
||||
assertEquals(limitNameFirst, limitResponseFirst.getLimitName());
|
||||
assertEquals(500, limitResponseFirst.getTotalValue());
|
||||
assertEquals(0, limitResponseFirst.getCommitValue());
|
||||
LimitResponse limitResponseSecond = getLimitResponseByLimitName(holdResponse, limitNameSecond);
|
||||
assertEquals(limitNameSecond, limitResponseSecond.getLimitName());
|
||||
assertEquals(500, limitResponseSecond.getTotalValue());
|
||||
assertEquals(0, limitResponseSecond.getCommitValue());
|
||||
LimitResponse limitResponseThird = getLimitResponseByLimitName(holdResponse, limitNameThird);
|
||||
assertEquals(limitNameThird, limitResponseThird.getLimitName());
|
||||
assertEquals(500, limitResponseThird.getTotalValue());
|
||||
assertEquals(0, limitResponseThird.getCommitValue());
|
||||
|
||||
liminatorService.commit(holdRequest);
|
||||
List<LimitResponse> lastLimitsValues =
|
||||
liminatorService.getLastLimitsValues(List.of(limitNameFirst, limitNameSecond, limitNameThird));
|
||||
assertEquals(3, lastLimitsValues.size());
|
||||
LimitResponse firstLimitResponseAfterCommit = getLimitResponseByLimitName(lastLimitsValues, limitNameFirst);
|
||||
assertEquals(limitNameFirst, firstLimitResponseAfterCommit.getLimitName());
|
||||
assertEquals(500, firstLimitResponseAfterCommit.getTotalValue());
|
||||
assertEquals(500, firstLimitResponseAfterCommit.getCommitValue());
|
||||
LimitResponse secondLimitResponseAfterCommit = getLimitResponseByLimitName(lastLimitsValues, limitNameSecond);
|
||||
assertEquals(limitNameSecond, secondLimitResponseAfterCommit.getLimitName());
|
||||
assertEquals(500, secondLimitResponseAfterCommit.getTotalValue());
|
||||
assertEquals(500, secondLimitResponseAfterCommit.getCommitValue());
|
||||
LimitResponse thirdLimitResponseAfterCommit = getLimitResponseByLimitName(lastLimitsValues, limitNameThird);
|
||||
assertEquals(limitNameThird, thirdLimitResponseAfterCommit.getLimitName());
|
||||
assertEquals(500, thirdLimitResponseAfterCommit.getTotalValue());
|
||||
assertEquals(500, thirdLimitResponseAfterCommit.getCommitValue());
|
||||
|
||||
}
|
||||
|
||||
private LimitResponse getLimitResponseByLimitName(List<LimitResponse> response, String limitName) {
|
||||
return response.stream()
|
||||
.filter(limitResponse -> limitResponse.getLimitName().equals(limitName))
|
||||
.findFirst()
|
||||
.get();
|
||||
}
|
||||
|
||||
private LimitRequest createRequest(String limitName, String operationId) {
|
||||
return new LimitRequest()
|
||||
.setOperationId(operationId)
|
||||
|
Loading…
Reference in New Issue
Block a user