Search in sources :

Example 6 with NodesLockRestorationManager

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

the class NodesLockRestorationManagerTest method testHandleMatchingNode.

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

Example 7 with NodesLockRestorationManager

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

the class NodesLockRestorationManagerTest method testHandleNonMatchingNode.

@Test
public void testHandleNonMatchingNode() {
    RMNodeImpl rmNode = RMNodeHelper.basicWithMockedInternals("ns2", "n1", "h1", "nurl1", "parurl1").getLeft();
    assertThat(rmNode.isLocked()).isFalse();
    Map<String, MutableInteger> table = Maps.newHashMap();
    MutableInteger putResult = table.put("ns1", new MutableInteger(1));
    assertThat(putResult).isNull();
    doReturn(table).when(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    assertThat(table).hasSize(1);
    verify(rmCore, never()).lockNodes(anySetOf(String.class));
    nodesLockRestorationManager.initialize();
    assertThat(nodesLockRestorationManager.isInitialized()).isTrue();
    verify(nodesLockRestorationManager).findNodesLockedOnPreviousRun();
    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 NodesLockRestorationManager

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

Example 9 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 10 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