Search in sources :

Example 6 with RMCore

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

use of org.ow2.proactive.resourcemanager.core.RMCore 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 8 with RMCore

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

the class NodesLockRestorationManagerTest method testLockNodeFails.

@Test
public void testLockNodeFails() {
    doReturn(new BooleanWrapper(false)).when(rmCore).lockNodes(anySetOf(String.class), eq(caller));
    verify(rmCore, never()).lockNodes(anySetOf(String.class), eq(caller));
    RMNode rmNode = RMNodeHelper.basicWithMockedInternals().getLeft();
    boolean lockResult = nodesLockRestorationManager.lockNode(rmNode, caller);
    assertThat(lockResult).isFalse();
    verify(rmCore).lockNodes(anySetOf(String.class), eq(caller));
}
Also used : BooleanWrapper(org.objectweb.proactive.core.util.wrapper.BooleanWrapper) RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Test(org.junit.Test)

Example 9 with RMCore

use of org.ow2.proactive.resourcemanager.core.RMCore 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))).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();
    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) Permission(java.security.Permission) Client(org.ow2.proactive.resourcemanager.authentication.Client)

Example 10 with RMCore

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

the class RMCoreTest method testSetNodesAvailableUnknownNodeUrl.

@Test
public void testSetNodesAvailableUnknownNodeUrl() throws ActiveObjectCreationException, NodeException {
    ImmutableMap<String, RMNode> allNodes = ImmutableMap.of(mockedBusyNode.getNodeURL(), mockedBusyNode);
    List<RMNode> freeNodes = Collections.emptyList();
    RMCore rmCore = createRmCore(allNodes, freeNodes);
    String unknownNodeUrl = mockedRemovableNode.getNodeURL();
    Set<String> unknownNodeUrls = rmCore.setNodesAvailable(ImmutableSet.of(unknownNodeUrl));
    assertThat(unknownNodeUrls).hasSize(1);
    assertThat(unknownNodeUrls).contains(unknownNodeUrl);
}
Also used : RMNode(org.ow2.proactive.resourcemanager.rmnode.RMNode) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)17 RMNode (org.ow2.proactive.resourcemanager.rmnode.RMNode)11 RMCore (org.ow2.proactive.resourcemanager.core.RMCore)8 Criteria (org.ow2.proactive.utils.Criteria)8 BooleanWrapper (org.objectweb.proactive.core.util.wrapper.BooleanWrapper)7 Client (org.ow2.proactive.resourcemanager.authentication.Client)7 NodeSource (org.ow2.proactive.resourcemanager.nodesource.NodeSource)7 NodeSet (org.ow2.proactive.utils.NodeSet)7 RMNodeImpl (org.ow2.proactive.resourcemanager.rmnode.RMNodeImpl)6 Node (org.objectweb.proactive.core.node.Node)5 MutableInteger (org.objectweb.proactive.core.util.MutableInteger)5 RMException (org.ow2.proactive.resourcemanager.exception.RMException)5 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)4 Matchers.anyString (org.mockito.Matchers.anyString)4 ActiveObjectCreationException (org.objectweb.proactive.ActiveObjectCreationException)4 TopologyManager (org.ow2.proactive.resourcemanager.selection.topology.TopologyManager)4 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)3 KeyException (java.security.KeyException)3 HashMap (java.util.HashMap)3