package org.sf.mustru.test;
import java.io.File;
import java.util.Date;
import junit.framework.TestCase;
import org.sf.mustru.utils.Constants;
import org.sf.mustru.utils.IndexTools;
public class TestIndexTools extends TestCase
{
/**
* Test the repair/verification of the index with the database
*/
public void testRepair()
{
System.out.println("Started testing repair index");
int TIMELIMIT = 1000; //*-- time limit to perform the repair operation
String tmpFile = Constants.MUSTRU_HOME + File.separator + "tmp" + File.separator + "repair.txt";
IndexTools itools = new IndexTools(tmpFile);
itools.setRunRepair(true); itools.setRunSummary(false);
itools.start();
boolean done = false; long scanStart = new Date().getTime();
while (!done)
{ done = true;
long start = new Date().getTime();
try { itools.join(1000); } catch (InterruptedException e) { }
long end = new Date().getTime();
if ( (end - start) > 750 ) done = false;
long secs = end - scanStart; secs /= 1000;
if ( (secs > TIMELIMIT) && itools.isAlive() )
{ itools.setRunning(false); done = true; }
} //*-- end of while
System.out.println("Finished testing repair -- check file repair.txt");
}
/**
* Test the generation of the summary of the index
*/
public void testSummary()
{
System.out.println("Started testing index summary");
int TIMELIMIT = 1000; //*-- time limit to perform the summary operation
String tmpFile = Constants.MUSTRU_HOME + File.separator + "tmp" + File.separator + "summary.txt";
IndexTools itools = new IndexTools(tmpFile);
itools.setRunRepair(false); itools.setRunSummary(true);
itools.start();
boolean done = false; long scanStart = new Date().getTime();
while (!done)
{ done = true;
long start = new Date().getTime();
try { itools.join(1000); } catch (InterruptedException e) { }
long end = new Date().getTime();
if ( (end - start) > 750 ) done = false;
long secs = end - scanStart; secs /= 1000;
if ( (secs > TIMELIMIT) && itools.isAlive() )
{ itools.setRunning(false); done = true; }
} //*-- end of while
System.out.println("Finished testing index summary -- check file index.txt");
}
}