@Test public void checkNoCallMadeForInvalidMessage() { RelatedItemIndexingMessage message = new RelatedItemIndexingMessage(configuration); message.setValidMessage(false); try { handler.onEvent(message,1,true); } catch (Exception e) { fail(); } assertEquals(0,repo.handlers.get(0).getNumberOfCalls()); }
@Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { try { if(request.isValidMessage()) { if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.info("indexing message not valid. ignoring. No related products"); return; } for(RelatedItem p : converter.convertFrom(request)) batchMessages.add(p); if(endOfBatch || batchMessages.size()>=batchSize) { log.debug("handing off request to indexing processor"); try { disruptors[nextDisruptor[COUNTER_POS]++ & mask].publishEvents(BatchCopyingRelatedItemIndexMessageTranslator.INSTANCE,batchMessages.toArray(new RelatedItem[batchMessages.size()])); } finally { batchMessages.clear(); } } } else { log.info("indexing message not valid, and will be ignored. Potentially contained {} related products", request.getRelatedItems().getNumberOfRelatedItems()); } } finally { request.setValidMessage(false); } }
RoundRobinRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { try { if(request.isValidMessage()) { if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.info("indexing message not valid. ignoring. No related products"); return; } for(RelatedItem p : converter.convertFrom(request)) batchMessages.add(p); if(endOfBatch || batchMessages.size()>=batchSize) { log.debug("handing off request to indexing processor"); try { disruptors[nextDisruptor[COUNTER_POS]++ & mask].publishEvents(BatchCopyingRelatedItemIndexMessageTranslator.INSTANCE,batchMessages.toArray(new RelatedItem[batchMessages.size()])); } finally { batchMessages.clear(); } } } else { log.info("indexing message not valid, and will be ignored. Potentially contained {} related products", request.getRelatedItems().getNumberOfRelatedItems()); } } finally { request.setValidMessage(false); } } }
RoundRobinRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { try { if(request.isValidMessage()) { if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.info("indexing message not valid. ignoring. No related products"); return; } for(RelatedItem p : converter.convertFrom(request)) batchMessages.add(p); if(endOfBatch || batchMessages.size()>=batchSize) { log.debug("handing off request to indexing processor"); try { disruptors[nextDisruptor[COUNTER_POS]++ & mask].publishEvents(BatchCopyingRelatedItemIndexMessageTranslator.INSTANCE,batchMessages.toArray(new RelatedItem[batchMessages.size()])); } finally { batchMessages.clear(); } } } else { log.info("indexing message not valid, and will be ignored. Potentially contained {} related products", request.getRelatedItems().getNumberOfRelatedItems()); } } finally { request.setValidMessage(false); } } RoundRobinRelatedItemIndexingMessageEventHandler(final Configuration configuration,
                                                            RelatedItemIndexingMessageConverter converter,
                                                            RelatedItemReferenceMessageFactory messageFactory,
                                                            RelatedItemReferenceEventHandlerFactory relatedItemIndexingEventHandlerFactory
    ); }
RoundRobinRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { try { if(request.isValidMessage()) { if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.info("indexing message not valid. ignoring. No related products"); return; } for(RelatedItem p : converter.convertFrom(request)) batchMessages.add(p); if(endOfBatch || batchMessages.size()>=batchSize) { log.debug("handing off request to indexing processor"); try { disruptors[nextDisruptor[COUNTER_POS]++ & mask].publishEvents(BatchCopyingRelatedItemIndexMessageTranslator.INSTANCE,batchMessages.toArray(new RelatedItem[batchMessages.size()])); } finally { batchMessages.clear(); } } } else { log.info("indexing message not valid, and will be ignored. Potentially contained {} related products", request.getRelatedItems().getNumberOfRelatedItems()); } } finally { request.setValidMessage(false); } } RoundRobinRelatedItemIndexingMessageEventHandler(final Configuration configuration,
                                                            RelatedItemIndexingMessageConverter converter,
                                                            RelatedItemReferenceMessageFactory messageFactory,
                                                            RelatedItemReferenceEventHandlerFactory relatedItemIndexingEventHandlerFactory
    ); @Override void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch); void shutdown(); }
RoundRobinRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { try { if(request.isValidMessage()) { if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.info("indexing message not valid. ignoring. No related products"); return; } for(RelatedItem p : converter.convertFrom(request)) batchMessages.add(p); if(endOfBatch || batchMessages.size()>=batchSize) { log.debug("handing off request to indexing processor"); try { disruptors[nextDisruptor[COUNTER_POS]++ & mask].publishEvents(BatchCopyingRelatedItemIndexMessageTranslator.INSTANCE,batchMessages.toArray(new RelatedItem[batchMessages.size()])); } finally { batchMessages.clear(); } } } else { log.info("indexing message not valid, and will be ignored. Potentially contained {} related products", request.getRelatedItems().getNumberOfRelatedItems()); } } finally { request.setValidMessage(false); } } RoundRobinRelatedItemIndexingMessageEventHandler(final Configuration configuration,
                                                            RelatedItemIndexingMessageConverter converter,
                                                            RelatedItemReferenceMessageFactory messageFactory,
                                                            RelatedItemReferenceEventHandlerFactory relatedItemIndexingEventHandlerFactory
    ); @Override void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch); void shutdown();  }