Advertisement
Guest User

Untitled

a guest
Jan 30th, 2013
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.68 KB | None | 0 0
  1.  
  2. /**
  3.  * @author Sebastien Lorber <i>(lorber.sebastien@gmail.com)</i>
  4.  */
  5. @RunWith(SpringJUnit4ClassRunner.class)
  6. @Category(IntegrationTest.class)
  7. @ContextConfiguration(classes = Config.class)
  8. public class JobExecutionsImportTest {
  9.  
  10.   @Value("#{solrClientsHolder.jobExecutionsClient}")
  11.   protected JobExecutionsSolrClient client;
  12.  
  13.   @Autowired
  14.   protected JobDashboardSearchService jobsService;
  15.  
  16.   @Autowired
  17.   protected JdbcTemplate jdbcTemplate;
  18.  
  19.   private void cleanIndex() throws Exception {
  20.     client.getSolrServer().deleteByQuery("*:*");
  21.     client.getSolrServer().commit();
  22.   }
  23.  
  24.   /**
  25.    * La derniere date d'indexation est settée dans un properties
  26.    */
  27.   private void deleteLastIndexDate() {
  28.     new File("./target/test-classes/solr/JobExecutionsCore/conf/data-import.properties").delete();
  29.   }
  30.  
  31.   private void assertIndexedDocuments(long expectedCount) throws Exception {
  32.     SolrQuery query = new SolrQuery();
  33.     query.setQuery("*:*");
  34.     QueryResponse response;
  35.     response = client.getSolrServer().query(query);
  36.     long count = response.getResults().getNumFound();
  37.     assertThat(count).isEqualTo(expectedCount);
  38.   }
  39.  
  40.   @Test
  41.   public void test_full_import_when_never_indexed() throws Exception {
  42.     cleanIndex();
  43.     deleteLastIndexDate();
  44.     assertIndexedDocuments(0);
  45.     jobsService.fullImport();
  46.     assertIndexedDocuments(2);
  47.   }
  48.   @Test
  49.   @Ignore("Worked with Solr 1.4 but doesn't work anymore because of SOLR-4376")
  50.   public void test_delta_import_when_never_indexed() throws Exception {
  51.     cleanIndex();
  52.     deleteLastIndexDate();
  53.     assertIndexedDocuments(0);
  54.     jobsService.deltaImport();
  55.     assertIndexedDocuments(2);
  56.   }
  57.  
  58.  
  59.  
  60.   @Test
  61.   public void test_full_import_when_already_indexed_and_index_cleaned() throws Exception {
  62.     jobsService.fullImport();
  63.     cleanIndex();
  64.     assertIndexedDocuments(0);
  65.     jobsService.fullImport();
  66.     assertIndexedDocuments(2);
  67.   }
  68.   @Test
  69.   public void test_delta_import_when_already_indexed_and_index_cleaned() throws Exception {
  70.     jobsService.fullImport();
  71.     cleanIndex();
  72.     assertIndexedDocuments(0);
  73.     jobsService.deltaImport();
  74.     // normal because dataimport.properties last index date is after the db date of job executions in db
  75.     assertIndexedDocuments(0);
  76.   }
  77.  
  78.  
  79.  
  80.   @Test
  81.   public void test_full_import_when_already_indexed_and_index_not_cleaned() throws Exception {
  82.     jobsService.fullImport();
  83.     assertIndexedDocuments(2);
  84.     jobsService.fullImport();
  85.     assertIndexedDocuments(2);
  86.   }
  87.   @Test
  88.   public void test_delta_import_when_already_indexed_and_index_not_cleaned() throws Exception {
  89.     jobsService.fullImport();
  90.     assertIndexedDocuments(2);
  91.     jobsService.deltaImport();
  92.     assertIndexedDocuments(2);
  93.   }
  94.  
  95.   @Test
  96.   @DirtiesContext
  97.   public void test_full_import_does_not_keep_jobs_removed_from_db() throws Exception {
  98.     jobsService.fullImport();
  99.     assertIndexedDocuments(2);
  100.     jdbcTemplate.execute("DELETE FROM BATCH_STEP_EXECUTION_CONTEXT WHERE STEP_EXECUTION_ID=3");
  101.     jdbcTemplate.execute("DELETE FROM BATCH_STEP_EXECUTION WHERE STEP_EXECUTION_ID=3");
  102.     jdbcTemplate.execute("DELETE FROM BATCH_JOB_EXECUTION_CONTEXT WHERE JOB_EXECUTION_ID=2");
  103.     jdbcTemplate.execute("DELETE FROM BATCH_JOB_EXECUTION WHERE JOB_EXECUTION_ID=2");
  104.     jobsService.fullImport();
  105.     assertIndexedDocuments(1);
  106.   }
  107.  
  108.  
  109.  
  110.   @Configuration
  111.   @ImportResource("classpath:META-INF/spring/embedded-solr-server-test-context.xml")
  112.   public static class Config extends AbstractH2DataSourceConfig {
  113.     @Override
  114.     protected List<String> getSqlScripts() {
  115.       return ImmutableList.of("classpath:sql/ddl--springbatchexecutions-dataset.sql");
  116.     }
  117.   }
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement