Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 package org.uberfire.io.lock;
 
 import org.junit.Test;
 import  org.uberfire.commons.lock.impl.ThreadLockServiceImpl;
 
 import static org.fest.assertions.api.Assertions.*;
 
 public class ThreadLockServiceTest {
 
    @Test
    public void testLock() {
        final ThreadLockServiceImpl lockService = new ThreadLockServiceImpl();
        lockService.lock();
        lockService.unlock();
    }
    @Test
    public void testDoubleLock() {
        final ThreadLockServiceImpl lockService = new ThreadLockServiceImpl();
        lockService.lock();
        lockService.lock();
        lockService.unlock();
        lockService.unlock();
    }
    @Test(expected = IllegalMonitorStateException.class)
    public void testUnlock() {
        final ThreadLockServiceImpl lockService = new ThreadLockServiceImpl();
        lockService.lock();
        lockService.lock();
        lockService.unlock();
        lockService.unlock();
        lockService.unlock();
    }
    @Test
    public void testOnThreads() throws InterruptedException {
        for ( int i = 0; i < 100; i++ ) {
            final ThreadLockServiceImpl lockService = new ThreadLockServiceImpl();
            final boolean[] vals = new boolean[]{ false };
            lockService.lock();
            Thread thread = new Threadnew Runnable() {
                @Override
                public void run() {
                    lockService.lock();
                    vals[ 0 ] = true;
                }
            } );
            thread.setName"temp" );
            assertThatvals[ 0 ] ).isEqualTofalse );
            thread.start();
            assertThatvals[ 0 ] ).isEqualTofalse );
            lockService.unlock();
            Thread.sleep( 120 );
            assertThatvals[ 0 ] ).isEqualTotrue );
        }
    }
New to GrepCode? Check out our FAQ X