@@ -0,0 +1,3056 @@
+/*%0A * LensKit, an open source recommender systems toolkit.%0A * Copyright 2010-2016 LensKit Contributors.  See CONTRIBUTORS.md.%0A * Work on LensKit has been funded by the National Science Foundation under%0A * grants IIS 05-34939, 08-08692, 08-12148, and 10-17697.%0A *%0A * This program is free software; you can redistribute it and/or modify%0A * it under the terms of the GNU Lesser General Public License as%0A * published by the Free Software Foundation; either version 2.1 of the%0A * License, or (at your option) any later version.%0A *%0A * This program is distributed in the hope that it will be useful, but WITHOUT%0A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS%0A * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more%0A * details.%0A *%0A * You should have received a copy of the GNU General Public License along with%0A * this program; if not, write to the Free Software Foundation, Inc., 51%0A * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.%0A */%0Apackage org.lenskit.util.parallel;%0A%0Aimport com.google.common.util.concurrent.Monitor;%0Aimport org.junit.Test;%0Aimport org.lenskit.util.UncheckedInterruptException;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.concurrent.ForkJoinPool;%0Aimport java.util.concurrent.RecursiveAction;%0Aimport java.util.concurrent.Semaphore;%0Aimport java.util.concurrent.atomic.AtomicInteger;%0A%0Aimport static org.hamcrest.Matchers.*;%0Aimport static org.junit.Assert.assertThat;%0A%0Apublic class BlockersTest %7B%0A    @Test%0A    public void testAcquireMonitor() %7B%0A        Monitor monitor = new Monitor();%0A        ForkJoinPool.commonPool().invoke(new RecursiveAction() %7B%0A            AtomicInteger running = new AtomicInteger();%0A%0A            @Override%0A            protected void compute() %7B%0A                List%3CRecursiveAction%3E actions = new ArrayList%3C%3E();%0A                for (int i = 0; i %3C 6; i++) %7B%0A                    actions.add(new RecursiveAction() %7B%0A                        @Override%0A                        protected void compute() %7B%0A                            try %7B%0A                                Blockers.enterMonitor(monitor);%0A                                try %7B%0A                                    assertThat(monitor.isOccupiedByCurrentThread(), equalTo(true));%0A                                    int n = running.incrementAndGet();%0A                                    assertThat(n, equalTo(1));%0A                                    Thread.sleep(100);%0A                                    running.decrementAndGet();%0A                                %7D finally %7B%0A                                    monitor.leave();%0A                                %7D%0A                            %7D catch (InterruptedException e) %7B%0A                                throw new UncheckedInterruptException(e);%0A                            %7D%0A                        %7D%0A                    %7D);%0A                %7D%0A                invokeAll(actions);%0A                for (RecursiveAction action: actions) %7B%0A                    action.join();%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A%0A%7D

Add test for monitor blocker utility