@Override public void execute(final LockInfo lockInfo) { if (!lockRequestPending && !unlockRequestPending) { updateLockInfo(lockInfo); } } };
@Override public void execute(final LockResult result) { if (result.isSuccess()) { updateLockInfo(result.getLockInfo()); releaseLockOnClose(); } else { handleLockFailure(result.getLockInfo()); } lockRequestPending = false; } };
@Override public void execute(final LockResult result) { updateLockInfo(result.getLockInfo()); if (result.isSuccess()) { if (closeHandler != null) { closeHandler.removeHandler(); } } unlockRequestPending = false; } };
@Test public void testUpdateLockInfoWhenLockTargetIsNull() { final LockInfo lockInfo = mock(LockInfo.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); doReturn(null).when(lockManager).getLockTarget(); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsNotEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file1.drl"); when(this.path.toURI()).thenReturn("directory/file2.drl"); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockTargetIsNull() { final LockInfo lockInfo = mock(LockInfo.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); doReturn(null).when(lockManager).getLockTarget(); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsNotEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file1.drl"); when(this.path.toURI()).thenReturn("directory/file2.drl"); lockManager.updateLockInfo(lockInfo); assertNotEquals(lockInfo, lockManager.getLockInfo()); assertFalse(lockManager.isLockSyncComplete()); verify(lockManager, never()).fireChangeTitleEvent(); verify(lockManager, never()).fireUpdatedLockStatusEvent(); verify(runnable1, never()).run(); verify(runnable2, never()).run(); verify(runnables, never()).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file.drl"); when(this.path.toURI()).thenReturn("directory/file.drl"); lockManager.updateLockInfo(lockInfo); assertEquals(lockInfo, lockManager.getLockInfo()); assertTrue(lockManager.isLockSyncComplete()); verify(lockManager).fireChangeTitleEvent(); verify(lockManager).fireUpdatedLockStatusEvent(); verify(runnable1).run(); verify(runnable2).run(); verify(runnables).clear(); }
@Test public void testUpdateLockInfoWhenLockInfoURIIsEqualToLockTargetURI() { final LockInfo lockInfo = mock(LockInfo.class); final Path path = mock(Path.class); final Runnable runnable1 = mock(Runnable.class); final Runnable runnable2 = mock(Runnable.class); final List<Runnable> runnables = spy(new ArrayList<>(Arrays.asList(runnable1, runnable2))); doReturn(runnables).when(lockManager).getSyncCompleteRunnables(); when(lockInfo.getFile()).thenReturn(path); when(path.toURI()).thenReturn("directory/file.drl"); when(this.path.toURI()).thenReturn("directory/file.drl"); lockManager.updateLockInfo(lockInfo); assertEquals(lockInfo, lockManager.getLockInfo()); assertTrue(lockManager.isLockSyncComplete()); verify(lockManager).fireChangeTitleEvent(); verify(lockManager).fireUpdatedLockStatusEvent(); verify(runnable1).run(); verify(runnable2).run(); verify(runnables).clear(); }
private void handleLockFailure(final LockInfo lockInfo) { if (lockInfo != null) { updateLockInfo(lockInfo); lockNotification.fire(new NotificationEvent(WorkbenchConstants.INSTANCE.lockedMessage(lockInfo.lockedBy()), NotificationEvent.NotificationType.INFO, true, lockTarget.getPlace(), 20)); } else { lockNotification.fire(new NotificationEvent(WorkbenchConstants.INSTANCE.lockError(), NotificationEvent.NotificationType.ERROR, true, lockTarget.getPlace(), 20)); } // Delay reloading slightly in case we're dealing with a flood of events if (reloadTimer == null) { reloadTimer = new Timer() { public void run() { reload(); } }; } if (!reloadTimer.isRunning()) { reloadTimer.schedule(250); } }