Search in sources :

Example 11 with Lock

use of com.twitter.heron.spi.statemgr.Lock in project incubator-heron by apache.

the class LocalFileSystemStateManagerTest method testGetLock.

@Test
public void testGetLock() throws Exception {
    initMocks();
    String expectedLockPath = String.format("//locks/%s__%s", TOPOLOGY_NAME, LOCK_NAME.getName());
    byte[] expectedContents = Thread.currentThread().getName().getBytes(Charset.defaultCharset());
    Lock lock = manager.getLock(TOPOLOGY_NAME, LOCK_NAME);
    assertTrue(lock.tryLock(0, TimeUnit.MILLISECONDS));
    assertWriteToFile(expectedLockPath, expectedContents, false);
    lock.unlock();
    assertDeleteFile(expectedLockPath);
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) Lock(com.twitter.heron.spi.statemgr.Lock) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with Lock

use of com.twitter.heron.spi.statemgr.Lock in project incubator-heron by apache.

the class UpdateTopologyManagerTest method mockLock.

private static Lock mockLock(boolean available) throws InterruptedException {
    Lock lock = mock(Lock.class);
    when(lock.tryLock(any(Long.class), any(TimeUnit.class))).thenReturn(available);
    return lock;
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Lock(com.twitter.heron.spi.statemgr.Lock)

Aggregations

Lock (com.twitter.heron.spi.statemgr.Lock)12 Test (org.junit.Test)8 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)8 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)4 TimeUnit (java.util.concurrent.TimeUnit)4 Matchers.anyString (org.mockito.Matchers.anyString)4 PackingPlans (com.twitter.heron.proto.system.PackingPlans)2 IScalable (com.twitter.heron.spi.scheduler.IScalable)2 Path (java.nio.file.Path)2 ConcurrentModificationException (java.util.ConcurrentModificationException)2 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)1 Resource (com.twitter.heron.spi.packing.Resource)1 HashSet (java.util.HashSet)1