From 673b49e2a9561cd1c82717523e29da497c91c804 Mon Sep 17 00:00:00 2001 From: Chris Goldthorpe Date: Thu, 13 Oct 2011 10:10:03 -0700 Subject: Fix tests for Search index locking to work on SUN JREs --- .../org/eclipse/ua/tests/help/search/LockTest.java | 42 ++++++++++++++++------ 1 file changed, 32 insertions(+), 10 deletions(-) (limited to 'org.eclipse.ua.tests/help/org') diff --git a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/LockTest.java b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/LockTest.java index b5a69408c..55ffa0f20 100644 --- a/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/LockTest.java +++ b/org.eclipse.ua.tests/help/org/eclipse/ua/tests/help/search/LockTest.java @@ -11,6 +11,8 @@ package org.eclipse.ua.tests.help.search; +import java.nio.channels.OverlappingFileLockException; + import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; @@ -28,18 +30,30 @@ public class LockTest extends TestCase { public void testSingleLock() { SearchIndex index1 = new SearchIndex(null, null, null); - boolean try1 = index1.tryLock(); - assertTrue(try1); + try { + boolean try1 = index1.tryLock(); + assertTrue(try1); + } catch (OverlappingFileLockException e1) { + fail("Exception thrown"); + } index1.releaseLock(); } public void testCompetingLocks() { SearchIndex index1 = new SearchIndex(null, null, null); - boolean try1 = index1.tryLock(); - assertTrue(try1); + try { + boolean try1 = index1.tryLock(); + assertTrue(try1); + } catch (OverlappingFileLockException e1) { + fail("Exception thrown"); + } SearchIndex index2 = new SearchIndex(null, null, null); - boolean try2 = index2.tryLock(); - assertFalse(try2); + try { + boolean try2 = index2.tryLock(); + assertFalse(try2); + } catch (OverlappingFileLockException e) { + // Throwing this exception or returning false is the expected result + } index1.releaseLock(); index2.releaseLock(); } @@ -47,12 +61,20 @@ public class LockTest extends TestCase { public void testNonCompetingLocks() { SearchIndex index1 = new SearchIndex(null, null, null); - boolean try1 = index1.tryLock(); - assertTrue(try1); + try { + boolean try1 = index1.tryLock(); + assertTrue(try1); + } catch (OverlappingFileLockException e1) { + fail("Exception thrown"); + } index1.releaseLock(); SearchIndex index2 = new SearchIndex(null, null, null); - boolean try2 = index2.tryLock(); - assertTrue(try2); + try { + boolean try2 = index2.tryLock(); + assertTrue(try2); + } catch (OverlappingFileLockException e) { + fail("Exception thrown"); + } index2.releaseLock(); } -- cgit v1.2.3