private boolean isInvalid(final int termOffset, final int termLength) { final boolean isInvalid = (termOffset > (termLength - DataHeaderFlyweight.HEADER_LENGTH)) || (termOffset < 0); if (isInvalid) { invalidPackets.increment(); } return isInvalid; }
private void offer(final Runnable cmd) { while (!commandQueue.offer(cmd)) { failCount.increment(); Thread.yield(); } } }
protected void closeSession(final RecordingSession session) { while (!closeQueue.offer(session)) { errorCounter.increment(); Thread.yield(); } }
private void send(final ReplaySession session) { while (!sessionsQueue.offer(session)) { errorCounter.increment(); Thread.yield(); } } }
private void send(final RecordingSession session) { while (!sessionsQueue.offer(session)) { errorCounter.increment(); Thread.yield(); } } }
protected void closeSession(final ReplaySession session) { while (!closeQueue.offer(session)) { errorCounter.increment(); Thread.yield(); } }
private void recordError(final Exception ex) { errors.increment(); errorHandler.onError(ex); } }
private void handleError(final Throwable throwable) { if (null != errorCounter) { errorCounter.increment(); } errorHandler.onError(throwable); } }
private void handleError(final Throwable throwable) { if (isRunning) { if (null != errorCounter) { errorCounter.increment(); } errorHandler.onError(throwable); } } }
public void onError(final Throwable throwable) { errorCounter.increment(); errorHandler.onError(throwable); } }
protected void send(final ByteBuffer buffer, final int bytesToSend, final ImageConnection[] imageConnections) { final int bytesSent; if (null == multiRcvDestination) { bytesSent = sendTo(buffer, imageConnections[0].controlAddress); } else { bytesSent = multiRcvDestination.sendToAll(imageConnections, buffer, 0, bytesToSend); } if (bytesToSend != bytesSent) { shortSends.increment(); } }
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(); } }
private void assertExceptionNotReported() { invoker.start(); invoker.invoke(); invoker.close(); verify(mockErrorHandler, never()).onError(any()); verify(mockAtomicCounter, never()).increment(); } }
@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 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 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 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 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 shouldNotDoWorkOnClosedRunner() throws Exception { runner.close(); runner.run(); verify(mockAgent, never()).onStart(); verify(mockAgent, never()).doWork(); verify(mockErrorHandler, never()).onError(any()); verify(mockAtomicCounter, never()).increment(); verify(mockAgent, times(1)).onClose(); assertTrue(runner.isClosed()); }
@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()); }