@Test public void testSendingManyItemsButBelowBatchSize() { try { for(int i=0;i<7;i++) { handler.onEvent(getMessage(),i,false); } handler.onEvent(getMessage(),8,true); } catch(Exception e) { fail(); } assertEquals(1,repo.getNumberOfCalls()); assertEquals(8,repo.getNumberOfProductsSentForStoring()); }
@Override public void onEvent(RelatedItemReference request, long l, boolean endOfBatch) throws Exception { try { relatedItems.add(request.getReference()); if(endOfBatch || --this.count[COUNTER_POS] == 0) { try { log.debug("Sending {} indexing requests to the storage repository",relatedItems.size()); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", relatedItems,e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setReference(null); } }
BatchingRelatedItemReferenceEventHandler implements RelatedItemReferenceEventHandler { @Override public void onEvent(RelatedItemReference request, long l, boolean endOfBatch) throws Exception { try { relatedItems.add(request.getReference()); if(endOfBatch || --this.count[COUNTER_POS] == 0) { try { log.debug("Sending {} indexing requests to the storage repository",relatedItems.size()); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", relatedItems,e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setReference(null); } } }
BatchingRelatedItemReferenceEventHandler implements RelatedItemReferenceEventHandler { @Override public void onEvent(RelatedItemReference request, long l, boolean endOfBatch) throws Exception { try { relatedItems.add(request.getReference()); if(endOfBatch || --this.count[COUNTER_POS] == 0) { try { log.debug("Sending {} indexing requests to the storage repository",relatedItems.size()); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", relatedItems,e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setReference(null); } } BatchingRelatedItemReferenceEventHandler(int batchSize,
                                                    RelatedItemStorageRepository repository,
                                                    RelatedItemStorageLocationMapper locationMapper); }
BatchingRelatedItemReferenceEventHandler implements RelatedItemReferenceEventHandler { @Override public void onEvent(RelatedItemReference request, long l, boolean endOfBatch) throws Exception { try { relatedItems.add(request.getReference()); if(endOfBatch || --this.count[COUNTER_POS] == 0) { try { log.debug("Sending {} indexing requests to the storage repository",relatedItems.size()); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", relatedItems,e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setReference(null); } } BatchingRelatedItemReferenceEventHandler(int batchSize,
                                                    RelatedItemStorageRepository repository,
                                                    RelatedItemStorageLocationMapper locationMapper); @Override void onEvent(RelatedItemReference request, long l, boolean endOfBatch); void shutdown(); }
BatchingRelatedItemReferenceEventHandler implements RelatedItemReferenceEventHandler { @Override public void onEvent(RelatedItemReference request, long l, boolean endOfBatch) throws Exception { try { relatedItems.add(request.getReference()); if(endOfBatch || --this.count[COUNTER_POS] == 0) { try { log.debug("Sending {} indexing requests to the storage repository",relatedItems.size()); try { storageRepository.store(locationMapper, relatedItems); } catch(Exception e) { log.warn("Exception calling storage repository for related products:{}", relatedItems,e); } } finally { this.count[COUNTER_POS] = batchSize; relatedItems.clear(); } } } finally { request.setReference(null); } } BatchingRelatedItemReferenceEventHandler(int batchSize,
                                                    RelatedItemStorageRepository repository,
                                                    RelatedItemStorageLocationMapper locationMapper); @Override void onEvent(RelatedItemReference request, long l, boolean endOfBatch); void shutdown();  }