Package org.hibernate.search.test.util

Examples of org.hibernate.search.test.util.FullTextSessionBuilder


  // the property is not called "id"
  @Test
  @TestForIssue(jiraKey = "HSEARCH-901")
  public void testIdentifierNaming() throws InterruptedException {
    //disable automatic indexing, to test manual index creation.
    FullTextSessionBuilder ftsb = new FullTextSessionBuilder()
        .setProperty( Environment.ANALYZER_CLASS, StandardAnalyzer.class.getName() )
        .addAnnotatedClass( Dvd.class )
        .addAnnotatedClass( Nation.class )
        .addAnnotatedClass( Book.class )
        .addAnnotatedClass( WeirdlyIdentifiedEntity.class )
        .setProperty( Environment.INDEXING_STRATEGY, "manual" )
        .build();
    {
      //creating the test data in database only:
      FullTextSession fullTextSession = ftsb.openFullTextSession();
      Transaction transaction = fullTextSession.beginTransaction();
      Nation us = new Nation( "United States of America", "US" );
      fullTextSession.persist( us );
      Dvd dvda = new Dvd();
      dvda.setTitle( "Star Trek (episode 96367)" );
      dvda.setFirstPublishedIn( us );
      fullTextSession.save( dvda );
      Dvd dvdb = new Dvd();
      dvdb.setTitle( "The Trek" );
      dvdb.setFirstPublishedIn( us );
      fullTextSession.save( dvdb );
      WeirdlyIdentifiedEntity entity = new WeirdlyIdentifiedEntity();
      entity.setId( "not an identifier" );
      fullTextSession.save( entity );
      transaction.commit();
      fullTextSession.close();
    }
    {
      //verify index is still empty:
      assertEquals( 0, countResults( new Term( "title", "trek" ), ftsb, Dvd.class ) );
      assertEquals( 0, countResults( new Term( "id", "not" ), ftsb, WeirdlyIdentifiedEntity.class ) );
    }
    {
      FullTextSession fullTextSession = ftsb.openFullTextSession();
      fullTextSession.createIndexer( Dvd.class )
          .startAndWait();
      fullTextSession.close();
    }
    {
      //verify index is now containing both DVDs:
      assertEquals( 2, countResults( new Term( "title", "trek" ), ftsb, Dvd.class ) );
    }
    {
      FullTextSession fullTextSession = ftsb.openFullTextSession();
      fullTextSession.createIndexer( WeirdlyIdentifiedEntity.class )
          .startAndWait();
      fullTextSession.close();
    }
    {
      //verify index is now containing the weirdly identified entity:
      assertEquals( 1, countResults( new Term( "id", "identifier" ), ftsb, WeirdlyIdentifiedEntity.class ) );
    }
    ftsb.close();
  }
View Full Code Here


  }

  @Test
  public void testExtendedIdentifierNaming() throws InterruptedException {
    //disable automatic indexing, to test manual index creation.
    FullTextSessionBuilder ftsb = new FullTextSessionBuilder()
        .setProperty( Environment.ANALYZER_CLASS, StandardAnalyzer.class.getName() )
        .addAnnotatedClass( ExtendedIssueEntity.class )
        .addAnnotatedClass( IssueEntity.class )
        .setProperty( Environment.INDEXING_STRATEGY, "manual" )
        .build();
    {
      //creating the test data in database only:
      FullTextSession fullTextSession = ftsb.openFullTextSession();
      Transaction transaction = fullTextSession.beginTransaction();
      ExtendedIssueEntity issue = new ExtendedIssueEntity();
      issue.jiraCode = "HSEARCH-977";
      issue.jiraDescription = "MassIndexer freezes when there is an indexed 'id' filed, which is not document's id";
      issue.id = 1l;
      fullTextSession.persist( issue );
      transaction.commit();
      fullTextSession.close();
    }
    {
      //verify index is still empty:
      assertEquals( 0, countResults( new Term( "jiraDescription", "freezes" ), ftsb, ExtendedIssueEntity.class ) );
      assertEquals( 0, countResults( new Term( "jiraCode", "HSEARCH" ), ftsb, ExtendedIssueEntity.class ) );
    }
    {
      FullTextSession fullTextSession = ftsb.openFullTextSession();
      fullTextSession.createIndexer( ExtendedIssueEntity.class )
          .startAndWait();
      fullTextSession.close();
    }
    {
      //verify index via term readers:
      assertEquals( 1, countResults( new Term( "jiraDescription", "freezes" ), ftsb, ExtendedIssueEntity.class ) );
      assertEquals( 1, countResults( new Term( "id", "1" ), ftsb, ExtendedIssueEntity.class ) );
    }
    ftsb.close();
  }
View Full Code Here

      fullTextSession.close();
    }
    // verify nodeb is able to find it:
    verifyNodeSeesUpdatedIndex( nodeb );
    // now start a new node, it will join the cluster and receive the current index state:
    FullTextSessionBuilder nodeC = createClusterNode( entityTypes, true );
    assertEquals( 3, clusterSize( nodea, SimpleEmail.class ) );
    try {
      // verify the new node is able to perform the same searches:
      verifyNodeSeesUpdatedIndex( nodeC );
    }
    finally {
      nodeC.close();
    }
    assertEquals( 2, clusterSize( nodea, SimpleEmail.class ) );
    verifyNodeSeesUpdatedIndex( nodea );
    verifyNodeSeesUpdatedIndex( nodeb );
  }
