protected void invokeAeronClient() { if (null != aeronClientInvoker) { aeronClientInvoker.invoke(); } } }
private void invokeAeronClient() { if (null != aeronClientInvoker) { aeronClientInvoker.invoke(); } }
protected final int invokeDriverConductor() { return null != driverAgentInvoker ? driverAgentInvoker.invoke() : 0; }
private void idle(final int workCount) { checkInterruptedStatus(); aeronClientInvoker.invoke(); idleStrategy.idle(workCount); }
private void idle() { checkInterruptedStatus(); aeronClientInvoker.invoke(); idleStrategy.idle(); }
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(); }
protected int preWork() { int workCount = 0; final long nowMs = epochClock.time(); if (cachedEpochClock.time() != nowMs) { cachedEpochClock.update(nowMs); markFile.updateActivityTimestamp(nowMs); workCount += aeronAgentInvoker.invoke(); } workCount += invokeDriverConductor(); workCount += runTasks(taskQueue); return workCount; }
@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 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(); }
@Test public void shouldHandleAgentTerminationExceptionThrownByAgent() throws Exception { final RuntimeException expectedException = new AgentTerminationException(); when(mockAgent.doWork()).thenThrow(expectedException); invoker.start(); invoker.invoke(); verify(mockAgent).doWork(); verify(mockErrorHandler).onError(expectedException); verify(mockAtomicCounter).increment(); verify(mockAgent).onClose(); assertTrue(invoker.isClosed()); reset(mockAgent); invoker.invoke(); verify(mockAgent, never()).doWork(); assertTrue(invoker.isClosed()); }
@Test public void shouldRemoveAgent() throws Exception { final Agent mockAgentOne = mock(Agent.class); final Agent mockAgentTwo = mock(Agent.class); final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME, mockAgentOne, mockAgentTwo); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.start(); verify(mockAgentOne, times(1)).onStart(); verify(mockAgentTwo, times(1)).onStart(); invoker.invoke(); verify(mockAgentOne, times(1)).doWork(); verify(mockAgentTwo, times(1)).doWork(); assertTrue(compositeAgent.tryRemove(mockAgentTwo)); assertFalse(compositeAgent.hasRemoveAgentCompleted()); invoker.invoke(); assertTrue(compositeAgent.hasRemoveAgentCompleted()); verify(mockAgentOne, times(2)).doWork(); verify(mockAgentTwo, times(1)).doWork(); verify(mockAgentOne, times(1)).onStart(); verify(mockAgentTwo, times(1)).onStart(); verify(mockAgentTwo, times(1)).onClose(); }
@Test public void shouldReportExceptionThrownOnStart() throws Exception { final RuntimeException expectedException = new RuntimeException(); Mockito.doThrow(expectedException).when(mockAgent).onStart(); invoker.start(); invoker.invoke(); verify(mockAgent, never()).doWork(); verify(mockErrorHandler).onError(expectedException); verify(mockAgent).onClose(); assertTrue(invoker.isStarted()); assertFalse(invoker.isRunning()); assertTrue(invoker.isClosed()); }
@Test public void shouldAddAgent() throws Exception { final Agent mockAgentOne = mock(Agent.class); final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME, mockAgentOne); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); assertThat(compositeAgent.roleName(), is(ROLE_NAME)); invoker.start(); verify(mockAgentOne, times(1)).onStart(); invoker.invoke(); verify(mockAgentOne, times(1)).onStart(); verify(mockAgentOne, times(1)).doWork(); final Agent mockAgentTwo = mock(Agent.class); assertTrue(compositeAgent.tryAdd(mockAgentTwo)); assertFalse(compositeAgent.hasAddAgentCompleted()); invoker.invoke(); assertTrue(compositeAgent.hasAddAgentCompleted()); verify(mockAgentOne, times(1)).onStart(); verify(mockAgentOne, times(2)).doWork(); verify(mockAgentTwo, times(1)).onStart(); verify(mockAgentTwo, times(1)).doWork(); }
aeronClientInvoker.invoke();
@Test public void shouldDetectConcurrentRemove() { final Agent mockAgentOne = mock(Agent.class); final Agent mockAgentTwo = mock(Agent.class); final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME, mockAgentOne, mockAgentTwo); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.start(); assertTrue(compositeAgent.tryAdd(mockAgentOne)); invoker.invoke(); assertTrue(compositeAgent.tryAdd(mockAgentTwo)); invoker.invoke(); assertTrue(compositeAgent.tryRemove(mockAgentOne)); assertFalse(compositeAgent.tryRemove(mockAgentTwo)); invoker.invoke(); assertTrue(compositeAgent.tryRemove(mockAgentTwo)); } }
private void snapshotState(final Publication publication, final long logPosition, final long leadershipTermId) { final ConsensusModuleSnapshotTaker snapshotTaker = new ConsensusModuleSnapshotTaker( publication, idleStrategy, aeronClientInvoker); snapshotTaker.markBegin(SNAPSHOT_TYPE_ID, logPosition, leadershipTermId, 0); for (final ClusterSession session : sessionByIdMap.values()) { if (session.state() == OPEN || session.state() == CLOSED) { snapshotTaker.snapshotSession(session); } } aeronClientInvoker.invoke(); timerService.snapshot(snapshotTaker); snapshotTaker.consensusModuleState(nextSessionId); snapshotTaker.clusterMembers(memberId, highMemberId, clusterMembers); snapshotTaker.markEnd(SNAPSHOT_TYPE_ID, logPosition, leadershipTermId, 0); }
@Test public void shouldDetectConcurrentAdd() { final Agent mockAgentOne = mock(Agent.class); final Agent mockAgentTwo = mock(Agent.class); final DynamicCompositeAgent compositeAgent = new DynamicCompositeAgent(ROLE_NAME, mockAgentOne, mockAgentTwo); final AgentInvoker invoker = new AgentInvoker(Throwable::printStackTrace, null, compositeAgent); invoker.start(); assertTrue(compositeAgent.tryAdd(mockAgentOne)); assertFalse(compositeAgent.tryAdd(mockAgentTwo)); invoker.invoke(); assertTrue(compositeAgent.tryAdd(mockAgentTwo)); }
aeronClientInvoker.invoke();