static MockErrorHandler getErrorHandler(SearchIntegrator integrator) { ErrorHandler errorHandler = integrator.getErrorHandler(); Assert.assertTrue( errorHandler instanceof MockErrorHandler ); MockErrorHandler mockErrorHandler = (MockErrorHandler) errorHandler; return mockErrorHandler; }
private MockErrorHandler getErrorHandlerAndAssertCorrectTypeIsUsed() { SearchIntegrator integrator = getExtendedSearchIntegrator(); ErrorHandler errorHandler = integrator.getErrorHandler(); Assert.assertEquals( MockErrorHandler.class, errorHandler.getClass() ); return (MockErrorHandler) errorHandler; }
private MockErrorHandler getErrorHandlerAndAssertCorrectTypeIsUsed() { SearchIntegrator integrator = getExtendedSearchIntegrator(); ErrorHandler errorHandler = integrator.getErrorHandler(); Assert.assertTrue( errorHandler instanceof MockErrorHandler ); return (MockErrorHandler)errorHandler; }
private MockErrorHandler getErrorHandlerAndAssertCorrectTypeIsUsed() { SearchIntegrator integrator = getExtendedSearchIntegrator(); ErrorHandler errorHandler = integrator.getErrorHandler(); Assert.assertTrue( errorHandler instanceof MockErrorHandler ); return (MockErrorHandler) errorHandler; }
@Test public void testEntityDeletionWithoutIdentifier() { SearchIntegrator integrator = getExtendedSearchIntegrator(); MockErrorHandler errorHandler = (MockErrorHandler) integrator.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 = 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() ); }
@Test public void testRolledBackIdentifiersOnUnusualDocumentId() { SearchIntegrator integrator = getExtendedSearchIntegrator(); MockErrorHandler errorHandler = (MockErrorHandler) integrator.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 = 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 = LeakingLocalBackend.getLastProcessedQueue(); Assert.assertEquals( 1, processedQueue.size() ); LuceneWork luceneWork = processedQueue.get( 0 ); Assert.assertEquals( "100", luceneWork.getIdInString() ); }
@Test public void canPassErrorHandlerInstanceToConfiguration() { // given ErrorHandler errorHandler = new MyErrorHandler(); // when SearchConfiguration cfg = getSearchConfiguration( errorHandler ); SearchIntegrator searchIntegrator = integratorResource.create( cfg ); // then assertSame( errorHandler, searchIntegrator.getErrorHandler() ); }
public static StaticTestingErrorHandler extract(Cache cache) { SearchManager searchManager = Search.getSearchManager(cache); SearchIntegrator searchFactory = searchManager.unwrap(SearchIntegrator.class); ErrorHandler errorHandler = searchFactory.getErrorHandler(); assertNotNull(errorHandler); if (errorHandler instanceof WrappingErrorHandler) { errorHandler = ((WrappingErrorHandler) errorHandler).unwrap(); } assertTrue(errorHandler instanceof StaticTestingErrorHandler); return (StaticTestingErrorHandler) errorHandler; }
@Test public void testReindexingWithCompositeIds() throws InterruptedException { try ( FullTextSession fullTextSession = ftsBuilder.openFullTextSession() ) { storeTestData( fullTextSession ); } try ( FullTextSession fullTextSession = ftsBuilder.openFullTextSession() ) { fullTextSession.createIndexer().startAndWait(); } SearchFactory searchFactory = ftsBuilder.getSearchFactory(); SearchIntegrator searchIntegrator = searchFactory.unwrap( SearchIntegrator.class ); CountingErrorHandler errorHandler = (CountingErrorHandler) searchIntegrator.getErrorHandler(); assertEquals( 0, errorHandler.getTotalCount() ); }
private void expectOnConfiguration(boolean async, boolean exclusiveIndexing, String... expectedStack) { SearchConfigurationForTest cfg = new SearchConfigurationForTest(); cfg.addProperty( "hibernate.search.default.worker.execution", async ? "async" : "sync" ); cfg.addProperty( "hibernate.search.default.exclusive_index_use", exclusiveIndexing ? "true" : "false" ); cfg.addProperty( "hibernate.search.error_handler", CountingErrorHandler.class.getName() ); cfg.addClass( Quote.class ); searchIntegrator = integratorResource.create( cfg ); final CountingErrorHandler errorHandler = (CountingErrorHandler) searchIntegrator.getErrorHandler(); writeData( NUMBER_ENTITIES ); //Check no errors happened in the asynchronous threads assertEquals( 0, errorHandler.getTotalCount() ); searchIntegrator.close(); //Now the SearchIntegrator was closed, let's unwind the recorder events and compare them with expectations: for ( int i = 0; i < expectedStack.length; i++ ) { //Check the events have been fired in the expected order assertEquals( expectedStack[i], byteman.consumeNextRecordedEvent() ); } //And no more events than those expected exist assertTrue( byteman.isEventStackEmpty() ); }
@Override public void initialize(String indexName, Properties properties, Similarity similarity, WorkerBuildContext buildContext) { ServiceManager serviceManager = buildContext.getServiceManager(); ComponentRegistryService componentRegistryService = serviceManager.requestService(ComponentRegistryService.class); ComponentRegistry componentRegistry = componentRegistryService.getComponentRegistry(); transactionHelper = new TransactionHelper(componentRegistry.getComponent(TransactionManager.class)); shardId = this.extractShardName(indexName); Transaction tx = transactionHelper.suspendTxIfExists(); try { super.initialize(indexName, properties, similarity, buildContext); } finally { transactionHelper.resume(tx); } RpcManager rpcManager = componentRegistry.getComponent(RpcManager.class); cache = componentRegistry.getComponent(Cache.class); keyTransformationHandler = componentRegistry.getComponent(QueryInterceptor.class).getKeyTransformationHandler(); shardAllocatorManager = componentRegistry.getComponent(ShardAllocatorManager.class); searchIntegrator = componentRegistry.getComponent(SearchIntegrator.class); isAsync = !BackendFactory.isConfiguredAsSync(properties); localShardAddress = new ShardAddress(shardId, rpcManager != null ? rpcManager.getAddress() : LocalModeAddress.INSTANCE); ExecutorService asyncExecutor = componentRegistry.getComponent(ExecutorService.class, ASYNC_OPERATIONS_EXECUTOR); luceneWorkDispatcher = new LuceneWorkDispatcher(this, rpcManager); workPartitioner = new WorkPartitioner(this, shardAllocatorManager); AffinityErrorHandler errorHandler = (AffinityErrorHandler) searchIntegrator.getErrorHandler(); errorHandler.initialize(rpcManager, asyncExecutor); cache.addListener(this); }
@Override public void initialize(String indexName, Properties properties, Similarity similarity, WorkerBuildContext buildContext) { ServiceManager serviceManager = buildContext.getServiceManager(); ComponentRegistryService componentRegistryService = serviceManager.requestService(ComponentRegistryService.class); ComponentRegistry componentRegistry = componentRegistryService.getComponentRegistry(); transactionHelper = new TransactionHelper(componentRegistry.getComponent(TransactionManager.class)); shardId = this.extractShardName(indexName); Transaction tx = transactionHelper.suspendTxIfExists(); try { super.initialize(indexName, properties, similarity, buildContext); } finally { transactionHelper.resume(tx); } RpcManager rpcManager = componentRegistry.getComponent(RpcManager.class); cache = componentRegistry.getComponent(Cache.class); keyTransformationHandler = componentRegistry.getComponent(QueryInterceptor.class).getKeyTransformationHandler(); shardAllocatorManager = componentRegistry.getComponent(ShardAllocatorManager.class); searchIntegrator = componentRegistry.getComponent(SearchIntegrator.class); isAsync = !BackendFactory.isConfiguredAsSync(properties); localShardAddress = new ShardAddress(shardId, rpcManager != null ? rpcManager.getAddress() : LocalModeAddress.INSTANCE); ExecutorService asyncExecutor = componentRegistry.getComponent(ExecutorService.class, ASYNC_OPERATIONS_EXECUTOR); luceneWorkDispatcher = new LuceneWorkDispatcher(this, rpcManager); workPartitioner = new WorkPartitioner(this, shardAllocatorManager); AffinityErrorHandler errorHandler = (AffinityErrorHandler) searchIntegrator.getErrorHandler(); errorHandler.initialize(rpcManager, asyncExecutor); cache.addListener(this); }