Skip to content
Snippets Groups Projects
Commit 108f6ee4 authored by jakubs's avatar jakubs
Browse files

SP-359 SWE-16 recalculate lucene index with each test

SVN: 27386
parent dc5fee9a
No related branches found
No related tags found
No related merge requests found
Showing
with 100 additions and 47 deletions
......@@ -61,31 +61,30 @@ public final class IndexCreationUtil
private static HibernateSearchContext hibernateSearchContext;
private static BeanFactory beanFactory;
private static AbstractApplicationContext applicationContext;
private IndexCreationUtil()
{
// Can not be instantiated.
}
private final static BeanFactory getBeanFactory()
private final static AbstractApplicationContext getApplicationContext()
{
if (beanFactory == null)
if (applicationContext == null)
{
final AbstractApplicationContext applicationContext =
new ClassPathXmlApplicationContext(new String[]
{ "applicationContext.xml" }, true);
IndexCreationUtil.beanFactory = applicationContext;
final AbstractApplicationContext appC = new ClassPathXmlApplicationContext(new String[]
{ "applicationContext.xml" }, true);
IndexCreationUtil.applicationContext = appC;
}
return beanFactory;
return applicationContext;
}
/**
* Performs a full text index because the test database has been migrated.
*/
private final static void performFullTextIndex() throws Exception
private final static void createAndRunFullTextIndexer() throws Exception
{
final BeanFactory factory = getBeanFactory();
final BeanFactory factory = getApplicationContext();
final IFullTextIndexUpdater updater = createDummyUpdater();
final FullTextIndexerRunnable fullTextIndexer =
new FullTextIndexerRunnable(
......@@ -135,7 +134,43 @@ public final class IndexCreationUtil
// Main method
//
public static void main(final String[] args) throws Exception
public static void main(final String... args) throws Exception
{
Parameters parameters = parseArguments(args);
LogInitializer.init();
if (parameters.getDuplicatedDatabaseKind() != null)
{
dumpDatabase(parameters);
}
performIsolatedIndexing(parameters);
releaseResources();
}
private static void dumpDatabase(Parameters parameters)
{
String databaseKind = parameters.getDatabaseKind();
String duplicatedDatabaseKind = parameters.getDuplicatedDatabaseKind();
String indexFolder = parameters.getIndexFolder();
String databaseName = DATABASE_NAME_PREFIX + databaseKind;
String duplicatedDatabaseName = DATABASE_NAME_PREFIX + duplicatedDatabaseKind;
boolean ok = duplicateDatabase(duplicatedDatabaseName, databaseName);
if (ok == false)
{
throw new IllegalStateException("Execution failed");
}
File dumpFile = parameters.getDumpFile();
operationLog.info("Dump '" + duplicatedDatabaseName + "' into '" + dumpFile + "'.");
DumpPreparator.createDatabaseDump(duplicatedDatabaseName, dumpFile);
databaseKind = duplicatedDatabaseKind;
FileUtilities.deleteRecursively(new File(indexFolder));
}
private static Parameters parseArguments(final String... args)
{
Parameters parameters = null;
try
......@@ -144,46 +179,49 @@ public final class IndexCreationUtil
} catch (IllegalArgumentException e)
{
System.out.println(Parameters.getUsage());
System.exit(1);
return; // for Eclipse
throw e;
}
LogInitializer.init();
return parameters;
}
private static void releaseResources()
{
applicationContext.stop();
applicationContext.close();
applicationContext.destroy();
}
/**
* Performs indexing and restored the environment to original state
*/
private static void performIsolatedIndexing(Parameters parameters) throws Exception
{
String databaseKind = parameters.getDatabaseKind();
String duplicatedDatabaseKind = parameters.getDuplicatedDatabaseKind();
String indexFolder = parameters.getIndexFolder();
if (duplicatedDatabaseKind != null)
{
String databaseName = DATABASE_NAME_PREFIX + databaseKind;
String duplicatedDatabaseName = DATABASE_NAME_PREFIX + duplicatedDatabaseKind;
boolean ok = duplicateDatabase(duplicatedDatabaseName, databaseName);
if (ok == false)
{
System.exit(1);
}
File dumpFile = parameters.getDumpFile();
operationLog.info("Dump '" + duplicatedDatabaseName + "' into '" + dumpFile + "'.");
DumpPreparator.createDatabaseDump(duplicatedDatabaseName, dumpFile);
databaseKind = duplicatedDatabaseKind;
FileUtilities.deleteRecursively(new File(indexFolder));
}
System.setProperty("database.kind", databaseKind);
// Deactivate the indexing in the application context loaded by Spring.
System.setProperty("hibernate.search.index-mode", "NO_INDEX");
System.setProperty("hibernate.search.index-base", indexFolder);
System.setProperty("database.create-from-scratch", "false");
performAndTimeIndexing(databaseKind, indexFolder);
}
private static void performAndTimeIndexing(String databaseKind, String indexFolder)
throws Exception
{
hibernateSearchContext = createHibernateSearchContext(indexFolder);
hibernateSearchContext.afterPropertiesSet();
operationLog.info("=========== Start indexing ===========");
StopWatch stopWatch = new StopWatch();
stopWatch.start();
performFullTextIndex();
createAndRunFullTextIndexer();
stopWatch.stop();
operationLog.info("Index of database '" + DATABASE_NAME_PREFIX + databaseKind
+ "' successfully built in '" + indexFolder + "' after "
+ ((stopWatch.getTime() + 30000) / 60000) + " minutes.");
Thread.sleep(10000);
System.exit(0);
}
static boolean duplicateDatabase(String destinationDatabase, String sourceDatabase)
......
......@@ -22,9 +22,11 @@ import java.io.IOException;
import org.apache.commons.io.FileUtils;
import ch.systemsx.cisd.base.exceptions.CheckedExceptionTunnel;
import ch.systemsx.cisd.base.exceptions.IOExceptionUnchecked;
import ch.systemsx.cisd.common.filesystem.FileUtilities;
import ch.systemsx.cisd.common.logging.LogInitializer;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.IndexCreationUtil;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.FullTextIndexerRunnable;
import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IndexMode;
......@@ -33,7 +35,7 @@ import ch.systemsx.cisd.openbis.generic.server.dataaccess.db.search.IndexMode;
*/
public class TestInitializer
{
public static final String LUCENE_INDEX_TEMPLATE_PATH = "../openbis/sourceTest/lucene/indices";
public static final String LUCENE_INDEX_TEMPLATE_PATH = "../openbis/targets/tempLuceneIndices";
public static final String LUCENE_INDEX_PATH = "../openbis/targets/lucene/indices";
......@@ -61,9 +63,33 @@ public class TestInitializer
init(IndexMode.NO_INDEX, SCRIPT_FOLDER_EMPTY_DB);
}
private static boolean firstTry = true;
private static void init(IndexMode hibernateIndexMode, String scriptFolder)
{
LogInitializer.init();
if (firstTry)
{
try
{
File temporaryFile = new File(LUCENE_INDEX_TEMPLATE_PATH);
FileUtilities.deleteRecursively(temporaryFile);
temporaryFile.mkdirs();
IndexCreationUtil.main("test", temporaryFile.getAbsolutePath());
} catch (Exception ex)
{
CheckedExceptionTunnel.wrapIfNecessary(ex);
}
firstTry = false;
}
// make sure the search index is up-to-date
// and in the right place when we run tests
restoreSearchIndex();
System.setProperty("database.create-from-scratch", "true");
System.setProperty("database.kind", "test");
System.setProperty("script-folder", scriptFolder);
......@@ -71,18 +97,15 @@ public class TestInitializer
System.setProperty("hibernate.search.index-base", LUCENE_INDEX_PATH);
System.setProperty("hibernate.search.worker.execution", "sync");
// make sure the search index is up-to-date
// and in the right place when we run tests
restoreSearchIndex();
}
// create a fresh copy of the Lucene index
public static void restoreSearchIndex()
{
File targetPath = new File(TestInitializer.LUCENE_INDEX_PATH);
File targetPath = new File(TestInitializer.LUCENE_INDEX_PATH).getAbsoluteFile();
FileUtilities.deleteRecursively(targetPath);
targetPath.mkdirs();
File srcPath = new File(LUCENE_INDEX_TEMPLATE_PATH);
File srcPath = new File(LUCENE_INDEX_TEMPLATE_PATH).getAbsoluteFile();
try
{
FileUtils.copyDirectory(srcPath, targetPath, new FileFilter()
......
File deleted
File deleted
￿༜ၟ桩扥牮慴敟捬慳猑ɩ搑੩摥湴楦楥爐ѣ潤攁ᅭ潤楦楣慴楯湟摡瑥ć灥牭彩搐൥硰敲業敮琠楤đ牥杩獴牡瑩潮彤慴攁ॴ祰攠捯摥ć瑹灥搁๲敧楳瑲慴潲搁፲敧楳瑲慴潲⁕獥爠䥤Ė牥杩獴牡瑯爠䙩牳琠乡浥ĕ牥杩獴牡瑯爠䱡獴⁎慭攁ᅲ敧楳瑲慴潲⁅浡楬ဌ捯湴慩湥爠楤đ獴潲慧敟捯湦楲浥搁ᕦ楬攠景牭慴⁴祰攠捯摥ē晩汥潲浡琠瑹灥搁ၰ牯灥牴礠䍏䵍䕎吁୰牯灥牴礠楤ĉ獡浰汥搁ተ牯灥牴礠䉁䍔䕒䥕䴁ᕰ牯灥牴礠䅎奟䵁呅剉䅌ď灲潰敲瑹⁇䕎䑅刁᭰牯灥牴礠癯捡扵污特⁴敲洠楤Ď浥瑡灲潪散琠楤Ė浥瑡灲潪散琠楤敮瑩晩敲
identifiercodemodification_dateperm_id experiment idregistration_date type codetype idregistrator idregistrator User Idregistrator First Nameregistrator Last Nameregistrator Email container idstorage_confirmedfile format type codefile format type idproperty COMMENT property id sample idproperty BACTERIUMproperty ANY_MATERIALproperty GENDERproperty vocabulary term idmetaproject idmetaproject identifier
\ No newline at end of file
 153!#%')+-/7  9;+9  '  / / %')+-/1537 9; !#7777   +)+-/1!#%'    # # # # 9; 9;
\ No newline at end of file
NRM||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||yyyyyyyyyyyyy||||||||||||||||||x|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||y|||||||||||||||||||||||||||||y|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||y|||||||||||||||||||||||||||||y||
\ No newline at end of file
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
File deleted
￿༢ၟ桩扥牮慴敟捬慳猑ɩ搑੩摥湴楦楥爐ѣ潤攁ᅭ潤楦楣慴楯湟摡瑥ć灥牭彩搁ᅲ敧楳瑲慴楯湟摡瑥ĉ瑹灥⁣潤攁ݴ祰攠楤Ď牥杩獴牡瑯爠楤ē牥杩獴牡瑯爠啳敲⁉搁ᙲ敧楳瑲慴潲⁆楲獴⁎慭攁ᕲ敧楳瑲慴潲⁌慳琠乡浥đ牥杩獴牡瑯爠䕭慩氐⡡瑴慣桭敮琠❥硡浰汥䕸灥物浥湴献瑸琧慭攁⥡瑴慣桭敮琠❥硡浰汥䕸灥物浥湴献瑸琧⁴楴汥į慴瑡捨浥湴‧數慭灬故硰敲業敮瑳⹴硴✠摥獣物灴楯渁ൡ瑴慣桭敮琠楤Ċ灲潪散琠楤Č灲潪散琠捯摥ď灲潪散琠灥牭彩搁ၰ牯橥捴⁳灡捥搁ተ牯橥捴⁳灡捥⁣潤攁ᑰ牯灥牴礠䑅千剉偔䥏丁୰牯灥牴礠楤ď灲潰敲瑹⁇䕎䑅刁᭰牯灥牴礠癯捡扵污特⁴敲洠楤Đ灲潰敲瑹⁃位䵅乔Ď浥瑡灲潪散琠楤Ė浥瑡灲潪散琠楤敮瑩晩敲Ė灲潰敲瑹⁐啒䍈䅓䕟䑁呅Ġ慴瑡捨浥湴‧捥汬偬慴敳⹴硴✠湡浥ġ慴瑡捨浥湴‧捥汬偬慴敳⹴硴✠瑩瑬攁❡瑴慣桭敮琠❣敬汐污瑥献瑸琧⁤敳捲楰瑩潮
identifiercodemodification_dateperm_idregistration_date type codetype idregistrator idregistrator User Idregistrator First Nameregistrator Last Nameregistrator Email(attachment 'exampleExperiments.txt' name)attachment 'exampleExperiments.txt' title/attachment 'exampleExperiments.txt' description attachment id
project id project codeproject perm_idproject space idproject space codeproperty DESCRIPTION property idproperty GENDERproperty vocabulary term idproperty COMMENTmetaproject idmetaproject identifierproperty PURCHASE_DATE attachment 'cellPlates.txt' name!attachment 'cellPlates.txt' title'attachment 'cellPlates.txt' description
\ No newline at end of file
File deleted
NRM||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||x|||||||||||||||||||||||||x||||||||y||||||||||||||||||||||||||||||||||||||||||||||||||x||x|xx|xvy|yy|yx||||||||||||||||||||||||||||||||||||||y|y|||||||y|y||||||||x|||||||||||||||||||||||||||||
\ No newline at end of file
File deleted
File deleted
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment