X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=policy-agent%2Fsrc%2Ftest%2Fjava%2Forg%2Foransc%2Fpolicyagent%2Futils%2FMockA1ClientFactory.java;h=c1fd8c3148223043de0575072e22e91b0c1ba026;hb=refs%2Fchanges%2F57%2F3057%2F3;hp=52682fac53e98b5b13d6b803f4f6e8271501b8ff;hpb=be2000ec2d21151b42cb559ef881695eb32e35e9;p=nonrtric.git diff --git a/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1ClientFactory.java b/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1ClientFactory.java index 52682fac..c1fd8c31 100644 --- a/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1ClientFactory.java +++ b/policy-agent/src/test/java/org/oransc/policyagent/utils/MockA1ClientFactory.java @@ -24,6 +24,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import java.lang.invoke.MethodHandles; +import java.time.Duration; import java.util.HashMap; import java.util.Map; @@ -40,6 +41,7 @@ public class MockA1ClientFactory extends A1ClientFactory { private static final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass()); private final Map clients = new HashMap<>(); private final PolicyTypes policyTypes; + private Duration asynchDelay = Duration.ofSeconds(0); public MockA1ClientFactory(PolicyTypes policyTypes) { super(mock(ApplicationConfig.class)); @@ -54,10 +56,20 @@ public class MockA1ClientFactory extends A1ClientFactory { public MockA1Client getOrCreateA1Client(String ricName) { if (!clients.containsKey(ricName)) { logger.debug("Creating client for RIC: {}", ricName); - MockA1Client client = spy(new MockA1Client(policyTypes)); + MockA1Client client = spy(new MockA1Client(policyTypes, asynchDelay)); clients.put(ricName, client); } return clients.get(ricName); } + /** + * Simulate network latency. The REST responses will be generated by separate + * threads + * + * @param delay the delay between the request and the response + */ + public void setResponseDelay(Duration delay) { + this.asynchDelay = delay; + } + }