Hi again,
I have a strange behaviour in my unit tests. Before each test I create some entities and save them to the session so the index will be updated / created. After each test I clear the database, purge all entities from index and try to delete the index directory. This works for each single test but when I try to execute all tests I get the error that some index files cannot be deleted after a test and before the next test the created entities will not be committed to the index (which I found out by debugging, the data is not in the index) so the test executes with an error. I don't know, why this could happen. I changed to manual indexing strategy and index each entity in the PostUpdate and PostPersist Events. These events will be triggered correctly but the data does not appear in the index.
Here my code for the setUp and tearDown of the tests:
Code:
@Before
public void setUp() {
// init GenericApplicationContext
...
// createSomeTestData
ProjectEntity pe = new ProjectEntityImpl();
manager.createProject(pe);
}
public void tearDown() {
// delete data
// close GenericApplicationContext
// delete index files and directories
deleteFiles(indexDir)
}
Code for saving an entity:
Code:
@Transactional(readOnly=false, propagation=Propagation.REQUIRED)
public void createProject(ProjectEntity pe) {
Session session = getSession();
session.save(pe);
}
The code for my entity:
Code:
public class ProjectEntityImpl ... {
@Field(name = "projectName", index = Index.UN_TOKENIZED)
private String name;
// more properties ...
@PostUpdate
@PostPersist
public void updateIndex() {
SearchManagerHolder.getSearchManager().updateIndex(this);
}
@PostRemove
public void deleteIndex() {
SearchManagerHolder.getSearchManager().deleteIndex(this);
}
...
}
The search manager:
Code:
public void updateIndex(Object entity) {
if (entity instanceof ProjectEntity) {
FullTextSession fullTextSession = Search.getFullTextSession(getSession());
fullTextSession.index(entity);
}
}
public void deleteIndex(Object entity) {
if ( instanceof ProjectEntity) {
FullTextSession fullTextSession = Search.getFullTextSession(getSession());
fullTextSession.purge(ProjectEntityImpl.class, ((ProjectEntity)entity).getID());
}
}
So after each test I got the error that some index files cannot be deleted. I don't know why. The next tests failed because some data which is created in the setUp method does not appear in the index... Maybe you can give me a hint?
Regards, jacquipre