Search in sources :

Example 1 with NodesRecoveryManager

use of org.ow2.proactive.resourcemanager.core.recovery.NodesRecoveryManager in project scheduling by ow2-proactive.

the class RMCoreTest method populateRMCore.

/**
 * 6 nodes (same nodesource).
 */
private void populateRMCore() {
    when(mockedCaller.checkPermission(any(Permission.class), any(String.class), any(Permission.class))).thenReturn(true);
    when(mockedSelectionManager.selectNodes(any(Criteria.class), any(Client.class))).thenReturn(new NodeSet());
    nodeSources = new HashMap<String, NodeSource>(1);
    configureNodeSource(mockedNodeSource, "NODESOURCE-test");
    nodeSources.put(mockedNodeSource.getName(), mockedNodeSource);
    // MockedRMNodeParameters(String url, boolean isFree, boolean isDown, boolean isLocked, NodeSource nodeSource, RMNode rmNode)
    configureRMNode(new MockedRMNodeParameters("mockedRemovableNode", true, true, false, mockedNodeSource, "NODESOURCE-test", mockedRemovableNode));
    configureRMNode(new MockedRMNodeParameters("mockedUnremovableNode", false, true, false, mockedNodeSource, "NODESOURCE-test", mockedUnremovableNode));
    configureRMNode(new MockedRMNodeParameters(RMDeployingNode.PROTOCOL_ID + "://removableNode", true, true, false, mockedNodeSource, "NODESOURCE-test", mockedRemovableNodeInDeploy));
    configureRMNode(new MockedRMNodeParameters(RMDeployingNode.PROTOCOL_ID + "://unRemovableNode", false, false, false, mockedNodeSource, "NODESOURCE-test", mockedUnremovableNodeInDeploy));
    configureRMNode(new MockedRMNodeParameters("mockedBusyNode", false, false, true, mockedNodeSource, "NODESOURCE-test", mockedBusyNode));
    configureRMNode(new MockedRMNodeParameters("mockedFreeButLockedNode", true, false, true, mockedNodeSource, "NODESOURCE-test", mockedFreeButLockedNode));
    HashMap<String, RMNode> nodes = new HashMap<>(6);
    nodes.put(mockedRemovableNodeInDeploy.getNodeName(), mockedRemovableNodeInDeploy);
    nodes.put(mockedUnremovableNodeInDeploy.getNodeName(), mockedUnremovableNodeInDeploy);
    nodes.put(mockedRemovableNode.getNodeName(), mockedRemovableNode);
    nodes.put(mockedUnremovableNode.getNodeName(), mockedUnremovableNode);
    nodes.put(mockedBusyNode.getNodeName(), mockedBusyNode);
    nodes.put(mockedFreeButLockedNode.getNodeName(), mockedFreeButLockedNode);
    ArrayList<RMNode> freeNodes = new ArrayList<>(3);
    freeNodes.add(mockedRemovableNodeInDeploy);
    freeNodes.add(mockedRemovableNode);
    freeNodes.add(mockedFreeButLockedNode);
    rmCore = new RMCore(nodeSources, nodes, mockedCaller, mockedMonitoring, mockedSelectionManager, freeNodes, dbManager);
    rmCore.signalRMCoreIsInitialized();
    rmCore = spy(rmCore);
    nodesLockRestorationManager = new NodesLockRestorationManager(rmCore);
    nodesLockRestorationManager = spy(nodesLockRestorationManager);
    doReturn(new Function<RMCore, NodesRecoveryManager>() {

        @Override
        public NodesRecoveryManager apply(RMCore rmCore) {
            nodesRecoveryManager = new NodesRecoveryManager(rmCore);
            nodesRecoveryManager = spy(nodesRecoveryManager);
            return nodesRecoveryManager;
        }
    }).when(rmCore).getNodesRecoveryManagerBuilder();
    doReturn(mockedCaller).when(rmCore).checkPermissionAndGetClientIsSuccessful();
    rmCore.initiateRecoveryIfRequired();
}
Also used : NodeSet(org.ow2.proactive.utils.NodeSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Criteria(org.ow2.proactive.utils.Criteria) NodeSource(org.ow2.proactive.resourcemanager.nodesource.NodeSource) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) NodesLockRestorationManager(org.ow2.proactive.resourcemanager.core.recovery.NodesLockRestorationManager) Permission(java.security.Permission) NodesRecoveryManager(org.ow2.proactive.resourcemanager.core.recovery.NodesRecoveryManager) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 2 with NodesRecoveryManager

use of org.ow2.proactive.resourcemanager.core.recovery.NodesRecoveryManager in project scheduling by ow2-proactive.

the class NodesRecoveryManagerTest method setUp.

@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    nodesLockRestorationManager = null;
    nodesRecoveryManager = new NodesRecoveryManager(rmCore);
    nodesRecoveryManager = spy(nodesRecoveryManager);
    nodesLockRestorationManager = null;
    doReturn((Function<RMCore, NodesLockRestorationManager>) rmCore -> {
        nodesLockRestorationManager = new NodesLockRestorationManager(rmCore);
        nodesLockRestorationManager = spy(nodesLockRestorationManager);
        doReturn(Maps.newHashMap()).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
        return nodesLockRestorationManager;
    }).when(nodesRecoveryManager).getNodesLockRestorationManagerBuilder();
    initialize();
}
Also used : RMCore(org.ow2.proactive.resourcemanager.core.RMCore) Mock(org.mockito.Mock) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) Mockito.spy(org.mockito.Mockito.spy) NodesLockRestorationManager(org.ow2.proactive.resourcemanager.core.recovery.NodesLockRestorationManager) Function(java.util.function.Function) Maps(com.google.common.collect.Maps) Mockito.verify(org.mockito.Mockito.verify) PAResourceManagerProperties(org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties) MockitoAnnotations(org.mockito.MockitoAnnotations) RMCore(org.ow2.proactive.resourcemanager.core.RMCore) Mockito.never(org.mockito.Mockito.never) NodesRecoveryManager(org.ow2.proactive.resourcemanager.core.recovery.NodesRecoveryManager) Mockito.doReturn(org.mockito.Mockito.doReturn) Before(org.junit.Before) NodesLockRestorationManager(org.ow2.proactive.resourcemanager.core.recovery.NodesLockRestorationManager) NodesRecoveryManager(org.ow2.proactive.resourcemanager.core.recovery.NodesRecoveryManager) Before(org.junit.Before)

Aggregations

NodesLockRestorationManager (org.ow2.proactive.resourcemanager.core.recovery.NodesLockRestorationManager)2 NodesRecoveryManager (org.ow2.proactive.resourcemanager.core.recovery.NodesRecoveryManager)2 Maps (com.google.common.collect.Maps)1 Truth.assertThat (com.google.common.truth.Truth.assertThat)1 Permission (java.security.Permission)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 Function (java.util.function.Function)1 Before (org.junit.Before)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 Mock (org.mockito.Mock)1 Mockito.doReturn (org.mockito.Mockito.doReturn)1 Mockito.never (org.mockito.Mockito.never)1 Mockito.spy (org.mockito.Mockito.spy)1 Mockito.verify (org.mockito.Mockito.verify)1 MockitoAnnotations (org.mockito.MockitoAnnotations)1 Client (org.ow2.proactive.resourcemanager.authentication.Client)1 RMCore (org.ow2.proactive.resourcemanager.core.RMCore)1 PAResourceManagerProperties (org.ow2.proactive.resourcemanager.core.properties.PAResourceManagerProperties)1