@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.getNumberOfCalls()); assertEquals(0,repo.getNumberOfProductsSentForStoring()); }
@Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { if(!request.isValidMessage()) { log.debug("Invalid indexing message. Ignoring message"); return; } if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.debug("Invalid indexing message, no related products. Ignoring message"); request.setValidMessage(false); return; } try { RelatedItem[] products = indexConverter.convertFrom(request); this.count[COUNTER_POS]-=products.length; for(RelatedItem p : products) { relatedItems.add(p); } if(endOfBatch || this.count[COUNTER_POS]<1) { try { log.debug("Sending indexing requests to the storage repository"); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", products, e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setValidMessage(false); } }
SingleRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { if(!request.isValidMessage()) { log.debug("Invalid indexing message. Ignoring message"); return; } if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.debug("Invalid indexing message, no related products. Ignoring message"); request.setValidMessage(false); return; } try { RelatedItem[] products = indexConverter.convertFrom(request); this.count[COUNTER_POS]-=products.length; for(RelatedItem p : products) { relatedItems.add(p); } if(endOfBatch || this.count[COUNTER_POS]<1) { try { log.debug("Sending indexing requests to the storage repository"); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", products, e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setValidMessage(false); } } }
SingleRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { if(!request.isValidMessage()) { log.debug("Invalid indexing message. Ignoring message"); return; } if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.debug("Invalid indexing message, no related products. Ignoring message"); request.setValidMessage(false); return; } try { RelatedItem[] products = indexConverter.convertFrom(request); this.count[COUNTER_POS]-=products.length; for(RelatedItem p : products) { relatedItems.add(p); } if(endOfBatch || this.count[COUNTER_POS]<1) { try { log.debug("Sending indexing requests to the storage repository"); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", products, e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setValidMessage(false); } } SingleRelatedItemIndexingMessageEventHandler(Configuration configuration,
                                                        RelatedItemIndexingMessageConverter converter,
                                                        RelatedItemStorageRepository repository,
                                                        RelatedItemStorageLocationMapper locationMapper); }
SingleRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { if(!request.isValidMessage()) { log.debug("Invalid indexing message. Ignoring message"); return; } if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.debug("Invalid indexing message, no related products. Ignoring message"); request.setValidMessage(false); return; } try { RelatedItem[] products = indexConverter.convertFrom(request); this.count[COUNTER_POS]-=products.length; for(RelatedItem p : products) { relatedItems.add(p); } if(endOfBatch || this.count[COUNTER_POS]<1) { try { log.debug("Sending indexing requests to the storage repository"); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", products, e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setValidMessage(false); } } SingleRelatedItemIndexingMessageEventHandler(Configuration configuration,
                                                        RelatedItemIndexingMessageConverter converter,
                                                        RelatedItemStorageRepository repository,
                                                        RelatedItemStorageLocationMapper locationMapper); @Override void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch); @Override void shutdown(); }
SingleRelatedItemIndexingMessageEventHandler implements RelatedItemIndexingMessageEventHandler { @Override public void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch) throws Exception { if(!request.isValidMessage()) { log.debug("Invalid indexing message. Ignoring message"); return; } if(request.getRelatedItems().getNumberOfRelatedItems()==0) { log.debug("Invalid indexing message, no related products. Ignoring message"); request.setValidMessage(false); return; } try { RelatedItem[] products = indexConverter.convertFrom(request); this.count[COUNTER_POS]-=products.length; for(RelatedItem p : products) { relatedItems.add(p); } if(endOfBatch || this.count[COUNTER_POS]<1) { try { log.debug("Sending indexing requests to the storage repository"); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", products, e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setValidMessage(false); } } SingleRelatedItemIndexingMessageEventHandler(Configuration configuration,
                                                        RelatedItemIndexingMessageConverter converter,
                                                        RelatedItemStorageRepository repository,
                                                        RelatedItemStorageLocationMapper locationMapper); @Override void onEvent(RelatedItemIndexingMessage request, long l, boolean endOfBatch); @Override void shutdown();  }