@Test public void testLockAquiredDuringExecution() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); try { concurrentV8.run(new V8Runnable() { @Override public void run(final V8 runtime) { assertTrue(runtime.getLocker().hasLock()); } }); } catch (Exception e) { // do nothing } concurrentV8.release(); }
@Test public void shouldShareV8AcrossThreads() { final ConcurrentV8 v8 = new ConcurrentV8();
@Test public void testConstructorWithoutV8() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); assertNotNull(concurrentV8.getV8()); concurrentV8.release(); }
@Test public void exceptionsShouldBeRaised() { ConcurrentV8 v8 = new ConcurrentV8(); final ExceptionThrower exceptionThrower = new ExceptionThrower(); v8.run(new V8Runnable() { @Override public void run(final V8 v8) { v8.registerJavaMethod(exceptionThrower, "whine", "whine", new Class[0]); } }); try { v8.run(new V8Runnable() { @Override public void run(final V8 v8) { v8.executeScript("whine();"); } }); Assert.fail("Regular concurrent V8 invocations should pass on exceptions."); } catch (Exception e) { assertEquals("Whaaa!", e.getCause().getMessage()); } v8.release(); } }
@Test public void testLockNotAquiredAfterCreation() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }
@Test public void testLockNotAcquiredAfterExecution() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); concurrentV8.run(new V8Runnable() { @Override public void run(final V8 runtime) { runtime.executeScript("foo = 7;"); } }); assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }
@Test public void testLockNotAquiredAfterException() { ConcurrentV8 concurrentV8 = new ConcurrentV8(); try { concurrentV8.run(new V8Runnable() { @Override public void run(final V8 runtime) { runtime.executeScript("throw 'my exception';"); } }); } catch (Exception e) { // do nothing } assertFalse(concurrentV8.getV8().getLocker().hasLock()); concurrentV8.release(); }