Search in sources :

Example 1 with NodesLockRestorationManager

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

the class NodesLockRestorationManagerTest method testHandleNotInitialized.

@Test
public void testHandleNotInitialized() {
    // creates a node that matches an entry in the table specifying the nodes to lock
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns1", "n1", "h1", "nurl1", "parurl1").getLeft();
    assertThat(rmNode.isLocked()).isFalse();
    Map<String, MutableInteger> table = Maps.newHashMap();
    MutableInteger putResult = table.put("ns", new MutableInteger(1));
    assertThat(putResult).isNull();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.handle(rmNode, caller);
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Example 2 with NodesLockRestorationManager

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

the class NodesLockRestorationManagerTest method testHandleNodeAlreadyLocked.

@Test
public void testHandleNodeAlreadyLocked() {
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns1", "n1", "h1", "nurl1", "parurl1").getLeft();
    rmNode.lock(null);
    assertThat(rmNode.isLocked()).isTrue();
    Map<String, MutableInteger> table = Maps.newHashMap();
    MutableInteger putResult = table.put("ns", new MutableInteger(1));
    assertThat(putResult).isNull();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    nodesLockRestorationManager.initialize();
    assertThat(nodesLockRestorationManager.isInitialized()).isTrue();
    verify(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.handle(rmNode, caller);
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Example 3 with NodesLockRestorationManager

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

the class NodesLockRestorationManagerTest method testHandleNotInitialized.

@Test
public void testHandleNotInitialized() {
    // creates a node that matches an entry in the table specifying the nodes to lock
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns1", "n1", "h1", "nurl1", "parurl1").getLeft();
    assertThat(rmNode.isLocked()).isFalse();
    Map<String, MutableInteger> table = Maps.newHashMap();
    MutableInteger putResult = table.put("ns", new MutableInteger(1));
    assertThat(putResult).isNull();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.handle(rmNode, caller);
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Example 4 with NodesLockRestorationManager

use of org.ow2.proactive.resourcemanager.core.recovery.NodesLockRestorationManager 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 5 with NodesLockRestorationManager

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

the class NodesLockRestorationManagerTest method testHandleNoNodesToLock.

@Test
public void testHandleNoNodesToLock() {
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns1", "n1", "h1", "nurl1", "parurl1").getLeft();
    assertThat(rmNode.isLocked()).isFalse();
    Map<String, MutableInteger> table = Maps.newHashMap();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    nodesLockRestorationManager.initialize();
    assertThat(nodesLockRestorationManager.isInitialized()).isTrue();
    verify(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(0);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.handle(rmNode, caller);
    assertThat(table).hasSize(0);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
}
Also used : MutableInteger(org.objectweb.proactive.core.util.MutableInteger) RMNodeImpl(org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)11 MutableInteger (org.objectweb.proactive.core.util.MutableInteger)10 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)10 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)2 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 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