private void releaseIfEmptyInflight() { synchronized (lock) { if (inflight.isEmpty()) { log.trace("Inflight empty for writer {}", writerId); waitingInflight.release(); } } }
private void releaseFlush() { flushLatch.release(); }
connectionSetupCompleted = null; if (closed || throwable instanceof SegmentSealedException) { waitingInflight.release();
this.emptyNotifier.release(); this.emptyNotifier = null;
private void invokeResendCallBack(WireCommand wireCommand) { if (state.needSuccessors.compareAndSet(false, true)) { Retry.indefinitelyWithExpBackoff(retrySchedule.getInitialMillis(), retrySchedule.getMultiplier(), retrySchedule.getMaxDelay(), t -> log.error(writerId + " to invoke resendToSuccessors callback: ", t)) .runInExecutor(() -> { log.debug("Invoking resendToSuccessors call back for {} on writer {}", wireCommand, writerId); resendToSuccessorsCallback.accept(Segment.fromScopedName(getSegmentName())); }, connectionFactory.getInternalExecutor()) .thenRun(() -> { log.trace("Release inflight latch for writer {}", writerId); state.waitingInflight.release(); }); } }
@Test public void endOfStreamNotifierTest() throws Exception { AtomicBoolean listenerInvoked = new AtomicBoolean(); ReusableLatch latch = new ReusableLatch(); when(state.isEndOfData()).thenReturn(false).thenReturn(true); when(sync.getState()).thenReturn(state); Listener<EndOfDataNotification> listener1 = notification -> { log.info("listener 1 invoked"); listenerInvoked.set(true); latch.release(); }; Listener<EndOfDataNotification> listener2 = notification -> { }; EndOfDataNotifier notifier = new EndOfDataNotifier(system, sync, executor); notifier.registerListener(listener1); verify(executor, times(1)).scheduleAtFixedRate(any(Runnable.class), anyLong(), anyLong(), any(TimeUnit.class)); latch.await(); verify(state, times(2)).isEndOfData(); assertTrue(listenerInvoked.get()); notifier.registerListener(listener2); verify(executor, times(1)).scheduleAtFixedRate(any(Runnable.class), anyLong(), anyLong(), any(TimeUnit.class)); notifier.unregisterAllListeners(); verify(system, times(1)).removeListeners(EndOfDataNotification.class.getSimpleName()); }
@Test(timeout = 5000) public void testRelease() { ReusableLatch latch = new ReusableLatch(false); AssertExtensions.assertBlocks(() -> latch.awaitUninterruptibly(), () -> latch.release()); }
@Test(timeout = 5000) public void testAlreadyRelease() throws InterruptedException { ReusableLatch latch = new ReusableLatch(false); latch.release(); latch.await(); latch = new ReusableLatch(true); latch.await(); }
invoked.get(operation).release(); Exceptions.handleInterrupted(() -> waitOn.get(operation).await()); return null; waitOn.get(op1).release(); invoked.get(op2).await(LOCK_TIMEOUT_MILLIS); Assert.assertEquals("Unexpected number of active segments.", 1, s.getSegmentWithOngoingOperationsCount()); waitOn.get(op2).release();
invoked.get(joiner.apply(operation, segment)).release(); Exceptions.handleInterrupted(() -> waitOn.get(joiner.apply(operation, segment)).await()); return null; waitOn.get(createSegment1Key).release(); AssertExtensions.assertThrows( "Concat was invoked while the at least one of the creates was running.", waitOn.get(createSegment2Key).release(); invoked.get(concatKey).await(TIMEOUT_MILLIS); waitOn.get(concatKey).release(); invoked.get(writeSegment1Key).await(LOCK_TIMEOUT_MILLIS); invoked.get(writeSegment2Key).await(LOCK_TIMEOUT_MILLIS); waitOn.get(writeSegment1Key).release(); waitOn.get(writeSegment2Key).release();
client.updates = updates; client.visableLength = 2; client.init.latch.release(); updates[0].latch.release(); updates[1].latch.release(); sync.fetchUpdates(); RevisionedImpl state1 = sync.getState(); AssertExtensions.assertBlocks(() -> { sync.fetchUpdates(); }, () -> updates[2].latch.release()); RevisionedImpl state2 = sync.getState(); assertEquals(new RevisionImpl(segment, 3, 3), state2.getRevision()); client.visableLength = 3; sync.getState(); updates[3].latch.release(); }); RevisionedImpl state3 = sync.getState();
Assert.assertFalse("startContainer() completed before previous container shut down (with failure).", startContainer2.isDone()); container1.stopSignal.release(); startContainer2.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS); TestContainer container2 = (TestContainer) registry.getContainer(containerId); Assert.assertFalse("startContainer() completed before previous container shut down (normally).", startContainer3.isDone()); container2.stopSignal.release(); startContainer3.get(TIMEOUT.toMillis(), TimeUnit.MILLISECONDS); TestContainer container3 = (TestContainer) registry.getContainer(containerId);
}, () -> latch.release());
/** * Tests the ability to detect a container failure and unregister the container in case the container fails on startup. */ @Test public void testContainerFailureOnStartup() throws Exception { final int containerId = 123; // We insert a ReusableLatch that will allow us to manually delay the TestContainer's shutdown/closing process // so that we have enough time to verify that calling getContainer() on a currently shutting down container will // throw the appropriate exception. ReusableLatch closeReleaseSignal = new ReusableLatch(); TestContainerFactory factory = new TestContainerFactory(new IntentionalException(), closeReleaseSignal); @Cleanup StreamSegmentContainerRegistry registry = new StreamSegmentContainerRegistry(factory, executorService()); AssertExtensions.assertThrows( "Unexpected exception thrown upon failed container startup.", registry.startContainer(containerId, TIMEOUT)::join, ex -> ex instanceof IntentionalException || (ex instanceof IllegalStateException && ex.getCause() instanceof IntentionalException)); AssertExtensions.assertThrows( "Container is registered even if it failed to start (and is currently shut down).", () -> registry.getContainer(containerId), ex -> ex instanceof ContainerNotFoundException); // Unblock container closing, which will, in turn, unblock its de-registration. closeReleaseSignal.release(); AssertExtensions.assertThrows( "Container is registered even if it failed to start (and has been unregistered).", () -> registry.getContainer(containerId), ex -> ex instanceof ContainerNotFoundException); }
listenerLatch.release(); }; readerGroup.getEndOfDataNotifier(executor).registerListener(l1);