History Service does not leaves content after testing.

Added method in History Service for removing content.
cusax-fix
Damian Minkov 19 years ago
parent 1d2f145a00
commit 53f2aae096

@ -18,6 +18,7 @@
/**
* @author Alexander Pelov
* @author Damian Minkov
*/
public class HistoryServiceImpl implements HistoryService {
@ -223,7 +224,7 @@ private File createHistoryDirectories(HistoryID id)
/**
* Set the configuration service.
*
* @param configurationService
* @param configurationService ConfigurationService
*/
public void setConfigurationService(
ConfigurationService configurationService)
@ -245,7 +246,7 @@ public void setConfigurationService(
/**
* Remove a configuration service.
*
* @param configurationService
* @param configurationService ConfigurationService
*/
public void unsetConfigurationService(
ConfigurationService configurationService)
@ -263,7 +264,7 @@ public void unsetConfigurationService(
/**
* Set the file access service.
*
* @param fileAccessService
* @param fileAccessService FileAccessService
*/
public void setFileAccessService(FileAccessService fileAccessService)
{
@ -277,7 +278,7 @@ public void setFileAccessService(FileAccessService fileAccessService)
/**
* Remove the file access service.
*
* @param fileAccessService
* @param fileAccessService FileAccessService
*/
public void unsetFileAccessService(FileAccessService fileAccessService)
{
@ -300,4 +301,44 @@ protected boolean isCacheEnabled()
return cacheEnabled;
}
/**
* Permamently removes local stored History
*
* @param id HistoryID
* @throws IOException
*/
public void purgeLocallyStoredHistory(HistoryID id)
throws IOException
{
// get the history direcoty coresponding the given id
File dir = this.createHistoryDirectories(id);
log.trace("Removing history directory " + dir);
deleteDirAndContent(dir);
}
/**
* Deletes given directory and its content
*
* @param dir File
* @throws IOException
*/
private void deleteDirAndContent(File dir)
throws IOException
{
if(!dir.isDirectory())
return;
File[] content = dir.listFiles();
File tmp;
for (int i = 0; i < content.length; i++)
{
tmp = content[i];
if(tmp.isDirectory())
deleteDirAndContent(tmp);
else
tmp.delete();
}
dir.delete();
}
}

@ -74,4 +74,13 @@ public interface HistoryService {
*/
History createHistory(HistoryID id, HistoryRecordStructure recordStructure)
throws IllegalArgumentException, IOException;
/**
* Permamently removes local stored History
*
* @param id HistoryID
* @throws IOException
* Thrown if the history could not be removed due to a IO error.
*/
public void purgeLocallyStoredHistory(HistoryID id) throws IOException;
}

@ -39,7 +39,7 @@ public void start(BundleContext bundleContext)
Hashtable properties = new Hashtable();
properties.put("service.pid", getName());
addTestSuite(TestHistoryService.class);
addTest(TestHistoryService.suite());
bundleContext.registerService(getClass().getName(), this, properties);
logger.debug("Successfully registered " + getClass().getName());

@ -30,11 +30,22 @@ public class TestHistoryService extends TestCase {
private Random random = new Random();
public TestHistoryService(String name)
throws Exception
{
super(name);
}
public static Test suite()
{
TestSuite suite = new TestSuite();
suite.addTest(new TestHistoryService("testCreateDB"));
suite.addTest(new TestHistoryService("testWriteRecords"));
suite.addTest(new TestHistoryService("testReadRecords"));
suite.addTest(new TestHistoryService("testPurgeLocallyStoredHistory"));
return suite;
}
protected void setUp()
throws Exception
{
@ -110,6 +121,17 @@ public void testCreateDB()
{
fail("Could not create database with id " + id + " with error " + e);
}
try
{
// after creating, remove it - do not leave content
this.historyService.purgeLocallyStoredHistory(id);
}
catch (Exception ex)
{
fail("Cannot delete local history with id " + this.history.getID()
+ " : " + ex.getMessage());
}
}
public void testWriteRecords()
@ -155,4 +177,17 @@ public void testReadRecords()
}
}
}
public void testPurgeLocallyStoredHistory()
{
try
{
this.historyService.purgeLocallyStoredHistory(this.history.getID());
}
catch (Exception ex)
{
fail("Cannot delete local history with id " + this.history.getID()
+ " : " + ex.getMessage());
}
}
}

Loading…
Cancel
Save