View Full Code Here

    else {
      if ( slaves.size() == 0 ) {
        growCluster = true;
      }
      else {
        FullTextSessionBuilder sessionBuilder = slaves.remove( 0 );
        sessionBuilder.close();
      }
    }
    waitForAllJoinsCompleted();
  }
View Full Code Here

   * Creates a new SessionFactory using a shared H2 connection pool, and running
   * an Infinispan Directory storing the index in memory and write-through filesystem.
   * @param createSchema set to false to not drop an existing schema
   */
  private void startNode(boolean createSchema) {
    node = new FullTextSessionBuilder()
      .setProperty( "hibernate.search.default.directory_provider", "infinispan" )
      .setProperty( DefaultCacheManagerService.INFINISPAN_CONFIGURATION_RESOURCENAME, "filesystem-loading-infinispan.xml" )
      // avoid killing the schema when you still have to run the second node:
      .setProperty( Environment.HBM2DDL_AUTO, createSchema ? "create" : "validate" )
      // share the same in-memory database connection pool
View Full Code Here

   * @param setInfinispanIndexManager  set to true to enable the indexmanager setting to 'infinispan'
   * @return
   */
  public static FullTextSessionBuilder createClusterNode(Set<Class<?>> entityTypes, boolean exclusiveIndexUse,
      boolean setInfinispanDirectory, boolean setInfinispanIndexManager) {
    FullTextSessionBuilder node = new FullTextSessionBuilder();
      if ( setInfinispanDirectory ) {
        node.setProperty( "hibernate.search.default.directory_provider", "infinispan" );
      }
      if ( setInfinispanIndexManager ) {
        node.setProperty( "hibernate.search.default.indexmanager", "infinispan" );
      }
      // fragment on every 13 bytes: don't use this on a real case!
      // only done to make sure we generate lots of small fragments.
      node.setProperty( "hibernate.search.default.indexwriter.chunk_size", "13" );
      //Override the JGroups configuration to use the testing loopback stack
      node.setProperty( DefaultCacheManagerService.INFINISPAN_TRANSPORT_OVERRIDE_RESOURCENAME, "testing-flush-loopback.xml" );
      // this schema is shared across nodes, so don't drop it on shutdown:
      node.setProperty( Environment.HBM2DDL_AUTO, "create" );
      // if we should allow aggressive index locking:
      node.setProperty( "hibernate.search.default." + org.hibernate.search.cfg.Environment.EXCLUSIVE_INDEX_USE,
          String.valueOf( exclusiveIndexUse ) );
      // share the same in-memory database connection pool
      node.setProperty(
          Environment.CONNECTION_PROVIDER,
          org.hibernate.search.infinispan.ClusterSharedConnectionProvider.class.getName()
          );
    for ( Class<?> entityType : entityTypes ) {
      node.addAnnotatedClass( entityType );
    }
    return node.build();
  }
View Full Code Here

    Mapping.enableFieldCache = new FieldCacheType[]{ FieldCacheType.CLASS, FieldCacheType.ID };
    wrapper( false );
  }

  public void wrapper(boolean usingMixedIds, String... expectedLoadedFields) {
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    if ( usingMixedIds ) {
      builder
        .addAnnotatedClass( Address.class )
        .addAnnotatedClass( Country.class );
    }
    builder.addAnnotatedClass( Item.class )
      .addAnnotatedClass( ProductCatalog.class )
      .setProperty( "hibernate.search.default." + Environment.READER_STRATEGY, FieldSelectorLeakingReaderProvider.class.getName() )
      .setProperty( Environment.MODEL_MAPPING, Mapping.class.getName() )
      .build();
    try {
      storeDemoData( builder );
      performtest( builder, expectedLoadedFields );
    }
    catch (IOException e) {
      Assert.fail( "unexpected exception " + e );
    }
    finally {
      builder.close();
    }
  }
View Full Code Here

*/
public class IndexManagerOverrideTest {

  @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();
  }
View Full Code Here

  private FullTextSessionBuilder builder;
  private FullTextSession sess;

  @Before
  public void setUp() {
    builder = new FullTextSessionBuilder();
    builder
      .addAnnotatedClass( AlternateBook.class )
      .addAnnotatedClass( Employee.class )
      .setProperty( "hibernate.default_batch_fetch_size", "10" )
      .build();
View Full Code Here

*/
public class ExclusiveIndexTest {

  @Test
  public void verifyIndexExclusivity() {
    FullTextSessionBuilder builder = new FullTextSessionBuilder();
    FullTextSession ftSession = builder
      .setProperty(
          "hibernate.search.org.hibernate.search.test.configuration.BlogEntry.exclusive_index_use",
          "true"
      )
      .setProperty( "hibernate.search.Book.exclusive_index_use", "false" )
      .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();
    //explicitly enabled:
    assertExclusiveIsEnabled( allIndexesManager, "org.hibernate.search.test.configuration.BlogEntry", true );
    //explicitly disabled (this entity defined a short index name):
    assertExclusiveIsEnabled( allIndexesManager, "Book", false );
    //using default:
    assertExclusiveIsEnabled( allIndexesManager, Foo.class.getName(), true );
    builder.close();
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.test.util.FullTextSessionBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.