import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ActorConstants;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithEvent;
+import org.onap.policy.controlloop.eventmanager.EventManagerServices;
import org.onap.policy.controlloop.eventmanager.StepContext;
import org.onap.policy.drools.apps.controller.usecases.step.AaiCqStep2;
import org.onap.policy.drools.apps.controller.usecases.step.AaiGetPnfStep2;
/**
* Constructs the object.
*
+ * @param services services the manager should use when processing the event
* @param params control loop parameters
* @param event event to be managed by this object
* @param workMem working memory to update if this changes
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public UsecasesEventManager(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
- throws ControlLoopException {
+ public UsecasesEventManager(EventManagerServices services, ControlLoopParams params, VirtualControlLoopEvent event,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, event, workMem);
+ super(services, params, event, workMem);
if (isClosedLoopDisabled(event)) {
throw new IllegalStateException("is-closed-loop-disabled is set to true on VServer or VNF");
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithSteps.State;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithOutcome.OperationOutcome2;
import org.onap.policy.controlloop.eventmanager.ClEventManagerWithEvent.NewEventStatus;
+import org.onap.policy.controlloop.eventmanager.EventManagerServices;
import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicy;
import org.slf4j.LoggerFactory;
import org.onap.policy.drools.system.PolicyEngineConstants;
+
+/*
+* Called at initial start-up, to create the event services that will be used by all
+* event managers in this rule engine instance.
+*/
+rule "CREATE.EVENT.SERVICES"
+ when
+ not (EventManagerServices())
+ then
+
+ Logger logger = LoggerFactory.getLogger(drools.getRule().getPackage());
+ logger.info("{}", drools.getRule().getName());
+
+ try {
+ insert(new EventManagerServices("event-manager"));
+
+ } catch(RuntimeException e) {
+ logger.warn("{}: cannot create event services", drools.getRule().getName(), e);
+ }
+end
+
/*
*
* Called when the ControlLoopParams object has been inserted into working memory from the PAP.
when
$params : ControlLoopParams( $clName : getClosedLoopControlName() )
$event : CanonicalOnset( closedLoopControlName == $clName )
+ $services : EventManagerServices()
not ( UsecasesEventManager( closedLoopControlName == $event.getClosedLoopControlName(),
getEvent() == $event ) )
then
notification.setPolicyVersion($params.getPolicyVersion());
} else {
- UsecasesEventManager manager = new UsecasesEventManager($params, $event, drools.getWorkingMemory());
+ UsecasesEventManager manager =
+ new UsecasesEventManager($services, $params, $event, drools.getWorkingMemory());
insert(manager);
try {
// load the first policy/step
import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.ControlLoopTargetType;
import org.onap.policy.controlloop.VirtualControlLoopEvent;
-import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationProperties;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
import org.onap.policy.controlloop.eventmanager.ActorConstants;
+import org.onap.policy.controlloop.eventmanager.EventManagerServices;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.drools.apps.controller.usecases.step.AaiCqStep2;
import org.onap.policy.drools.apps.controller.usecases.step.AaiGetPnfStep2;
@Mock
private Actor policyActor;
@Mock
- private ActorService actors;
+ private EventManagerServices services;
@Mock
private OperationHistoryDataManager dataMgr;
@Mock
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getDataManager()).thenReturn(dataMgr);
+
when(workMem.getFactHandle(any())).thenReturn(factHandle);
event = new VirtualControlLoopEvent();
locks = new ArrayList<>();
- mgr = new MyManager(params, event, workMem);
+ mgr = new MyManager(services, params, event, workMem);
}
@Test
Map<String, String> orig = event.getAai();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.hasMessage("is-closed-loop-disabled is set to true on VServer or VNF");
// vserver ACTIVE
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toUpperCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vserver active
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toLowerCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vserver inactive
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.hasMessage("prov-status is not ACTIVE on VServer or VNF");
// vnf ACTIVE
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toUpperCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vnf active
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS,
UsecasesConstants.PROV_STATUS_ACTIVE.toLowerCase()));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
// vnf inactive
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.hasMessage("prov-status is not ACTIVE on VServer or VNF");
// valid
// invalid
event.setTarget("unknown-target");
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(ControlLoopException.class);
}
Map<String, String> orig = event.getAai();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_IS_CLOSED_LOOP_DISABLED, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
event.setAai(addAai(orig, UsecasesConstants.PNF_IS_IN_MAINT, "true"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
}
Map<String, String> orig = event.getAai();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "ACTIVE"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "ACTIVE"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
event.setAai(addAai(orig, UsecasesConstants.GENERIC_VNF_PROV_STATUS, "inactive"));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
}
for (String value : Arrays.asList("yes", "y", "true", "t", "yEs", "trUe")) {
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, value));
- assertThatThrownBy(() -> new UsecasesEventManager(params, event, workMem))
+ assertThatThrownBy(() -> new UsecasesEventManager(services, params, event, workMem))
.isInstanceOf(IllegalStateException.class);
}
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "false"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
event.setAai(addAai(orig, UsecasesConstants.VSERVER_IS_CLOSED_LOOP_DISABLED, "no"));
- assertThatCode(() -> new UsecasesEventManager(params, event, workMem)).doesNotThrowAnyException();
+ assertThatCode(() -> new UsecasesEventManager(services, params, event, workMem)).doesNotThrowAnyException();
}
private class MyManager extends UsecasesEventManager {
private static final long serialVersionUID = 1L;
- public MyManager(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
- throws ControlLoopException {
+ public MyManager(EventManagerServices services, ControlLoopParams params, VirtualControlLoopEvent event,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, event, workMem);
+ super(services, params, event, workMem);
}
@Override
callback.lockAvailable(lock);
}
- @Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
@Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
/**
* Constructs the object.
*
+ * @param services services the manager should use when processing the event
* @param params control loop parameters
* @param event event to be managed by this object
* @param workMem working memory to update if this changes
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ClEventManagerWithEvent(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
- throws ControlLoopException {
+ public ClEventManagerWithEvent(EventManagerServices services, ControlLoopParams params,
+ VirtualControlLoopEvent event, WorkingMemory workMem) throws ControlLoopException {
- super(params, event.getRequestId(), workMem);
+ super(services, params, event.getRequestId(), workMem);
checkEventSyntax(event);
/**
* Constructs the object.
*
+ * @param services services the manager should use when processing the event
* @param params control loop parameters
* @param requestId event request ID
* @param workMem working memory to update if this changes
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ClEventManagerWithOutcome(ControlLoopParams params, UUID requestId, WorkingMemory workMem)
- throws ControlLoopException {
+ public ClEventManagerWithOutcome(EventManagerServices services, ControlLoopParams params, UUID requestId,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, requestId, workMem);
+ super(services, params, requestId, workMem);
}
@Override
/**
* Constructs the object.
*
+ * @param services services the manager should use when processing the event
* @param params control loop parameters
* @param requestId event request ID
* @param workMem working memory to update if this changes
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ClEventManagerWithSteps(ControlLoopParams params, UUID requestId, WorkingMemory workMem)
- throws ControlLoopException {
+ public ClEventManagerWithSteps(EventManagerServices services, ControlLoopParams params, UUID requestId,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, requestId);
+ super(services, params, requestId);
if (requestId == null) {
throw new ControlLoopException("No request ID");
private static final OperationHistoryDataManager STUB_DATA_MANAGER = new OperationHistoryDataManagerStub();
private static final String GUARD_DISABLED_PROPERTY = "guard.disabled";
- private static final String EVENT_MANAGER_SERVICE_CONFIG = "event-manager";
/**
* Counts the number of these objects that have been created. This is used by junit
*/
private transient boolean createdByThisJvmInstance;
+ private final transient EventManagerServices services;
+
@Getter
@ToString.Include
public final String closedLoopControlName;
/**
* Constructs the object.
*
+ * @param services services the manager should use when processing the event
* @param params control loop parameters
* @param requestId event request ID
* @throws ControlLoopException if the event is invalid or if a YAML processor cannot
* be created
*/
- public ControlLoopEventManager(ControlLoopParams params, UUID requestId) throws ControlLoopException {
+ public ControlLoopEventManager(EventManagerServices services, ControlLoopParams params, UUID requestId)
+ throws ControlLoopException {
createCount.incrementAndGet();
this.createdByThisJvmInstance = true;
+ this.services = services;
this.closedLoopControlName = params.getClosedLoopControlName();
this.requestId = requestId;
this.policyName = params.getPolicyName();
properties.remove(name);
}
- /**
- * Initializes various components, on demand.
- */
- private static class LazyInitData {
- private static final OperationHistoryDataManager DATA_MANAGER;
- private static final ActorService ACTOR_SERVICE;
-
- static {
- EventManagerServices services = new EventManagerServices(EVENT_MANAGER_SERVICE_CONFIG);
- ACTOR_SERVICE = services.getActorService();
- DATA_MANAGER = services.getDataManager();
- }
- }
-
// the following methods may be overridden by junit tests
public Executor getExecutor() {
}
public ActorService getActorService() {
- return LazyInitData.ACTOR_SERVICE;
+ return services.getActorService();
}
public OperationHistoryDataManager getDataManager() {
boolean guardDisabled = "true".equalsIgnoreCase(getEnvironmentProperty(GUARD_DISABLED_PROPERTY));
- return (guardDisabled ? STUB_DATA_MANAGER : LazyInitData.DATA_MANAGER);
+ return (guardDisabled ? STUB_DATA_MANAGER : services.getDataManager());
}
protected String getEnvironmentProperty(String propName) {
@Mock
private Actor policyActor;
@Mock
+ private EventManagerServices services;
+ @Mock
private ActorService actors;
@Mock
private OperationHistoryDataManager dataMgr;
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getActorService()).thenReturn(actors);
+ when(services.getDataManager()).thenReturn(dataMgr);
+
when(workMem.getFactHandle(any())).thenReturn(factHandle);
event = new VirtualControlLoopEvent();
locks = new ArrayList<>();
- mgr = new MyManager(params, event, workMem);
+ mgr = new MyManager(services, params, event, workMem);
}
@Test
// invalid
event.setTarget("");
- assertThatThrownBy(() -> new MyManager(params, event, workMem)).isInstanceOf(ControlLoopException.class);
+ assertThatThrownBy(() -> new MyManager(services, params, event, workMem))
+ .isInstanceOf(ControlLoopException.class);
}
@Test
public void testPopulateNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, event, workMem);
+ mgr = new MyManager(services, params, event, workMem);
// before started
assertNotNull(mgr.makeNotification());
private class MyManager extends ClEventManagerWithEvent<MyStep> {
private static final long serialVersionUID = 1L;
- public MyManager(ControlLoopParams params, VirtualControlLoopEvent event, WorkingMemory workMem)
- throws ControlLoopException {
+ public MyManager(EventManagerServices services, ControlLoopParams params, VirtualControlLoopEvent event,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, event, workMem);
+ super(services, params, event, workMem);
}
@Override
callback.lockAvailable(lock);
}
- @Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
@Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
import org.onap.policy.controlloop.ControlLoopException;
import org.onap.policy.controlloop.ControlLoopResponse;
import org.onap.policy.controlloop.VirtualControlLoopNotification;
-import org.onap.policy.controlloop.actorserviceprovider.ActorService;
import org.onap.policy.controlloop.actorserviceprovider.Operation;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
-import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
@Mock
private Actor policyActor;
@Mock
- private ActorService actors;
- @Mock
- private OperationHistoryDataManager dataMgr;
+ private EventManagerServices services;
@Mock
private ExecutorService executor;
@Mock
locks = new ArrayList<>();
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
}
@Test
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
- assertThatThrownBy(() -> new MyManager(params, null, workMem)).isInstanceOf(ControlLoopException.class);
+ assertThatThrownBy(() -> new MyManager(services, params, null, workMem))
+ .isInstanceOf(ControlLoopException.class);
}
@Test
public void testLoadNextPolicy_testGetFullHistory_testGetPartialHistory() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
// start and load step for first policy
mgr.start();
@Test
public void testMakeNotification() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
// before started
assertNotNull(mgr.makeNotification());
private class MyManager extends ClEventManagerWithOutcome<MyStep> {
private static final long serialVersionUID = 1L;
- public MyManager(ControlLoopParams params, UUID requestId, WorkingMemory workMem) throws ControlLoopException {
+ public MyManager(EventManagerServices services, ControlLoopParams params, UUID requestId, WorkingMemory workMem)
+ throws ControlLoopException {
- super(params, requestId, workMem);
+ super(services, params, requestId, workMem);
}
@Override
callback.lockAvailable(lock);
}
- @Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
@Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
import org.onap.policy.controlloop.actorserviceprovider.parameters.ControlLoopOperationParams;
import org.onap.policy.controlloop.actorserviceprovider.spi.Actor;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
-import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
import org.onap.policy.drools.core.lock.LockState;
@Mock
private Actor policyActor;
@Mock
- private ActorService actors;
+ private ExecutorService executor;
@Mock
- private OperationHistoryDataManager dataMgr;
+ private EventManagerServices services;
@Mock
- private ExecutorService executor;
+ private ActorService actors;
@Mock
private MyStep stepa;
@Mock
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getActorService()).thenReturn(actors);
+
when(workMem.getFactHandle(any())).thenReturn(factHandle);
params = new ControlLoopParams();
locks = new ArrayList<>();
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
}
@Test
assertEquals(POLICY_NAME, mgr.getPolicyName());
// invalid
- assertThatThrownBy(() -> new MyManager(params, null, workMem)).isInstanceOf(ControlLoopException.class);
+ assertThatThrownBy(() -> new MyManager(services, params, null, workMem))
+ .isInstanceOf(ControlLoopException.class);
}
@Test
@Test
public void testStartInactive() throws Exception {
// make an inactive manager by deserializing it
- RealManager mgr2 = Serializer.roundTrip(new RealManager(params, REQ_ID, workMem));
+ RealManager mgr2 = Serializer.roundTrip(new RealManager(services, params, REQ_ID, workMem));
mgr = mgr2;
// cannot re-start
@Test
public void testLoadNextPolicy() throws Exception {
loadPolicy(EVENT_MGR_MULTI_YAML);
- mgr = new MyManager(params, REQ_ID, workMem);
+ mgr = new MyManager(services, params, REQ_ID, workMem);
// start and load step for first policy
mgr.start();
private class MyManager extends ClEventManagerWithSteps<MyStep> {
private static final long serialVersionUID = 1L;
- public MyManager(ControlLoopParams params, UUID requestId, WorkingMemory workMem) throws ControlLoopException {
+ public MyManager(EventManagerServices services, ControlLoopParams params, UUID requestId, WorkingMemory workMem)
+ throws ControlLoopException {
- super(params, requestId, workMem);
+ super(services, params, requestId, workMem);
}
@Override
callback.lockAvailable(lock);
}
- @Override
- public ActorService getActorService() {
- return actors;
- }
-
- @Override
- public OperationHistoryDataManager getDataManager() {
- return dataMgr;
- }
-
@Override
protected PolicyEngine getPolicyEngineManager() {
return engineMgr;
private static class RealManager extends ClEventManagerWithSteps<MyStep> {
private static final long serialVersionUID = 1L;
- public RealManager(ControlLoopParams params, UUID requestId, WorkingMemory workMem)
- throws ControlLoopException {
+ public RealManager(EventManagerServices services, ControlLoopParams params, UUID requestId,
+ WorkingMemory workMem) throws ControlLoopException {
- super(params, requestId, workMem);
+ super(services, params, requestId, workMem);
}
@Override
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.ArrayList;
import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
import org.onap.policy.controlloop.drl.legacy.ControlLoopParams;
+import org.onap.policy.controlloop.ophistory.OperationHistoryDataManager;
import org.onap.policy.controlloop.ophistory.OperationHistoryDataManagerStub;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockImpl;
@Mock
private ExecutorService executor;
+ @Mock
+ private EventManagerServices services;
+ @Mock
+ private OperationHistoryDataManager dataMgr;
private long preCreateTimeMs;
private List<LockImpl> locks;
*/
@Before
public void setUp() throws ControlLoopException, CoderException {
+ when(services.getDataManager()).thenReturn(dataMgr);
+
params = new ControlLoopParams();
params.setClosedLoopControlName(CL_NAME);
params.setPolicyName(POLICY_NAME);
MyManager.executor = executor;
MyManager.locks = locks;
- mgr = new MyManager(params, REQ_ID);
+ mgr = new MyManager(services, params, REQ_ID);
}
@Test
public void testGetCreateCount() throws ControlLoopException {
long original = ControlLoopEventManager.getCreateCount();
- new MyManager(params, REQ_ID);
+ new MyManager(services, params, REQ_ID);
assertEquals(original + 1, ControlLoopEventManager.getCreateCount());
- new MyManager(params, REQ_ID);
+ new MyManager(services, params, REQ_ID);
assertEquals(original + 2, ControlLoopEventManager.getCreateCount());
}
@Test
public void testIsActive() throws Exception {
- mgr = new ControlLoopEventManager(params, REQ_ID);
+ mgr = new ControlLoopEventManager(services, params, REQ_ID);
assertTrue(mgr.isActive());
ControlLoopEventManager mgr2 = Serializer.roundTrip(mgr);
*/
@Test
public void testReleaseLockException() throws ControlLoopException {
- mgr = new MyManager(params, REQ_ID) {
+ mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@Override
assertFalse(mgr.contains(MY_KEY));
}
+ /**
+ * Tests getDataManager() when not disabled.
+ */
+ @Test
+ public void testGetDataManagerNotDisabled() throws ControlLoopException {
+ assertThat(mgr.getDataManager()).isSameAs(dataMgr);
+ }
+
/**
* Tests getDataManager() when guard.disabled=true.
*/
@Test
public void testGetDataManagerDisabled() throws ControlLoopException {
- mgr = new MyManager(params, REQ_ID) {
+ mgr = new MyManager(services, params, REQ_ID) {
private static final long serialVersionUID = 1L;
@Override
private static ExecutorService executor;
private static List<LockImpl> locks;
- public MyManager(ControlLoopParams params, UUID requestId) throws ControlLoopException {
- super(params, requestId);
+ public MyManager(EventManagerServices services, ControlLoopParams params, UUID requestId)
+ throws ControlLoopException {
+ super(services, params, requestId);
}
@Override