@Test
  public void verifyIndexExclusivity() {
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    FullTextSession ftSession =
        builder
            .setProperty("hibernate.search.Book.indexmanager", "near-real-time")
            .setProperty(
                "hibernate.search." + Foo.class.getName() + ".indexmanager",
                "org.hibernate.search.testsupport.indexmanager.RamIndexManager")
            .addAnnotatedClass(BlogEntry.class)
            .addAnnotatedClass(Foo.class)
            .addAnnotatedClass(org.hibernate.search.test.query.Book.class)
            .addAnnotatedClass(org.hibernate.search.test.query.Author.class)
            .openFullTextSession();
    SearchFactoryImplementor searchFactory =
        (SearchFactoryImplementor) ftSession.getSearchFactory();
    ftSession.close();
    IndexManagerHolder allIndexesManager = searchFactory.getIndexManagerHolder();

    // checks for the default implementation
    checkIndexManagerType(
        allIndexesManager,
        "org.hibernate.search.test.configuration.BlogEntry",
        org.hibernate.search.indexes.impl.DirectoryBasedIndexManager.class);

    // Uses "NRT" taken from shortcut names
    checkIndexManagerType(
        allIndexesManager, "Book", org.hibernate.search.indexes.impl.NRTIndexManager.class);

    // Uses a fully qualified name to load an implementation
    checkIndexManagerType(allIndexesManager, Foo.class.getName(), RamIndexManager.class);

    builder.close();
  }
 public void testUseOfCustomLockingFactory() {
   assertNull(CustomLockFactoryFactory.optionValue);
   FullTextSessionBuilder builder = new FullTextSessionBuilder();
   builder
       .addAnnotatedClass(SnowStorm.class)
       .setProperty("hibernate.search.default.locking_option", "somethingHere")
       .setProperty(
           "hibernate.search.default.locking_strategy",
           "org.hibernate.search.test.directoryProvider.CustomLockFactoryFactory")
       .build();
   builder.close();
   assertEquals("somethingHere", CustomLockFactoryFactory.optionValue);
 }
  @Test
  public void testScenario() {

    FullTextSessionBuilder fullTextSessionBuilder = createSearchFactory();
    try {
      // check no operations are done:
      assertOperationsPerformed(0);
      assertLocationsLoaded(0);
      // create initial data
      initializeData(fullTextSessionBuilder);
      // this should have triggered 5 indexing operations, no entity loadings:
      assertOperationsPerformed(5);
      assertLocationsLoaded(0);
      FullTextSession fullTextSession = fullTextSessionBuilder.openFullTextSession();
      // now check index state:
      assertFoundLocations(fullTextSession, "floor", 5);
      assertFoundLocations(fullTextSession, "airport", 0);
      fullTextSession.clear();
      try {
        // we add a new Location to the group:
        addLocationToGroupCollection(fullTextSession);
        // NOTHING else should be loaded, there was no need to reindex unrelated Locations!
        assertLocationsLoaded(0);
        // of course the new Location should have been indexed:
        assertOperationsPerformed(1);
        fullTextSession.clear();
        // so now we have 6 Locations in the index, in LocationGroup "floor":
        assertFoundLocations(fullTextSession, "floor", 6);
        assertFoundLocations(fullTextSession, "airport", 0);
        // changing the locationGroup name to Airport:
        updateLocationGroupName(fullTextSession);
        fullTextSession.clear();
        // check index functionality:
        assertFoundLocations(fullTextSession, "floor", 0);
        assertFoundLocations(fullTextSession, "airport", 6);
        // six locations have been loaded for re-indexing:
        assertLocationsLoaded(6);
        // and six update operations have been sent to the backend:
        assertOperationsPerformed(6);
      } finally {
        fullTextSession.close();
      }
    } finally {
      fullTextSessionBuilder.close();
    }
  }
 public void testFailOnInexistentLockingFactory() {
   FullTextSessionBuilder builder = new FullTextSessionBuilder();
   try {
     builder
         .addAnnotatedClass(SnowStorm.class)
         .setProperty("hibernate.search.default.locking_option", "somethingHere")
         .setProperty(
             "hibernate.search.default.locking_strategy", "org.hibernate.NotExistingFactory")
         .build();
     builder.close();
     fail();
   } catch (org.hibernate.HibernateException e) {
     Throwable causeSearch = e.getCause();
     assertNotNull(causeSearch);
     assertTrue(causeSearch instanceof org.hibernate.search.SearchException);
     Throwable causeLockin = causeSearch.getCause();
     assertNotNull(causeLockin);
     assertEquals(
         "Unable to find locking_strategy implementation class: org.hibernate.NotExistingFactory",
         causeLockin.getMessage());
   }
 }