Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-644 Enable Byteman for unit tests, introduce a test for HSEAR…
…CH-625
- Loading branch information
1 parent
4d83d95
commit 685d232
Showing
4 changed files
with
144 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
...rc/test/java/org/hibernate/search/test/errorhandling/ConcurrentMergeErrorHandledTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* Hibernate, Relational Persistence for Idiomatic Java | ||
* | ||
* Copyright (c) 2010, Red Hat, Inc. and/or its affiliates or third-party contributors as | ||
* indicated by the @author tags or express copyright attribution | ||
* statements applied by the authors. All third-party contributions are | ||
* distributed under license by Red Hat, Inc. | ||
* | ||
* This copyrighted material is made available to anyone wishing to use, modify, | ||
* copy, or redistribute it subject to the terms and conditions of the GNU | ||
* Lesser General Public License, as published by the Free Software Foundation. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License | ||
* for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public License | ||
* along with this distribution; if not, write to: | ||
* Free Software Foundation, Inc. | ||
* 51 Franklin Street, Fifth Floor | ||
* Boston, MA 02110-1301 USA | ||
*/ | ||
package org.hibernate.search.test.errorhandling; | ||
|
||
import junit.framework.Assert; | ||
|
||
import org.hibernate.Session; | ||
import org.hibernate.Transaction; | ||
import org.hibernate.search.Environment; | ||
import org.hibernate.search.FullTextSession; | ||
import org.hibernate.search.Search; | ||
import org.hibernate.search.SearchFactory; | ||
import org.hibernate.search.engine.SearchFactoryImplementor; | ||
import org.hibernate.search.exception.ErrorHandler; | ||
import org.hibernate.search.test.Document; | ||
import org.hibernate.search.test.SearchTestCase; | ||
|
||
/** | ||
* This test uses Byteman. Byteman is activated at the invocation of the test | ||
* in this class, and it will have the IndexWriter fail during segments merge, | ||
* which means the commit on the index from our part. | ||
* The tricky issue is that the merger works in a separate thread and some | ||
* inner private classes are involved. | ||
* | ||
* The Byteman rules are defined in a resources file ConcurrentMergeErrorTest.bytemanrules | ||
* | ||
* The goal of the test is to make sure we can catch and report the errors | ||
* thrown by the merger via wathever is configured as Environment.ERROR_HANDLER. | ||
* | ||
* @see Environment#ERROR_HANDLER | ||
* @author Sanne Grinovero | ||
*/ | ||
public class ConcurrentMergeErrorHandledTest extends SearchTestCase { | ||
|
||
public void testLuceneMergerErrorHandling() { | ||
SearchFactoryImplementor searchFactory = getSearchFactoryImpl(); | ||
ErrorHandler errorHandler = searchFactory.getErrorHandler(); | ||
Assert.assertTrue( errorHandler instanceof MockErrorHandler ); | ||
MockErrorHandler mockErrorHandler = (MockErrorHandler)errorHandler; | ||
Session session = openSession(); | ||
Transaction transaction = session.beginTransaction(); | ||
session.persist( new Document( | ||
"Byteman Programmers Guider", "Version 1.5.0 Draft", "contains general guidelines to use Byteman" ) ); | ||
transaction.commit(); | ||
session.close(); | ||
String errorMessage = mockErrorHandler.getErrorMessage(); | ||
Assert.assertEquals( "Exception occurred java.io.IOException: Byteman said: your disk is full!\n", errorMessage ); | ||
} | ||
|
||
protected Class<?>[] getAnnotatedClasses() { | ||
return new Class[] { Document.class }; | ||
} | ||
|
||
protected SearchFactoryImplementor getSearchFactoryImpl() { | ||
FullTextSession s = Search.getFullTextSession( openSession() ); | ||
s.close(); | ||
SearchFactory searchFactory = s.getSearchFactory(); | ||
return (SearchFactoryImplementor) searchFactory; | ||
} | ||
|
||
protected void configure(org.hibernate.cfg.Configuration cfg) { | ||
super.configure( cfg ); | ||
cfg.setProperty( Environment.ERROR_HANDLER, MockErrorHandler.class.getName() ); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
...t/resources/org/hibernate/search/test/errorhandling/ConcurrentMergeErrorTest.bytemanrules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
######################################################################## | ||
# JBoss, Home of Professional Open Source | ||
# Copyright 2009-2010, Red Hat and individual contributors | ||
# by the @authors tag. See the copyright.txt in the distribution for a | ||
# full listing of individual contributors. | ||
# | ||
# This is free software; you can redistribute it and/or modify it | ||
# under the terms of the GNU Lesser General Public License as | ||
# published by the Free Software Foundation; either version 2.1 of | ||
# the License, or (at your option) any later version. | ||
# | ||
# This software is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
# Lesser General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public | ||
# License along with this software; if not, write to the Free | ||
# Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | ||
# 02110-1301 USA, or see the FSF site: http://www.fsf.org. | ||
# | ||
# @authors Sanne Grinovero | ||
# | ||
# ConcurrentMergeErrorTest | ||
# | ||
# Using Byteman we alter IndexWriter at runtime to throw an IOException during the merge operation, this might happen | ||
# in a secondary thread. | ||
# The flag "createIndexWriterIOException" is checked to make sure we only raise the exception when requested, | ||
# i.e. when we are running the ConcurrentMergeErrorHandledTest | ||
|
||
RULE org.apache.lucene.index.ConcurrentMergeScheduler throws IOException in service thread | ||
CLASS org.apache.lucene.index.IndexWriter | ||
METHOD checkpoint | ||
IF flagged("createIndexWriterIOException") | ||
DO | ||
clear("createIndexWriterIOException"); | ||
traceln( "This invocation of checkpoint() is going to throw an IOException\n" ); | ||
throw new IOException("Byteman said: your disk is full!"); | ||
ENDRULE | ||
|
||
RULE ConcurrentMergeErrorHandledTest | ||
CLASS org.hibernate.search.test.errorhandling.ConcurrentMergeErrorHandledTest | ||
METHOD testLuceneMergerErrorHandling | ||
IF TRUE | ||
DO | ||
traceln( "\n *** Byteman rules deployed! Next IndexWriter.checkpoint invocation will fail. ***\n" ); | ||
flag("createIndexWriterIOException") | ||
ENDRULE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters