### Question:
Server extends SimpleChannelHandler implements ChannelPipelineFactory, Lifecycle,
        ChannelCloser { @Override public void messageReceived( ChannelHandlerContext ctx, MessageEvent event ) { try { ChannelBuffer message = (ChannelBuffer) event.getMessage(); handleRequest( message, event.getChannel() ); } catch ( Throwable e ) { msgLog.error( "Error handling request", e ); ChunkingChannelBuffer buffer = newChunkingBuffer( event.getChannel() ); buffer.clear( true ); writeFailureResponse( e, buffer ); ctx.getChannel().close(); tryToCloseChannel( ctx.getChannel() ); throw e; } } Server( T requestTarget, Configuration config, LogProvider logProvider, int frameLength,
                   ProtocolVersion protocolVersion, TxChecksumVerifier txVerifier, Clock clock, ByteCounterMonitor
            byteCounterMonitor, RequestMonitor requestMonitor ); @Override void init(); @Override void start(); @Override void stop(); @Override void shutdown(); InetSocketAddress getSocketAddress(); @Override ChannelPipeline getPipeline(); @Override void channelOpen( ChannelHandlerContext ctx, ChannelStateEvent e ); @Override void messageReceived( ChannelHandlerContext ctx, MessageEvent event ); @Override void writeComplete( ChannelHandlerContext ctx, WriteCompletionEvent e ); @Override void channelClosed( ChannelHandlerContext ctx, ChannelStateEvent e ); @Override void channelDisconnected( ChannelHandlerContext ctx, ChannelStateEvent e ); @Override void exceptionCaught( ChannelHandlerContext ctx, ExceptionEvent e ); @Override void tryToCloseChannel( Channel channel ); static final int DEFAULT_MAX_NUMBER_OF_CONCURRENT_TRANSACTIONS; }### Answer:
@Test public void shouldSendExceptionBackToClientOnInvalidChecksum() throws Throwable { Server<Object,Object> server = newServer( checksumVerifier ); RequestContext ctx = new RequestContext( 0, 1, 0, 2, 12 ); doThrow( new IllegalStateException( "123" ) ).when( checksumVerifier ).assertMatch( anyLong(), anyLong() ); try { server.messageReceived( channelCtx( channel ), message( reqType, ctx, channel, EMPTY_SERIALIZER ) ); fail( "Should have failed." ); } catch ( IllegalStateException e ) { } try { protocol.deserializeResponse( channel.asBlockingReadHandler(), ByteBuffer.allocate( (int) ByteUnit.kibiBytes( 1 ) ), 1, VOID_DESERIALIZER, mock( ResourceReleaser.class ), new VersionAwareLogEntryReader<>() ); fail( "Should have failed." ); } catch ( IllegalStateException e ) { assertThat( e.getMessage(), equalTo( "123" ) ); } }
@Test public void shouldNotSendExceptionBackToClientOnInvalidChecksumIfThereAreNoTransactions() throws Throwable { Server<Object,Object> server = newServer( checksumVerifier ); RequestContext ctx = new RequestContext( 0, 1, 0, TransactionIdStore.BASE_TX_ID, TransactionIdStore.BASE_TX_CHECKSUM ); server.messageReceived( channelCtx( channel ), message( reqType, ctx, channel, EMPTY_SERIALIZER ) ); verifyZeroInteractions( checksumVerifier ); }