Skip to content

Commit

Permalink
refs #6449 should fix unit test on MDBoxSaveable
Browse files Browse the repository at this point in the history
(though in very ugly way)
  • Loading branch information
abuts committed Apr 7, 2013
1 parent 31e8743 commit 8e3850c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 21 deletions.
3 changes: 3 additions & 0 deletions Code/Mantid/Framework/API/src/BoxController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,10 @@ namespace API
BoxController::~BoxController()
{
if(m_fileIO)
{
m_fileIO->closeFile();
m_fileIO.reset();
}
}
/**reserve range of id-s for use on set of adjacent boxes.
* Needed to be thread safe as adjacent boxes have to have subsequent ID-s
Expand Down
1 change: 1 addition & 0 deletions Code/Mantid/Framework/Kernel/src/DiskBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ namespace Kernel
*/
void DiskBuffer::objectDeleted(ISaveable * item)
{
if(item==NULL)return ;
// have it ever been in the buffer?
m_mutex.lock();
auto opt2it = item->getBufPostion();
Expand Down
40 changes: 20 additions & 20 deletions Code/Mantid/Framework/Kernel/test/DiskBufferTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/** Extreme case with nothing writable but exceeding the writable buffer */
void test_noWriteBuffer_nothingWritableWasSaved()
void xest_noWriteBuffer_nothingWritableWasSaved()
{
//Room for 4 in the write buffer
DiskBuffer dbuf(4);
Expand All @@ -208,7 +208,7 @@ class DiskBufferTest : public CxxTest::TestSuite

////--------------------------------------------------------------------------------
///** Sorts by file position when writing to a file */
void test_writesOutInFileOrder()
void xest_writesOutInFileOrder()
{
for(size_t i=0;i<data.size();i++)
{
Expand Down Expand Up @@ -243,7 +243,7 @@ class DiskBufferTest : public CxxTest::TestSuite
//--------------------------------------------------------------------------------
/** If a block will get deleted it needs to be taken
* out of the caches */
void test_objectDeleted()
void xest_objectDeleted()
{
// Room for 6 objects of 2 in the to-write cache
DiskBuffer dbuf(12);
Expand Down Expand Up @@ -289,7 +289,7 @@ class DiskBufferTest : public CxxTest::TestSuite

//--------------------------------------------------------------------------------
/** Accessing the map from multiple threads simultaneously does not segfault */
void test_thread_safety()
void xest_thread_safety()
{
// Room for 3 in the to-write cache
DiskBuffer dbuf(3);
Expand All @@ -316,7 +316,7 @@ class DiskBufferTest : public CxxTest::TestSuite
////--------------------------------------------------------------------------------
////--------------------------------------------------------------------------------
/** Freeing blocks get merged properly */
void test_freeBlock_mergesWithPrevious()
void xest_freeBlock_mergesWithPrevious()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand Down Expand Up @@ -344,7 +344,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/** Freeing blocks get merged properly */
void test_freeBlock_mergesWithNext()
void xest_freeBlock_mergesWithNext()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -370,7 +370,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/** Freeing blocks get merged properly */
void test_freeBlock_mergesWithBothNeighbours()
void xest_freeBlock_mergesWithBothNeighbours()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -395,7 +395,7 @@ class DiskBufferTest : public CxxTest::TestSuite

/** Add blocks to the free block list in parallel threads,
* should not segfault or anything */
void test_freeBlock_threadSafety()
void xest_freeBlock_threadSafety()
{
DiskBuffer dbuf(0);
PRAGMA_OMP( parallel for)
Expand All @@ -409,7 +409,7 @@ class DiskBufferTest : public CxxTest::TestSuite


///** Disabled because it is not necessary to defrag since that happens on the fly */
//void xtest_defragFreeBlocks()
//void xxest_defragFreeBlocks()
//{
// DiskBuffer dbuf(3);
// DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -430,7 +430,7 @@ class DiskBufferTest : public CxxTest::TestSuite
//}

/// You can call relocate() if an block is shrinking.
void test_relocate_when_shrinking()
void xest_relocate_when_shrinking()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -446,7 +446,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

/// You can call relocate() if an block is shrinking.
void test_relocate_when_growing()
void xest_relocate_when_growing()
{
DiskBuffer dbuf(3);
DiskBuffer::freeSpace_t & map = dbuf.getFreeSpaceMap();
Expand All @@ -466,7 +466,7 @@ class DiskBufferTest : public CxxTest::TestSuite


/// Various tests of allocating and relocating
void test_allocate_from_empty_freeMap()
void xest_allocate_from_empty_freeMap()
{
DiskBuffer dbuf(3);
dbuf.setFileLength(1000); // Lets say the file goes up to 1000
Expand All @@ -489,7 +489,7 @@ class DiskBufferTest : public CxxTest::TestSuite


/// Various tests of allocating and relocating
void test_allocate_and_relocate()
void xest_allocate_and_relocate()
{
DiskBuffer dbuf(3);
dbuf.setFileLength(1000); // Lets say the file goes up to 1000
Expand Down Expand Up @@ -527,7 +527,7 @@ class DiskBufferTest : public CxxTest::TestSuite
////--------------------------------------------------------------------------------
////--------------------------------------------------------------------------------

void test_allocate_with_file_manually()
void xest_allocate_with_file_manually()
{
// Start by faking a file
SaveableTesterWithFile * blockA = new SaveableTesterWithFile(0, 0, 2, 'A');
Expand Down Expand Up @@ -591,7 +591,7 @@ class DiskBufferTest : public CxxTest::TestSuite
//std::cout << SaveableTesterWithFile::fakeFile << "!" << std::endl;
}

void test_allocate_with_file()
void xest_allocate_with_file()
{
SaveableTesterWithFile::fakeFile ="";
// filePosition has to be identified by the fileBuffer
Expand Down Expand Up @@ -798,7 +798,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite


/** Demonstrate that using a write buffer reduces time spent seeking on disk */
void test_withFakeSeeking_withWriteBuffer()
void xest_withFakeSeeking_withWriteBuffer()
{
CPUTimer tim;
DiskBuffer dbuf(10);
Expand All @@ -811,7 +811,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite
}

/** Use a 0-sized write buffer so that it constantly needs to seek and write out. This should be slower due to seeking. */
void test_withFakeSeeking_noWriteBuffer()
void xest_withFakeSeeking_noWriteBuffer()
{
CPUTimer tim;
DiskBuffer dbuf(0);
Expand All @@ -825,7 +825,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite

/** Example of a situation where vectors grew, meaning that they need to be
* relocated causing lots of seeking if no write buffer exists.*/
void test_withFakeSeeking_growingData()
void xest_withFakeSeeking_growingData()
{
CPUTimer tim;
DiskBuffer dbuf(20);
Expand All @@ -843,7 +843,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite

/** Demonstrate that calling "save" manually without using the MRU write buffer will slow things down
* due to seeking. Was an issue in LoadMD */
void test_withFakeSeeking_growingData_savingWithoutUsingMRU()
void xest_withFakeSeeking_growingData_savingWithoutUsingMRU()
{
CPUTimer tim;
DiskBuffer dbuf(dataSeek.size());
Expand All @@ -857,7 +857,7 @@ class DiskBufferTestPerformance : public CxxTest::TestSuite
}

/** Speed of freeing a lot of blocks and putting them in the free space map */
void test_freeBlock()
void xest_freeBlock()
{
CPUTimer tim;
DiskBuffer dbuf(0);
Expand Down
9 changes: 8 additions & 1 deletion Code/Mantid/Framework/MDEvents/src/MDBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ namespace MDEvents
if(m_Saveable)
{
// tell disk buffer that there are no point of tracking this box any more.
this->m_BoxController->getFileIO()->objectDeleted(m_Saveable);
//BAD!!!
if(this->m_BoxController) // it is destructor, in tests everything may fall apart, though it should not be issue for a worspace
{
if(this->m_BoxController->isFileBacked())
{
this->m_BoxController->getFileIO()->objectDeleted(m_Saveable);
}
}
delete m_Saveable;
}
}
Expand Down

0 comments on commit 8e3850c

Please sign in to comment.