### Question:
DisruptorBasedRelatedItemIndexRequestProcessor implements RelatedItemIndexRequestProcessor { @Override public IndexRequestPublishingStatus processRequest(Configuration config, ByteBuffer data) { if(canIndex) { try { boolean published = ringBuffer.tryPublishEvent(requestConverter.createConverter(config,data)); return published ? IndexRequestPublishingStatus.PUBLISHED : IndexRequestPublishingStatus.NO_SPACE_AVALIABLE; } catch(InvalidIndexingRequestException e) { log.warn("Invalid json content, unable to process request: {}", e.getMessage()); if(log.isDebugEnabled()) { if(canOutputRequestData && data.hasArray()) { log.debug("content requested to be indexed: {}", Arrays.toString(data.array())); } } return IndexRequestPublishingStatus.FAILED; } } else { log.error("The indexing processor has been shutdown, and cannot accept requests."); return IndexRequestPublishingStatus.PUBLISHER_SHUTDOWN; } } DisruptorBasedRelatedItemIndexRequestProcessor(Configuration configuration,
                                                          IndexingRequestConverterFactory requestConverter,
                                                          EventFactory<RelatedItemIndexingMessage> indexingMessageFactory,
                                                          RelatedItemIndexingMessageEventHandler eventHandler
    ); @Override IndexRequestPublishingStatus processRequest(Configuration config, ByteBuffer data); @PreDestroy void shutdown();  }### Answer:
@Test public void testHandlerIsNotExecutedWithIndexingRequestWithTooManyProducts() { String json = "{" + " \"channel\" : 1.0," + " \"site\" : \"amazon\"," + " \"items\" : [ \"1\",\"2\",\"3\",\"4\",\"5\" ]"+ "}"; processor.processRequest(configuation, ByteBuffer.wrap(json.getBytes())); assertEquals(0,handler.getNumberOfCalls()); }
@Test public void testHandlerIsNotExecutedWithIndexingRequestWithNoProducts() { String json = "{" + " \"channel\" : 1.0," + " \"site\" : \"amazon\"," + " \"items\" : [ ]"+ "}"; processor.processRequest(configuation, ByteBuffer.wrap(json.getBytes())); assertEquals(0,handler.getNumberOfCalls()); }
@Test public void testHandlerIsCalled() { String json = "{" + " \"channel\" : 1.0," + " \"site\" : \"amazon\"," + " \"items\" : [ \"1\" ]"+ "}"; processor.processRequest(configuation, ByteBuffer.wrap(json.getBytes())); try { handler.getLatch().await(5000, TimeUnit.MILLISECONDS); } catch(Exception e) { fail("Failed waiting for disruptor to call the handler"); } assertEquals(1,handler.getNumberOfCalls()); }
@Test public void testHandlerIsNotExecutedWithEmptyRequestData() { processor.processRequest(configuation, ByteBuffer.wrap(new byte[0])); assertEquals(0,handler.getNumberOfCalls()); }