protected void closeSession(final T session) { try { session.close(); } catch (final Exception ex) { errorHandler.onError(ex); } }
private void recordError(final Exception ex) { errors.increment(); errorHandler.onError(ex); } }
void handleError(final Throwable ex) { ctx.errorHandler().onError(ex); }
private void handleError(final Throwable throwable) { if (isRunning) { if (null != errorCounter) { errorCounter.increment(); } errorHandler.onError(throwable); } } }
private void handleError(final Throwable throwable) { if (null != errorCounter) { errorCounter.increment(); } errorHandler.onError(throwable); } }
public void close() { if (!free()) { errorHandler.onError(new AeronException("unable to delete " + logFile)); } }
private void assertExceptionNotReported() throws Exception { new Thread(runner).start(); Thread.sleep(100); runner.close(); verify(mockAgent, times(1)).onStart(); verify(mockAgent, atLeastOnce()).doWork(); verify(mockErrorHandler, never()).onError(any()); verify(mockAtomicCounter, never()).increment(); } }
@Test public void shouldErrorOnRemoveSubscriptionOnUnknownRegistrationId() { final long id1 = driverProxy.addSubscription(CHANNEL_4000, STREAM_ID_1); driverProxy.removeSubscription(id1 + 100); driverConductor.doWork(); final InOrder inOrder = inOrder(receiverProxy, mockClientProxy); inOrder.verify(receiverProxy).addSubscription(any(), anyInt()); inOrder.verify(mockClientProxy).onSubscriptionReady(eq(id1), anyInt()); inOrder.verify(mockClientProxy).onError(anyLong(), eq(UNKNOWN_SUBSCRIPTION), anyString()); inOrder.verifyNoMoreInteractions(); verify(mockErrorHandler).onError(any(Throwable.class)); }
@Test public void shouldErrorOnAddSubscriptionWithInvalidChannel() { driverProxy.addSubscription(INVALID_URI, STREAM_ID_1); driverConductor.doWork(); driverConductor.doWork(); verify(senderProxy, never()).newNetworkPublication(any()); verify(mockClientProxy).onError(anyLong(), eq(INVALID_CHANNEL), anyString()); verify(mockClientProxy, never()).operationSucceeded(anyLong()); verify(mockErrorCounter).increment(); verify(mockErrorHandler).onError(any(Throwable.class)); }
@Test public void shouldErrorOnRemovePublicationOnUnknownRegistrationId() { final long id = driverProxy.addPublication(CHANNEL_4000, STREAM_ID_1); driverProxy.removePublication(id + 1); driverConductor.doWork(); final InOrder inOrder = inOrder(senderProxy, mockClientProxy); inOrder.verify(senderProxy).newNetworkPublication(any()); inOrder.verify(mockClientProxy).onPublicationReady( anyLong(), eq(id), eq(STREAM_ID_1), anyInt(), any(), anyInt(), anyInt(), eq(false)); inOrder.verify(mockClientProxy).onError(anyLong(), eq(UNKNOWN_PUBLICATION), anyString()); inOrder.verifyNoMoreInteractions(); verify(mockErrorCounter).increment(); verify(mockErrorHandler).onError(any(Throwable.class)); }
@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 shouldErrorOnAddPublicationWithClashingSessionId() { driverProxy.addPublication(CHANNEL_4000, STREAM_ID_1); driverConductor.doWork(); final ArgumentCaptor<NetworkPublication> argumentCaptor = ArgumentCaptor.forClass(NetworkPublication.class); verify(senderProxy).newNetworkPublication(argumentCaptor.capture()); final String sessionIdParam = "|" + CommonContext.SESSION_ID_PARAM_NAME + "=" + argumentCaptor.getValue().sessionId(); final long correlationId = driverProxy.addExclusivePublication(CHANNEL_4000 + sessionIdParam, STREAM_ID_1); driverConductor.doWork(); verify(mockClientProxy).onError(eq(correlationId), eq(GENERIC_ERROR), anyString()); verify(mockErrorCounter).increment(); verify(mockErrorHandler).onError(any(Throwable.class)); }
@Test public void shouldTimeoutInterServiceIfTooLongBetweenDoWorkCalls() { suppressPrintError = true; conductor.doWork(); timeNs += (TimeUnit.MILLISECONDS.toNanos(INTER_SERVICE_TIMEOUT_MS) + 1); conductor.doWork(); verify(mockClientErrorHandler).onError(any(ConductorServiceTimeoutException.class)); assertTrue(conductor.isTerminating()); }
@Test public void shouldUseUniqueChannelEndpointOnAddSubscriptionWithNoDistinguishingCharacteristics() { final long id1 = driverProxy.addSubscription(CHANNEL_SUB_CONTROL_MODE_MANUAL, STREAM_ID_1); final long id2 = driverProxy.addSubscription(CHANNEL_SUB_CONTROL_MODE_MANUAL, STREAM_ID_1); driverConductor.doWork(); verify(receiverProxy, times(2)).registerReceiveChannelEndpoint(any()); driverProxy.removeSubscription(id1); driverProxy.removeSubscription(id2); driverConductor.doWork(); verify(receiverProxy, times(2)).closeReceiveChannelEndpoint(any()); verify(mockErrorHandler, never()).onError(any()); }
@Test public void shouldErrorOnAddPublicationWithNonEqualSessionId() { driverProxy.addPublication(CHANNEL_4000, STREAM_ID_1); driverConductor.doWork(); final ArgumentCaptor<NetworkPublication> argumentCaptor = ArgumentCaptor.forClass(NetworkPublication.class); verify(senderProxy).newNetworkPublication(argumentCaptor.capture()); final String sessionIdParam = "|" + CommonContext.SESSION_ID_PARAM_NAME + "=" + (argumentCaptor.getValue().sessionId() + 1); final long correlationId = driverProxy.addPublication(CHANNEL_4000 + sessionIdParam, STREAM_ID_1); driverConductor.doWork(); verify(mockClientProxy).onError(eq(correlationId), eq(GENERIC_ERROR), anyString()); verify(mockErrorCounter).increment(); verify(mockErrorHandler).onError(any(Throwable.class)); }
@Test public void shouldUseExistingChannelEndpointOnAddSubscriptionWithSameTagId() { final long id1 = driverProxy.addSubscription(CHANNEL_4000_TAG_ID_1, STREAM_ID_1); final long id2 = driverProxy.addSubscription(CHANNEL_TAG_ID_1, STREAM_ID_1); driverConductor.doWork(); verify(mockErrorHandler, never()).onError(any()); verify(receiverProxy).registerReceiveChannelEndpoint(any()); driverProxy.removeSubscription(id1); driverProxy.removeSubscription(id2); driverConductor.doWork(); verify(receiverProxy).closeReceiveChannelEndpoint(any()); }
@Test public void shouldUseExistingChannelEndpointOnAddPublicationWithSameTagIdDifferentStreamId() { final long id1 = driverProxy.addPublication(CHANNEL_4000_TAG_ID_1, STREAM_ID_1); final long id2 = driverProxy.addPublication(CHANNEL_TAG_ID_1, STREAM_ID_2); driverConductor.doWork(); verify(mockErrorHandler, never()).onError(any()); verify(senderProxy).registerSendChannelEndpoint(any()); verify(senderProxy, times(2)).newNetworkPublication(any()); driverProxy.removePublication(id1); driverProxy.removePublication(id2); doWorkUntil(() -> (PUBLICATION_LINGER_NS * 2 + CLIENT_LIVENESS_TIMEOUT_NS * 2) - nanoClock.nanoTime() <= 0); verify(senderProxy).closeSendChannelEndpoint(any()); }
@Test public void shouldUseExistingChannelEndpointOnAddPublciationWithSameTagIdAndSameStreamId() { final long id1 = driverProxy.addPublication(CHANNEL_4000_TAG_ID_1, STREAM_ID_1); final long id2 = driverProxy.addPublication(CHANNEL_TAG_ID_1, STREAM_ID_1); driverConductor.doWork(); verify(mockErrorHandler, never()).onError(any()); verify(senderProxy).registerSendChannelEndpoint(any()); verify(senderProxy).newNetworkPublication(any()); driverProxy.removePublication(id1); driverProxy.removePublication(id2); doWorkUntil(() -> (PUBLICATION_LINGER_NS * 2 + CLIENT_LIVENESS_TIMEOUT_NS * 2) - nanoClock.nanoTime() <= 0); verify(senderProxy).closeSendChannelEndpoint(any()); }
@Test public void shouldHandleAgentTerminationExceptionThrownByAgent() throws Exception { final RuntimeException expectedException = new AgentTerminationException(); when(mockAgent.doWork()).thenThrow(expectedException); runner.run(); verify(mockAgent).doWork(); verify(mockErrorHandler).onError(expectedException); verify(mockAtomicCounter).increment(); verify(mockAgent, times(1)).onClose(); assertTrue(runner.isClosed()); }
@Test public void shouldNotCloseAndErrorOnClientTimeoutForAnotherClientIdFromDriver() { whenReceiveBroadcastOnMessage( ControlProtocolEvents.ON_CLIENT_TIMEOUT, clientTimeoutBuffer, (buffer) -> { clientTimeout.clientId(conductor.driverListenerAdapter().clientId() + 1); return ClientTimeoutFlyweight.LENGTH; }); conductor.doWork(); verify(mockClientErrorHandler, never()).onError(any(TimeoutException.class)); assertFalse(conductor.isClosed()); }