Package org.hibernate.search.test.errorhandling

Examples of org.hibernate.search.test.errorhandling.MockErrorHandler


public class UsingIdentifierRollbackTest extends SearchTestBase {

  @Test
  public void testEntityDeletionWithoutIdentifier() {
    SearchFactoryImplementor searchFactoryImpl = getSearchFactoryImpl();
    MockErrorHandler errorHandler = (MockErrorHandler) searchFactoryImpl.getErrorHandler();

    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    s.persist( new Document( "Hibernate in Action", "Object/relational mapping with Hibernate", "blah blah blah" ) );
    s.getTransaction().commit();
    s.close();

    s = getSessionFactory().openSession();
    s.getTransaction().begin();
    Document entity = (Document) s.get( Document.class, Long.valueOf( 1 ) );
    Assert.assertNotNull( entity );
    s.delete( entity );
    s.getTransaction().commit();
    s.close();
    Assert.assertNull( "unexpected exception detected", errorHandler.getLastException() );
  }
View Full Code Here


  }

  @Test
  public void testRolledBackIdentifiersOnUnusualDocumentId() {
    SearchFactoryImplementor searchFactoryImpl = getSearchFactoryImpl();
    MockErrorHandler errorHandler = (MockErrorHandler) searchFactoryImpl.getErrorHandler();

    Session s = getSessionFactory().openSession();
    s.getTransaction().begin();
    s.persist( new PersonWithBrokenSocialSecurityNumber( Long.valueOf( 2 ), "This guy is unaffected by identifier rollback" ) );
    s.getTransaction().commit();
    s.close();

    s = getSessionFactory().openSession();
    s.getTransaction().begin();
    PersonWithBrokenSocialSecurityNumber entity = (PersonWithBrokenSocialSecurityNumber) s.get( PersonWithBrokenSocialSecurityNumber.class, Long.valueOf( 2 ) );
    Assert.assertNotNull( entity );
    s.delete( entity );
    s.getTransaction().commit();
    s.close();
    Assert.assertNull( "unexpected exception detected", errorHandler.getLastException() );
    List<LuceneWork> processedQueue = LeakingLuceneBackend.getLastProcessedQueue();
    Assert.assertEquals( 1, processedQueue.size() );
    LuceneWork luceneWork = processedQueue.get( 0 );
    Assert.assertEquals( "100", luceneWork.getIdInString() );
  }
View Full Code Here

      targetMethod = "loadList",
      action = "throw new NullPointerException(\"Byteman created NPE\")",
      name = "testMassIndexerErrorsReported")
  public void testMassIndexerErrorsReported() throws InterruptedException {
    SearchFactoryImplementor searchFactory = getSearchFactoryImpl();
    MockErrorHandler mockErrorHandler = getErrorHandler( searchFactory );

    FullTextSession fullTextSession = prepareSomeData( this );

    fullTextSession.createIndexer( Book.class ).startAndWait();

    getSession().close();
    String errorMessage = mockErrorHandler.getErrorMessage();
    Assert.assertEquals( "HSEARCH000212: An exception occurred while the MassIndexer was transforming identifiers to Lucene Documents", errorMessage );
    Throwable exception = mockErrorHandler.getLastException();
    Assert.assertTrue( exception instanceof NullPointerException );
    Assert.assertEquals( "Byteman created NPE", exception.getMessage() );
  }
View Full Code Here

  }

  static MockErrorHandler getErrorHandler(SearchFactoryImplementor searchFactory) {
    ErrorHandler errorHandler = searchFactory.getErrorHandler();
    Assert.assertTrue( errorHandler instanceof MockErrorHandler );
    MockErrorHandler mockErrorHandler = (MockErrorHandler) errorHandler;
    return mockErrorHandler;
  }
View Full Code Here

  @Test
  @RequiresDialect(comment = "H2 does not accept negative fetch sizes",
    strictMatching = true, value = org.hibernate.dialect.H2Dialect.class)
  public void testSetFetchSizeOnH2Fails() throws InterruptedException {
    SearchFactoryImplementor searchFactory = getSearchFactoryImpl();
    MockErrorHandler mockErrorHandler = MassIndexerErrorReportingTest.getErrorHandler( searchFactory );

    FullTextSession fullTextSession = MassIndexerErrorReportingTest.prepareSomeData( this );

    fullTextSession.createIndexer( Book.class ).idFetchSize( -1 ).startAndWait();

    getSession().close();
    String errorMessage = mockErrorHandler.getErrorMessage();
    Assert.assertEquals( "HSEARCH000211: An exception occurred while the MassIndexer was fetching the primary identifiers list", errorMessage );
    Throwable exception = mockErrorHandler.getLastException();
    Assert.assertTrue( exception instanceof org.hibernate.exception.GenericJDBCException );
  }
View Full Code Here

  @Test
  @RequiresDialect(comment = "MySQL definitely should accept Integer.MIN_VALUE",
    strictMatching = false, value = org.hibernate.dialect.MySQLDialect.class)
  public void testSetFetchSizeOnMySQL() throws InterruptedException {
    SearchFactoryImplementor searchFactory = getSearchFactoryImpl();
    MockErrorHandler mockErrorHandler = MassIndexerErrorReportingTest.getErrorHandler( searchFactory );

    FullTextSession fullTextSession = MassIndexerErrorReportingTest.prepareSomeData( this );

    fullTextSession.createIndexer( Book.class ).idFetchSize( Integer.MIN_VALUE ).startAndWait();

    getSession().close();
    String errorMessage = mockErrorHandler.getErrorMessage();
    Assert.assertEquals( null, errorMessage );
  }
View Full Code Here

    s.getTransaction().commit();
    s.close();

    ErrorHandler errorHandler = searchFactoryBySFI.getErrorHandler();
    Assert.assertTrue( errorHandler instanceof MockErrorHandler );
    MockErrorHandler mockErrorHandler = (MockErrorHandler)errorHandler;
    Assert.assertNull( "Errors detected in the backend!", mockErrorHandler.getLastException() );
  }
View Full Code Here

TOP

Related Classes of org.hibernate.search.test.errorhandling.MockErrorHandler

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.