From 88fedd4d3edbb581eabe20074a65c32b635fc3b2 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 1 Apr 2020 11:03:31 -0400 Subject: Set sub request ID before start callback Modified new actor code to generate the sub request ID before invoking the start callback. Issue-ID: POLICY-2461 Change-Id: I4adabd6efda2c30c0e2da31f95f01dd5fe546c0a Signed-off-by: Jim Hahn --- .../actor/aai/AaiCustomQueryOperation.java | 5 ++ .../controlloop/actor/aai/AaiGetOperation.java | 7 ++- .../actor/aai/AaiCustomQueryOperationTest.java | 6 ++ .../controlloop/actor/aai/AaiGetOperationTest.java | 9 +++ .../controlloop/actor/appc/AppcOperation.java | 13 ++-- .../actor/appc/ModifyConfigOperation.java | 3 +- .../controlloop/actor/appc/AppcOperationTest.java | 69 +++++++++------------- .../actor/appc/ModifyConfigOperationTest.java | 7 +-- .../actor/appclcm/AppcLcmOperation.java | 10 ++-- .../actor/appclcm/AppcLcmOperationTest.java | 23 ++++---- .../controlloop/actor/cds/GrpcOperation.java | 7 ++- .../controlloop/actor/cds/GrpcOperationTest.java | 1 + .../controlloop/actor/guard/GuardOperation.java | 5 +- .../actor/guard/GuardOperationTest.java | 5 +- .../actor/sdnc/BandwidthOnDemandOperation.java | 3 +- .../controlloop/actor/sdnc/RerouteOperation.java | 3 +- .../controlloop/actor/sdnc/SdncOperation.java | 2 - .../actor/sdnc/BandwidthOnDemandOperationTest.java | 4 +- .../actor/sdnc/RerouteOperationTest.java | 4 +- .../actor/sdnr/ModifyConfigOperation.java | 8 +-- .../controlloop/actor/sdnr/SdnrOperation.java | 10 ++-- .../actor/sdnr/ModifyConfigOperationTest.java | 8 +-- .../controlloop/actor/sdnr/SdnrOperationTest.java | 10 ++-- .../policy/controlloop/actor/so/SoOperation.java | 15 +++-- .../controlloop/actor/so/SoOperationTest.java | 10 ++-- .../impl/BidirectionalTopicOperation.java | 11 +--- .../impl/OperationPartial.java | 21 +++++++ .../impl/BidirectionalTopicOperationTest.java | 18 ++---- .../impl/OperationPartialTest.java | 14 ++--- 29 files changed, 162 insertions(+), 149 deletions(-) diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java index 9f8d30a26..b00928847 100644 --- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java +++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperation.java @@ -90,6 +90,11 @@ public class AaiCustomQueryOperation extends HttpOperation { return params.getContext().obtain(AaiGetOperation.getTenantKey(vserver), tenantParams); } + @Override + public void generateSubRequestId(int attempt) { + setSubRequestId(String.valueOf(attempt)); + } + @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { outcome.setSubRequestId(String.valueOf(attempt)); diff --git a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java index 9ff56d61f..a20200807 100644 --- a/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java +++ b/models-interactions/model-actors/actor.aai/src/main/java/org/onap/policy/controlloop/actor/aai/AaiGetOperation.java @@ -90,9 +90,12 @@ public class AaiGetOperation extends HttpOperation { } @Override - protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { - outcome.setSubRequestId(String.valueOf(attempt)); + public void generateSubRequestId(int attempt) { + setSubRequestId(String.valueOf(attempt)); + } + @Override + protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { Map headers = makeHeaders(); headers.put("Accept", MediaType.APPLICATION_JSON); diff --git a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java index cf19ef65d..aa8165e34 100644 --- a/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java +++ b/models-interactions/model-actors/actor.aai/src/test/java/org/onap/policy/controlloop/actor/aai/AaiCustomQueryOperationTest.java @@ -141,6 +141,12 @@ public class AaiCustomQueryOperationTest extends BasicAaiOperation { assertEquals(10, oper.getRetry(10)); } + @Test + public void testGenerateSubRequestId() { + oper.generateSubRequestId(3); + assertEquals("3", oper.getSubRequestId()); + } + @Test @SuppressWarnings("unchecked") public void testStartOperationAsync_testStartQueryAsync_testPostProcessResponse() throws Exception { @@ -124,6 +130,9 @@ public class AaiGetOperationTest extends BasicAaiOperation { when(webAsync.get(any(InvocationCallback.class))).thenAnswer(provideResponse(rawResponse)); + oper.generateSubRequestId(1); + outcome.setSubRequestId(oper.getSubRequestId()); + CompletableFuture future2 = oper.startOperationAsync(1, outcome); assertFalse(future2.isDone()); diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java index 3ed23957a..75a4c9f58 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/AppcOperation.java @@ -23,9 +23,7 @@ package org.onap.policy.controlloop.actor.appc; import java.util.List; import java.util.Map; import java.util.Map.Entry; -import java.util.UUID; import java.util.concurrent.CompletableFuture; -import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.appc.CommonHeader; import org.onap.policy.appc.Request; import org.onap.policy.appc.Response; @@ -86,14 +84,11 @@ public abstract class AppcOperation extends BidirectionalTopicOperation makeRequest(int attempt, String targetVnf) { + protected Request makeRequest(int attempt, String targetVnf) { Request request = new Request(); request.setCommonHeader(new CommonHeader()); request.getCommonHeader().setRequestId(params.getRequestId()); - - // TODO ok to use UUID, or does it have to be the "attempt"? - final String subreq = UUID.randomUUID().toString(); - request.getCommonHeader().setSubRequestId(subreq); + request.getCommonHeader().setSubRequestId(getSubRequestId()); request.setAction(getName()); @@ -107,7 +102,7 @@ public abstract class AppcOperation extends BidirectionalTopicOperation getExpectedKeyValues(int attempt, Request request) { - return List.of(request.getCommonHeader().getSubRequestId()); + return List.of(getSubRequestId()); } @Override diff --git a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java index e4fd51c07..a318444aa 100644 --- a/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java +++ b/models-interactions/model-actors/actor.appc/src/main/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperation.java @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.actor.appc; import java.util.concurrent.CompletableFuture; -import org.apache.commons.lang3.tuple.Pair; import org.onap.aai.domain.yang.GenericVnf; import org.onap.policy.aai.AaiConstants; import org.onap.policy.aai.AaiCqResponse; @@ -61,7 +60,7 @@ public class ModifyConfigOperation extends AppcOperation { } @Override - protected Pair makeRequest(int attempt) { + protected Request makeRequest(int attempt) { AaiCqResponse cq = params.getContext().getProperty(AaiCqResponse.CONTEXT_KEY); GenericVnf genvnf = cq.getGenericVnfByModelInvariantId(params.getTarget().getResourceID()); diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java index 7f7ac7a54..4c6477d93 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/AppcOperationTest.java @@ -22,14 +22,12 @@ package org.onap.policy.controlloop.actor.appc; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import java.util.Arrays; import java.util.Map; import java.util.TreeMap; -import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -40,6 +38,8 @@ import org.onap.policy.appc.Request; import org.onap.policy.appc.ResponseCode; import org.onap.policy.appc.ResponseStatus; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation.Status; +import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; +import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.controlloop.policy.PolicyResult; public class AppcOperationTest extends BasicAppcOperation { @@ -64,12 +64,7 @@ public class AppcOperationTest extends BasicAppcOperation { public void setUp() throws Exception { super.setUp(); - oper = new AppcOperation(params, config) { - @Override - protected Pair makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; + oper = new MyOper(params, config); } @After @@ -91,11 +86,11 @@ public class AppcOperationTest extends BasicAppcOperation { @Test public void testMakeRequest() { - Pair result = oper.makeRequest(2, MY_VNF); - String subreq = result.getLeft(); + oper.generateSubRequestId(2); + String subreq = oper.getSubRequestId(); assertNotNull(subreq); - Request request = result.getRight(); + Request request = oper.makeRequest(2, MY_VNF); assertEquals(DEFAULT_OPERATION, request.getAction()); assertNotNull(request.getPayload()); @@ -106,27 +101,18 @@ public class AppcOperationTest extends BasicAppcOperation { assertEquals(subreq, header.getSubRequestId()); - // a subsequent request should have a different sub-request id - result = oper.makeRequest(2, MY_VNF); - assertNotEquals(subreq, result.getLeft()); - - assertNotNull(result.getLeft()); - assertEquals(result.getLeft(), result.getRight().getCommonHeader().getSubRequestId()); + request = oper.makeRequest(2, MY_VNF); + assertEquals(subreq, request.getCommonHeader().getSubRequestId()); // repeat using a null payload params = params.toBuilder().payload(null).build(); - oper = new AppcOperation(params, config) { - @Override - protected Pair makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; - assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getRight().getPayload()); + oper = new MyOper(params, config); + assertEquals(Map.of(AppcOperation.VNF_ID_KEY, MY_VNF), oper.makeRequest(2, MY_VNF).getPayload()); } @Test public void testConvertPayload() { - Request request = oper.makeRequest(2, MY_VNF).getRight(); + Request request = oper.makeRequest(2, MY_VNF); // @formatter:off assertEquals( @@ -145,13 +131,8 @@ public class AppcOperationTest extends BasicAppcOperation { params = params.toBuilder().payload(payload).build(); - oper = new AppcOperation(params, config) { - @Override - protected Pair makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; - request = oper.makeRequest(2, MY_VNF).getRight(); + oper = new MyOper(params, config); + request = oper.makeRequest(2, MY_VNF); // @formatter:off assertEquals( @@ -171,13 +152,8 @@ public class AppcOperationTest extends BasicAppcOperation { payload.put(KEY3, "def"); params = params.toBuilder().payload(payload).build(); - oper = new AppcOperation(params, config) { - @Override - protected Pair makeRequest(int attempt) { - return oper.makeRequest(attempt, MY_VNF); - } - }; - request = oper.makeRequest(2, MY_VNF).getRight(); + oper = new MyOper(params, config); + request = oper.makeRequest(2, MY_VNF); payload.put(AppcOperation.VNF_ID_KEY, MY_VNF); payload.put(KEY1, "abc"); @@ -189,7 +165,8 @@ public class AppcOperationTest extends BasicAppcOperation { @Test public void testGetExpectedKeyValues() { - Request request = oper.makeRequest(2, MY_VNF).getRight(); + oper.generateSubRequestId(2); + Request request = oper.makeRequest(2, MY_VNF); assertEquals(Arrays.asList(request.getCommonHeader().getSubRequestId()), oper.getExpectedKeyValues(50, request)); } @@ -250,4 +227,16 @@ public class AppcOperationTest extends BasicAppcOperation { assertEquals(MY_DESCRIPTION, outcome.getMessage()); } } + + private static class MyOper extends AppcOperation { + + public MyOper(ControlLoopOperationParams params, BidirectionalTopicConfig config) { + super(params, config); + } + + @Override + protected Request makeRequest(int attempt) { + return makeRequest(attempt, MY_VNF); + } + } } diff --git a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java index 743896c18..4f4f506ce 100644 --- a/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java +++ b/models-interactions/model-actors/actor.appc/src/test/java/org/onap/policy/controlloop/actor/appc/ModifyConfigOperationTest.java @@ -34,7 +34,6 @@ import static org.mockito.Mockito.when; import java.util.Arrays; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; -import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -161,10 +160,8 @@ public class ModifyConfigOperationTest extends BasicAppcOperation { genvnf.setModelInvariantId(RESOURCE_ID); cq.setInventoryResponseItems(Arrays.asList(genvnf)); - Pair result = oper.makeRequest(2); - assertNotNull(result.getLeft()); - - Request request = result.getRight(); + oper.generateSubRequestId(2); + Request request = oper.makeRequest(2); assertNotNull(request); assertEquals(MY_VNF, request.getPayload().get(ModifyConfigOperation.VNF_ID_KEY)); diff --git a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java index 87ff357e9..e34d3c586 100644 --- a/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java +++ b/models-interactions/model-actors/actor.appclcm/src/main/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperation.java @@ -22,10 +22,8 @@ package org.onap.policy.controlloop.actor.appclcm; import java.util.List; import java.util.Map; -import java.util.UUID; import java.util.concurrent.CompletableFuture; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.appclcm.AppcLcmBody; import org.onap.policy.appclcm.AppcLcmCommonHeader; import org.onap.policy.appclcm.AppcLcmDmaapWrapper; @@ -81,9 +79,9 @@ public class AppcLcmOperation extends BidirectionalTopicOperation makeRequest(int attempt) { + protected AppcLcmDmaapWrapper makeRequest(int attempt) { VirtualControlLoopEvent onset = params.getContext().getEvent(); - String subRequestId = UUID.randomUUID().toString(); + String subRequestId = getSubRequestId(); AppcLcmCommonHeader header = new AppcLcmCommonHeader(); header.setOriginatorId(onset.getRequestId().toString()); @@ -126,7 +124,7 @@ public class AppcLcmOperation extends BidirectionalTopicOperation getExpectedKeyValues(int attempt, AppcLcmDmaapWrapper request) { - return List.of(request.getBody().getInput().getCommonHeader().getSubRequestId()); + return List.of(getSubRequestId()); } @Override diff --git a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java index 9744d829b..b2a44af53 100644 --- a/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java +++ b/models-interactions/model-actors/actor.appclcm/src/test/java/org/onap/policy/controlloop/actor/appclcm/AppcLcmOperationTest.java @@ -23,7 +23,6 @@ package org.onap.policy.controlloop.actor.appclcm; import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; @@ -36,7 +35,6 @@ import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -170,11 +168,11 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { @Test public void testMakeRequest() { - Pair result = oper.makeRequest(2); - String subreq = result.getLeft(); + oper.generateSubRequestId(2); + String subreq = oper.getSubRequestId(); assertNotNull(subreq); - AppcLcmDmaapWrapper request = result.getRight(); + AppcLcmDmaapWrapper request = oper.makeRequest(2); assertEquals("DefaultOperation", request.getBody().getInput().getAction()); AppcLcmCommonHeader header = request.getBody().getInput().getCommonHeader(); @@ -185,11 +183,8 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { assertEquals("{vnf-id=my-target}", request.getBody().getInput().getActionIdentifiers().toString()); - // a subsequent request should have a different sub-request id - result = oper.makeRequest(2); - assertNotEquals(subreq, result.getLeft()); - assertNotNull(result.getLeft()); - assertEquals(result.getLeft(), result.getRight().getBody().getInput().getCommonHeader().getSubRequestId()); + request = oper.makeRequest(2); + assertEquals(subreq, request.getBody().getInput().getCommonHeader().getSubRequestId()); } @Test @@ -198,7 +193,8 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { params = params.toBuilder().operation(AppcLcmConstants.OPERATION_CONFIG_MODIFY).build(); oper = new AppcLcmOperation(params, config); - AppcLcmDmaapWrapper req = oper.makeRequest(2).getRight(); + oper.generateSubRequestId(2); + AppcLcmDmaapWrapper req = oper.makeRequest(2); assertEquals("{\"key-A\":\"value-A\"}", req.getBody().getInput().getPayload()); // coder exception @@ -214,13 +210,16 @@ public class AppcLcmOperationTest extends BasicBidirectionalTopicOperation { } }; + oper.generateSubRequestId(2); + assertThatIllegalArgumentException().isThrownBy(() -> oper.makeRequest(2)) .withMessage("Cannot convert payload"); } @Test public void testGetExpectedKeyValues() { - AppcLcmDmaapWrapper request = oper.makeRequest(2).getRight(); + oper.generateSubRequestId(2); + AppcLcmDmaapWrapper request = oper.makeRequest(2); assertEquals(Arrays.asList(request.getBody().getInput().getCommonHeader().getSubRequestId()), oper.getExpectedKeyValues(50, request)); } diff --git a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java index efe358bad..e57bc041f 100644 --- a/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java +++ b/models-interactions/model-actors/actor.cds/src/main/java/org/onap/policy/controlloop/actor/cds/GrpcOperation.java @@ -92,6 +92,11 @@ public class GrpcOperation extends OperationPartial { return allOf(() -> params.getContext().obtain(AaiCqResponse.CONTEXT_KEY, cqParams), this::startGuardAsync); } + @Override + public void generateSubRequestId(int attempt) { + setSubRequestId("0"); + } + /** * {@inheritDoc}. */ @@ -167,7 +172,7 @@ public class GrpcOperation extends OperationPartial { // Build CDS gRPC request common-header CommonHeader commonHeader = CommonHeader.newBuilder().setOriginatorId(CdsActorConstants.ORIGINATOR_ID) .setRequestId(params.getContext().getEvent().getRequestId().toString()) - .setSubRequestId(Integer.toString(0)).build(); + .setSubRequestId(getSubRequestId()).build(); // Build CDS gRPC request action-identifier ActionIdentifiers actionIdentifiers = diff --git a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java index 81636b194..7baf8aaf7 100644 --- a/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java +++ b/models-interactions/model-actors/actor.cds/src/test/java/org/onap/policy/controlloop/actor/cds/GrpcOperationTest.java @@ -173,6 +173,7 @@ public class GrpcOperationTest { assertEquals(1000, operation.getTimeoutMs(null)); assertEquals(1000, operation.getTimeoutMs(0)); assertEquals(2000, operation.getTimeoutMs(2)); + operation.generateSubRequestId(1); CompletableFuture future3 = operation.startOperationAsync(1, params.makeOutcome()); assertNotNull(future3); } diff --git a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java index edd2e230d..3a7821ec2 100644 --- a/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java +++ b/models-interactions/model-actors/actor.guard/src/main/java/org/onap/policy/controlloop/actor/guard/GuardOperation.java @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.actor.guard; import java.util.Map; -import java.util.UUID; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import javax.ws.rs.client.Entity; @@ -106,8 +105,6 @@ public class GuardOperation extends HttpOperation { @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { - outcome.setSubRequestId(String.valueOf(attempt)); - DecisionRequest request = makeRequest(); Entity entity = Entity.entity(request, MediaType.APPLICATION_JSON); @@ -135,7 +132,7 @@ public class GuardOperation extends HttpOperation { } DecisionRequest req = config.makeRequest(); - req.setRequestId(UUID.randomUUID().toString()); + req.setRequestId(getSubRequestId()); req.setResource(Map.of("guard", params.getPayload())); return req; diff --git a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java index 3d1538312..58d54a5ed 100644 --- a/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java +++ b/models-interactions/model-actors/actor.guard/src/test/java/org/onap/policy/controlloop/actor/guard/GuardOperationTest.java @@ -161,7 +161,8 @@ public class GuardOperationTest extends BasicHttpOperation { assertEquals(PolicyResult.SUCCESS, future2.get().getResult()); - assertEquals("1", future2.get().getSubRequestId()); + assertNotNull(oper.getSubRequestId()); + assertEquals(oper.getSubRequestId(), future2.get().getSubRequestId()); } /** @@ -189,6 +190,8 @@ public class GuardOperationTest extends BasicHttpOperation { @Test public void testMakeRequest() throws CoderException { + oper.generateSubRequestId(2); + verifyPayload("makeReqStd.json", makePayload()); verifyPayload("makeReqDefault.json", new TreeMap<>()); diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java index daced6e81..0c44169e1 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperation.java @@ -20,7 +20,6 @@ package org.onap.policy.controlloop.actor.sdnc; -import java.util.UUID; import org.apache.commons.lang3.StringUtils; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; @@ -85,7 +84,7 @@ public class BandwidthOnDemandOperation extends SdncOperation { SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); headerInfo.setSvcAction("update"); - headerInfo.setSvcRequestId(UUID.randomUUID().toString()); + headerInfo.setSvcRequestId(getSubRequestId()); SdncRequest request = new SdncRequest(); request.setNsInstanceId(serviceInstance); diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java index 2e0d7b855..d8e1b0548 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperation.java @@ -20,7 +20,6 @@ package org.onap.policy.controlloop.actor.sdnc; -import java.util.UUID; import org.apache.commons.lang3.StringUtils; import org.onap.policy.controlloop.actorserviceprovider.controlloop.ControlLoopEventContext; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; @@ -72,7 +71,7 @@ public class RerouteOperation extends SdncOperation { SdncHealRequestHeaderInfo headerInfo = new SdncHealRequestHeaderInfo(); headerInfo.setSvcAction("reoptimize"); - headerInfo.setSvcRequestId(UUID.randomUUID().toString()); + headerInfo.setSvcRequestId(getSubRequestId()); SdncRequest request = new SdncRequest(); request.setNsInstanceId(serviceInstance); diff --git a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java index 0c0558282..ca6d07b16 100644 --- a/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java +++ b/models-interactions/model-actors/actor.sdnc/src/main/java/org/onap/policy/controlloop/actor/sdnc/SdncOperation.java @@ -61,8 +61,6 @@ public abstract class SdncOperation extends HttpOperation { protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { SdncRequest request = makeRequest(attempt); - outcome.setSubRequestId(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); - Entity entity = Entity.entity(request, MediaType.APPLICATION_JSON); Map headers = makeHeaders(); diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java index 8e26c68f4..2b856707e 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/BandwidthOnDemandOperationTest.java @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.actor.sdnc; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.util.Map; import org.junit.AfterClass; @@ -85,11 +84,12 @@ public class BandwidthOnDemandOperationTest extends BasicSdncOperation { @Test public void testMakeRequest() throws Exception { + oper.generateSubRequestId(1); SdncRequest request = oper.makeRequest(1); assertEquals("my-service", request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); assertEquals("/my-path/", request.getUrl()); - assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); + assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); verifyRequest("bod.json", request, IGNORE_FIELDS); diff --git a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java index 97cdcb054..678648db3 100644 --- a/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java +++ b/models-interactions/model-actors/actor.sdnc/src/test/java/org/onap/policy/controlloop/actor/sdnc/RerouteOperationTest.java @@ -21,7 +21,6 @@ package org.onap.policy.controlloop.actor.sdnc; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; import java.util.Map; import org.junit.AfterClass; @@ -85,11 +84,12 @@ public class RerouteOperationTest extends BasicSdncOperation { @Test public void testMakeRequest() throws Exception { + oper.generateSubRequestId(1); SdncRequest request = oper.makeRequest(1); assertEquals("my-service", request.getNsInstanceId()); assertEquals(REQ_ID, request.getRequestId()); assertEquals("/my-path/", request.getUrl()); - assertNotNull(request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); + assertEquals(oper.getSubRequestId(), request.getHealRequest().getRequestHeaderInfo().getSvcRequestId()); verifyRequest("reroute.json", request, IGNORE_FIELDS); diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java index a5193ec52..2b7f644b6 100644 --- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/ModifyConfigOperation.java @@ -20,7 +20,6 @@ package org.onap.policy.controlloop.actor.sdnr; -import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.controlloop.actorserviceprovider.parameters.BidirectionalTopicConfig; import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams; import org.onap.policy.sdnr.PciMessage; @@ -39,14 +38,13 @@ public class ModifyConfigOperation extends SdnrOperation { } @Override - protected Pair makeRequest(int attempt) { - final Pair req = super.makeRequest(attempt); - final PciMessage request = req.getRight(); + protected PciMessage makeRequest(int attempt) { + final PciMessage request = super.makeRequest(attempt); // // Set the recipe and action information // request.setRpcName(NAME.toLowerCase()); request.getBody().getInput().setAction(NAME); - return req; + return request; } } diff --git a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java index de498e6ab..b5066c72a 100644 --- a/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java +++ b/models-interactions/model-actors/actor.sdnr/src/main/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperation.java @@ -21,9 +21,7 @@ package org.onap.policy.controlloop.actor.sdnr; import java.util.List; -import java.util.UUID; import java.util.concurrent.CompletableFuture; -import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.controlloop.VirtualControlLoopEvent; import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome; import org.onap.policy.controlloop.actorserviceprovider.impl.BidirectionalTopicOperation; @@ -62,7 +60,7 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation getExpectedKeyValues(int attempt, PciMessage request) { - return List.of(request.getBody().getInput().getCommonHeader().getSubRequestId()); + return List.of(getSubRequestId()); } @Override @@ -128,9 +126,9 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation makeRequest(int attempt) { + protected PciMessage makeRequest(int attempt) { VirtualControlLoopEvent onset = params.getContext().getEvent(); - String subRequestId = UUID.randomUUID().toString(); + String subRequestId = getSubRequestId(); /* Construct an SDNR request using pci Model */ @@ -159,6 +157,6 @@ public abstract class SdnrOperation extends BidirectionalTopicOperation result = oper.makeRequest(1); - assertNotNull(result.getLeft()); - assertNotNull(result.getRight()); + oper.generateSubRequestId(1); + + PciMessage request = oper.makeRequest(1); + assertNotNull(request); } } diff --git a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java index 8f58f7d87..836b1ae57 100644 --- a/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java +++ b/models-interactions/model-actors/actor.sdnr/src/test/java/org/onap/policy/controlloop/actor/sdnr/SdnrOperationTest.java @@ -26,7 +26,6 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertSame; import java.util.Arrays; -import org.apache.commons.lang3.tuple.Pair; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; @@ -78,10 +77,9 @@ public class SdnrOperationTest extends BasicSdnrOperation { @Test public void testMakeRequest() { - Pair result = operation.makeRequest(1); - assertNotNull(result.getLeft()); + operation.generateSubRequestId(1); - PciMessage request = result.getRight(); + PciMessage request = operation.makeRequest(1); assertNotNull(request.getBody()); assertEquals("1.0", request.getVersion()); @@ -94,7 +92,9 @@ public class SdnrOperationTest extends BasicSdnrOperation { @Test public void testGetExpectedKeyValues() { - PciMessage request = operation.makeRequest(1).getRight(); + operation.generateSubRequestId(1); + + PciMessage request = operation.makeRequest(1); assertEquals(Arrays.asList(request.getBody().getInput().getCommonHeader().getSubRequestId()), operation.getExpectedKeyValues(50, request)); } diff --git a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java index 4d53f6350..86b910176 100644 --- a/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java +++ b/models-interactions/model-actors/actor.so/src/main/java/org/onap/policy/controlloop/actor/so/SoOperation.java @@ -198,14 +198,14 @@ public abstract class SoOperation extends HttpOperation { if (rawResponse.getStatus() == 200) { String requestState = getRequestState(response); if (COMPLETE.equalsIgnoreCase(requestState)) { - populateSubRequestId(outcome, response); + extractSubRequestId(response); successfulCompletion(); return CompletableFuture .completedFuture(setOutcome(outcome, PolicyResult.SUCCESS, rawResponse, response)); } if (FAILED.equalsIgnoreCase(requestState)) { - populateSubRequestId(outcome, response); + extractSubRequestId(response); return CompletableFuture .completedFuture(setOutcome(outcome, PolicyResult.FAILURE, rawResponse, response)); } @@ -214,7 +214,7 @@ public abstract class SoOperation extends HttpOperation { // still incomplete // need a request ID with which to query - if (!populateSubRequestId(outcome, response)) { + if (!extractSubRequestId(response)) { throw new IllegalArgumentException("missing request ID in response"); } @@ -231,13 +231,18 @@ public abstract class SoOperation extends HttpOperation { return sleep(getWaitMsGet(), TimeUnit.MILLISECONDS).thenComposeAsync(doGet); } - private boolean populateSubRequestId(OperationOutcome outcome, SoResponse response) { + @Override + public void generateSubRequestId(int attempt) { + setSubRequestId(null); + } + + private boolean extractSubRequestId(SoResponse response) { if (response == null || response.getRequestReferences() == null || response.getRequestReferences().getRequestId() == null) { return false; } - outcome.setSubRequestId(response.getRequestReferences().getRequestId()); + setSubRequestId(response.getRequestReferences().getRequestId()); return true; } diff --git a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java index 80f20b59b..ce0d2c24f 100644 --- a/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java +++ b/models-interactions/model-actors/actor.so/src/test/java/org/onap/policy/controlloop/actor/so/SoOperationTest.java @@ -166,21 +166,23 @@ public class SoOperationTest extends BasicSoOperation { @Test public void testPostProcess() throws Exception { // completed - outcome.setSubRequestId(null); + oper.generateSubRequestId(2); + assertNull(oper.getSubRequestId()); CompletableFuture future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); assertEquals(PolicyResult.SUCCESS, outcome.getResult()); - assertNotNull(outcome.getSubRequestId()); + assertNotNull(oper.getSubRequestId()); // failed - outcome.setSubRequestId(null); + oper.generateSubRequestId(2); + assertNull(oper.getSubRequestId()); response.getRequest().getRequestStatus().setRequestState(SoOperation.FAILED); future2 = oper.postProcessResponse(outcome, PATH, rawResponse, response); assertTrue(future2.isDone()); assertSame(outcome, future2.get()); assertEquals(PolicyResult.FAILURE, outcome.getResult()); - assertNotNull(outcome.getSubRequestId()); + assertNotNull(oper.getSubRequestId()); // no request id in the response response.getRequestReferences().setRequestId(null); diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java index f598d627a..9decd8a61 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperation.java @@ -25,7 +25,6 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.function.BiConsumer; import lombok.Getter; -import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; import org.onap.policy.common.utils.coder.CoderException; import org.onap.policy.common.utils.coder.StandardCoderObject; @@ -106,10 +105,7 @@ public abstract class BidirectionalTopicOperation extends OperationPartial @Override protected CompletableFuture startOperationAsync(int attempt, OperationOutcome outcome) { - final Pair pair = makeRequest(attempt); - final Q request = pair.getRight(); - outcome.setSubRequestId(pair.getLeft()); - + final Q request = makeRequest(attempt); final List expectedKeyValues = getExpectedKeyValues(attempt, request); final PipelineControllerFuture controller = new PipelineControllerFuture<>(); @@ -151,10 +147,9 @@ public abstract class BidirectionalTopicOperation extends OperationPartial * Makes the request. * * @param attempt operation attempt - * @return a pair containing sub request ID, which may be {@code null} and the new - * request + * @return a new request */ - protected abstract Pair makeRequest(int attempt); + protected abstract Q makeRequest(int attempt); /** * Gets values, expected in the response, that should match the selector keys. diff --git a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java index a9d7f4e58..4aa723614 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java +++ b/models-interactions/model-actors/actorServiceProvider/src/main/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartial.java @@ -28,6 +28,7 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Queue; +import java.util.UUID; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletionException; @@ -38,7 +39,9 @@ import java.util.function.BiConsumer; import java.util.function.Function; import java.util.function.Supplier; import java.util.function.UnaryOperator; +import lombok.AccessLevel; import lombok.Getter; +import lombok.Setter; import org.onap.policy.common.endpoints.event.comm.Topic.CommInfrastructure; import org.onap.policy.common.endpoints.utils.NetLoggerUtil; import org.onap.policy.common.endpoints.utils.NetLoggerUtil.EventType; @@ -96,6 +99,10 @@ public abstract class OperationPartial implements Operation { @Getter private final String fullName; + @Getter + @Setter(AccessLevel.PROTECTED) + private String subRequestId; + /** * Constructs the object. @@ -271,6 +278,8 @@ public abstract class OperationPartial implements Operation { private CompletableFuture startOperationAttempt( PipelineControllerFuture controller, int attempt) { + generateSubRequestId(attempt); + // propagate "stop" to the operation attempt controller.wrap(startAttemptWithoutRetries(attempt)).thenCompose(retryOnFailure(controller, attempt)) .whenCompleteAsync(controller.delayedComplete(), params.getExecutor()); @@ -278,6 +287,16 @@ public abstract class OperationPartial implements Operation { return controller; } + /** + * Generates and sets {@link #subRequestId} to a new subrequest ID. + * @param attempt attempt number, typically starting with 1 + */ + public void generateSubRequestId(int attempt) { + // Note: this should be "protected", but that makes junits much messier + + setSubRequestId(UUID.randomUUID().toString()); + } + /** * Starts the operation attempt, without doing any retries. * @@ -889,6 +908,7 @@ public abstract class OperationPartial implements Operation { return (outcome, thrown) -> { if (callbacks.canStart()) { + outcome.setSubRequestId(getSubRequestId()); outcome.setStart(callbacks.getStartTime()); outcome.setEnd(null); @@ -917,6 +937,7 @@ public abstract class OperationPartial implements Operation { return (outcome, thrown) -> { if (callbacks.canEnd()) { + outcome.setSubRequestId(getSubRequestId()); outcome.setStart(callbacks.getStartTime()); outcome.setEnd(callbacks.getEndTime()); diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java index 48669f799..55782a34d 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/BidirectionalTopicOperationTest.java @@ -40,7 +40,6 @@ import java.util.concurrent.CompletableFuture; import java.util.function.BiConsumer; import lombok.Getter; import lombok.Setter; -import org.apache.commons.lang3.tuple.Pair; import org.junit.Before; import org.junit.Test; import org.mockito.ArgumentCaptor; @@ -67,7 +66,6 @@ public class BidirectionalTopicOperationTest { private static final String OPERATION = "my-operation"; private static final String REQ_ID = "my-request-id"; private static final String TEXT = "some text"; - private static final String SUB_REQID = "my-sub-request-id"; private static final int TIMEOUT_SEC = 10; private static final long TIMEOUT_MS = 1000 * TIMEOUT_SEC; private static final int MAX_REQUESTS = 100; @@ -138,8 +136,6 @@ public class BidirectionalTopicOperationTest { CompletableFuture future = oper.startOperationAsync(1, outcome); assertFalse(future.isDone()); - assertEquals(SUB_REQID, outcome.getSubRequestId()); - verify(forwarder).register(eq(Arrays.asList(REQ_ID)), listenerCaptor.capture()); verify(forwarder, never()).unregister(any(), any()); @@ -183,8 +179,6 @@ public class BidirectionalTopicOperationTest { CompletableFuture future = oper.startOperationAsync(1, outcome); assertFalse(future.isDone()); - assertEquals(SUB_REQID, outcome.getSubRequestId()); - verify(forwarder).register(eq(Arrays.asList(REQ_ID)), listenerCaptor.capture()); verify(forwarder, never()).unregister(any(), any()); @@ -363,8 +357,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected Pair makeRequest(int attempt) { - return Pair.of(SUB_REQID, TEXT); + protected String makeRequest(int attempt) { + return TEXT; } @Override @@ -385,8 +379,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected Pair makeRequest(int attempt) { - return Pair.of(SUB_REQID, new MyRequest()); + protected MyRequest makeRequest(int attempt) { + return new MyRequest(); } @Override @@ -407,8 +401,8 @@ public class BidirectionalTopicOperationTest { } @Override - protected Pair makeRequest(int attempt) { - return Pair.of(SUB_REQID, new MyRequest()); + protected MyRequest makeRequest(int attempt) { + return new MyRequest(); } @Override diff --git a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java index 7b8eed59e..75463b9d7 100644 --- a/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java +++ b/models-interactions/model-actors/actorServiceProvider/src/test/java/org/onap/policy/controlloop/actorserviceprovider/impl/OperationPartialTest.java @@ -531,7 +531,7 @@ public class OperationPartialTest { } }; - verifyRun("testSetRetryFlag_testRetryOnFailure_NullOutcome", 1, 1, PolicyResult.FAILURE, null, noop()); + verifyRun("testSetRetryFlag_testRetryOnFailure_NullOutcome", 1, 1, PolicyResult.FAILURE, noop()); } @Test @@ -1179,10 +1179,7 @@ public class OperationPartialTest { private void verifyRun(String testName, int expectedCallbacks, int expectedOperations, PolicyResult expectedResult) { - String expectedSubRequestId = - (expectedResult == PolicyResult.FAILURE_EXCEPTION ? null : String.valueOf(expectedOperations)); - - verifyRun(testName, expectedCallbacks, expectedOperations, expectedResult, expectedSubRequestId, noop()); + verifyRun(testName, expectedCallbacks, expectedOperations, expectedResult, noop()); } /** @@ -1192,13 +1189,12 @@ public class OperationPartialTest { * @param expectedCallbacks number of callbacks expected * @param expectedOperations number of operation invocations expected * @param expectedResult expected outcome - * @param expectedSubRequestId expected sub request ID * @param manipulator function to modify the future returned by * {@link OperationPartial#start(ControlLoopOperationParams)} before the tasks * in the executor are run */ private void verifyRun(String testName, int expectedCallbacks, int expectedOperations, PolicyResult expectedResult, - String expectedSubRequestId, Consumer> manipulator) { + Consumer> manipulator) { tstart = null; opstart = null; @@ -1244,7 +1240,9 @@ public class OperationPartialTest { } if (expectedOperations > 0) { - assertEquals(testName, expectedSubRequestId, opend.getSubRequestId()); + assertNotNull(testName, oper.getSubRequestId()); + assertEquals(testName + " op start", oper.getSubRequestId(), opstart.getSubRequestId()); + assertEquals(testName + " op end", oper.getSubRequestId(), opend.getSubRequestId()); } } -- cgit 1.2.3-korg