/** * Clean up and release all Aeron client resources and shutdown conductor thread if not using * {@link Context#useConductorAgentInvoker(boolean)}. * <p> * This will close all currently open {@link Publication}s, {@link Subscription}s, and {@link Counter}s created * from this client. */ public void close() { if (IS_CLOSED_UPDATER.compareAndSet(this, 0, 1)) { if (null != conductorRunner) { conductorRunner.close(); } else { conductorInvoker.close(); } } }
/** * Mark the invoker as started and call the {@link Agent#onStart()} method. * <p> * Startup logic will only be performed once. */ public void start() { try { if (!isStarted) { isStarted = true; agent.onStart(); isRunning = true; } } catch (final Throwable throwable) { errorHandler.onError(throwable); close(); } }
private void assertExceptionNotReported() { invoker.start(); invoker.invoke(); invoker.close(); verify(mockErrorHandler, never()).onError(any()); verify(mockAtomicCounter, never()).increment(); } }
@Test public void shouldNotDoWorkOnClosedRunnerButCallOnClose() throws Exception { invoker.close(); invoker.invoke(); verify(mockAgent, never()).onStart(); verify(mockAgent, never()).doWork(); verify(mockErrorHandler, never()).onError(any()); verify(mockAtomicCounter, never()).increment(); verify(mockAgent).onClose(); }
@Test public void shouldFollowLifecycle() throws Exception { invoker.start(); invoker.start(); verify(mockAgent, times(1)).onStart(); verifyNoMoreInteractions(mockAgent); invoker.invoke(); invoker.invoke(); verify(mockAgent, times(2)).doWork(); verifyNoMoreInteractions(mockAgent); invoker.close(); invoker.close(); verify(mockAgent, times(1)).onClose(); verifyNoMoreInteractions(mockAgent); }
@Test(expected = IllegalStateException.class) public void shouldNotAllowRemoveAfterClose() { final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.close(); compositeAgent.tryRemove(mock(Agent.class)); }
@Test(expected = IllegalStateException.class) public void shouldNotAllowAddAfterClose() { final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.close(); compositeAgent.tryAdd(mock(Agent.class)); }
@Test public void shouldReportExceptionThrownByAgent() throws Exception { final RuntimeException expectedException = new RuntimeException(); when(mockAgent.doWork()).thenThrow(expectedException); invoker.start(); invoker.invoke(); verify(mockAgent).doWork(); verify(mockErrorHandler).onError(expectedException); verify(mockAtomicCounter).increment(); verify(mockAgent, never()).onClose(); reset(mockAgent); invoker.invoke(); verify(mockAgent).doWork(); reset(mockAgent); invoker.close(); verify(mockAgent, never()).doWork(); verify(mockAgent).onClose(); }
/** * Clean up and release all Aeron client resources and shutdown conductor thread if not using * {@link Context#useConductorAgentInvoker(boolean)}. * <p> * This will close all currently open {@link Publication}s, {@link Subscription}s, and {@link Counter}s created * from this client. */ public void close() { if (IS_CLOSED_UPDATER.compareAndSet(this, 0, 1)) { if (null != conductorRunner) { conductorRunner.close(); } else { conductorInvoker.close(); } } }
/** * Clean up and release all Aeron client resources and shutdown conductor thread if not using * {@link Context#useConductorAgentInvoker(boolean)}. * <p> * This will close all currently open {@link Publication}s, {@link Subscription}s, and {@link Counter}s created * from this client. */ public void close() { if (IS_CLOSED_UPDATER.compareAndSet(this, 0, 1)) { if (null != conductorRunner) { conductorRunner.close(); } else { conductorInvoker.close(); } } }
/** * Mark the invoker as started and call the {@link Agent#onStart()} method. * <p> * Startup logic will only be performed once. */ public void start() { try { if (!isStarted) { isStarted = true; agent.onStart(); isRunning = true; } } catch (final Throwable throwable) { errorHandler.onError(throwable); close(); } }