@Override public void run() { try { deleteIndex(); buildIndex(); } catch (IOException e) { logger.error(ERROR_MESSAGE, e); } }
/** * Runs reindexing on demand and writes back a response. * @param response used for writing back a response */ @RequestMapping(value = "/reindex", method = RequestMethod.GET) public void reindex(final HttpServletResponse response) { indexTaskScheduler.runReindexOnDemand(); PrintWriter writer; try { writer = response.getWriter(); writer.write("Reindexing!"); writer.flush(); } catch (IOException e) { logger.info("error occurred when accessing /reindex", e); } } }
private void deleteIndex() throws IOException { logger.info(DELETING_DOCUMENTS_MESSAGE); indexWriter.deleteAll(); doCommit(); indexStatus.setReady(false); logger.info(DELETED_DOCUMENTS_MESSAGE); }
/** * This method reads in property file of wilma-message-search. * @throws Exception {@link PropertyLoader}, {@link ApplicationContext} can throw different exceptions. */ @PostConstruct void afterPropertiesSet() throws Exception { propertyLoader.loadProperties(); loadProperties(); startUpMessageGenerator.logStartUpMessage(); jmsConnectionConfigurer.setBrokerUrl(); indexTaskScheduler = applicationContext.getBean("indexTaskScheduler", IndexTaskScheduler.class); indexTaskScheduler.runReindexOnDemand(); indexTaskScheduler.startReindexScheduling(); }
@Test public void testRunReindexOnDemand() { //GIVEN Date now = new Date(); given(dateFactory.createNewDate()).willReturn(now); //WHEN underTest.runReindexOnDemand(); //THEN verify(taskScheduler).schedule(luceneReindexerTask, now); }
@Test public void testStartReindexScheduling() { //GIVEN given(configurationAccess.getProperties()).willReturn(properties); given(properties.getReindexTimer()).willReturn(CRON_EXPRESSION); given(cronTriggerFactory.create(CRON_EXPRESSION)).willReturn(cronTrigger); //WHEN underTest.startReindexScheduling(); //THEN verify(taskScheduler).schedule(luceneReindexerTask, cronTrigger); }
@Test public final void testAfterPropertiesScheduleReindexing() throws Exception { //GIVEN in setup //WHEN underTest.afterPropertiesSet(); //THEN verify(indexTaskScheduler).startReindexScheduling(); }
@Test public void testReindexShouldRunReindex() throws IOException { //GIVEN //WHEN underTest.reindex(response); //THEN verify(indexTaskScheduler).runReindexOnDemand(); }
private void buildIndex() throws IOException { logger.info(STARTING_INDEXING); String[] folders = messageFoldersUtil.getFolders(configurationAccess.getProperties().getMessageDirectories()); for (String folder : folders) { luceneEngine.buildIndex(folder); } doCommit(); indexStatus.setReady(true); logger.info(INDEXING_FINISHED); }
@Test public final void testAfterPropertiesShouldBuildTheIndex() throws Exception { //GIVEN in setup //WHEN underTest.afterPropertiesSet(); //THEN verify(indexTaskScheduler).runReindexOnDemand(); }
@Test public void testReindexShouldRunReindexThenExceptionRaisedInGetWriter() throws IOException { //GIVEN IOException exception = new IOException(); doThrow(exception).when(response).getWriter(); //WHEN underTest.reindex(response); //THEN verify(indexTaskScheduler).runReindexOnDemand(); verify(logger).info("error occurred when accessing /reindex", exception); }