diff options
author | Balaji, Ramya (rb111y) <rb111y@att.com> | 2018-09-07 16:00:46 -0400 |
---|---|---|
committer | Takamune Cho <tc012c@att.com> | 2018-09-11 15:10:09 +0000 |
commit | f1b353074c937b473e23e717966d97602bc981f8 (patch) | |
tree | f35ef0d0571f898ac7c9bf1d435da9d47effe944 /appc-dispatcher/appc-dispatcher-common/transaction-recorder | |
parent | 99043712640be0ffc317f95d0630b2119998cb2b (diff) |
In progress trxns criteria fix
Changed the criteria for inprogress
transactions to the last X hours.
This will eliminate stale transactions
causing an incorrect scope
overlap error.
Issue-ID: APPC-1194
Change-Id: I2f3147503f4202e8e8931b2615e626e3b9af8261
Signed-off-by: Balaji, Ramya (rb111y) <rb111y@att.com>
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common/transaction-recorder')
3 files changed, 36 insertions, 13 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java index 299115d99..17e0e2575 100644 --- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java +++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/TransactionRecorder.java @@ -9,15 +9,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ============LICENSE_END========================================================= */ @@ -62,10 +62,11 @@ public interface TransactionRecorder { * Fetch list of Transactions which are in non-terminal state i.e. ACCEPTED or RECEIVED for particular TargetId. * @param record Transactions object from which TargetId and StartTime is extracted to fetch list of in progress * requests which APPC received before the current request. + * @param interval Number of hours - Time window to consider requests as being in progress * @return List of Transactions in non terminal state. * @throws APPCException */ - List<TransactionRecord> getInProgressRequests(TransactionRecord record) throws APPCException; + List<TransactionRecord> getInProgressRequests(TransactionRecord record, int interval) throws APPCException; /** * Checks whether the incoming request is duplicate. diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java index 7c1581f57..98ea1b538 100644 --- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java +++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/main/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImpl.java @@ -9,15 +9,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ============LICENSE_END========================================================= */ @@ -45,6 +45,7 @@ import java.time.format.DateTimeFormatter; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.time.temporal.ChronoUnit; import static org.onap.appc.transactionrecorder.objects.TransactionConstants.TRANSACTION_ATTRIBUTES.*; import static org.onap.appc.transactionrecorder.objects.TransactionConstants.*; @@ -165,19 +166,24 @@ public class TransactionRecorderImpl implements TransactionRecorder { } @Override - public List<TransactionRecord> getInProgressRequests(TransactionRecord record) throws APPCException { + public List<TransactionRecord> getInProgressRequests(TransactionRecord record, int interval) throws APPCException { - final String IN_PROGRESS_REQUESTS_QUERY = "SELECT * FROM " + + String IN_PROGRESS_REQUESTS_QUERY = "SELECT * FROM " + TransactionConstants.TRANSACTIONS + WHERE + TARGET_ID + " = ? AND " + STATE.getColumnName() + " IN (?,?) AND " + START_TIME.getColumnName() + " < ?"; ArrayList<String> inProgressQueryParams = new ArrayList<>(); + Instant window = record.getStartTime().minus(interval, ChronoUnit.HOURS); inProgressQueryParams.add(record.getTargetId()); inProgressQueryParams.add(RequestStatus.RECEIVED.name()); inProgressQueryParams.add(RequestStatus.ACCEPTED.name()); inProgressQueryParams.add(dateToStringConverterMillis(record.getStartTime())); + if (interval > 0) { + IN_PROGRESS_REQUESTS_QUERY += " AND " + START_TIME.getColumnName() + " > ? "; + inProgressQueryParams.add(dateToStringConverterMillis(window)); + } try (CachedRowSet rowSet = dbLibService.getData(IN_PROGRESS_REQUESTS_QUERY, inProgressQueryParams, SCHEMA)) { List<TransactionRecord> inProgressRecords = new ArrayList<>(); diff --git a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java index fd1790d49..1418e89c6 100644 --- a/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java +++ b/appc-dispatcher/appc-dispatcher-common/transaction-recorder/src/test/java/org/onap/appc/transactionrecorder/impl/TransactionRecorderImplTest.java @@ -9,15 +9,15 @@ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - * + * * ============LICENSE_END========================================================= */ @@ -45,8 +45,10 @@ import java.sql.*; import java.time.Instant; import java.time.ZoneOffset; import java.time.format.DateTimeFormatter; +import java.time.temporal.ChronoUnit; import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.UUID; @@ -152,7 +154,21 @@ public class TransactionRecorderImplTest { input.setStartTime(Instant.now()); Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> inMemoryExecutionWithResultSet(invocation.getArguments())); - Assert.assertEquals(1, transactionRecorderImpl.getInProgressRequests(input).size()); + Assert.assertEquals(1, transactionRecorderImpl.getInProgressRequests(input,0).size()); + + } + + @Test + public void testGetInProgressRequestsWithinTimeInterval() throws SQLException, APPCException { + TransactionRecord record1 = prepareTransactionsInput(); + record1.setStartTime(Instant.now().minus(4,ChronoUnit.HOURS)); + insertRecord(record1); + TransactionRecord input = prepareTransactionsInput(); + input.setStartTime(Instant.now()); + Mockito.when(dbLibService.getData(anyString(), anyObject(), anyString())).thenAnswer(invocation -> + inMemoryExecutionWithResultSet(invocation.getArguments())); + List<TransactionRecord> aList= transactionRecorderImpl.getInProgressRequests(input,12); + Assert.assertEquals(1, transactionRecorderImpl.getInProgressRequests(input,12).size()); } |