Skip to content

Commit

Permalink
refs #6449 Have hopefully fixed system test
Browse files Browse the repository at this point in the history
  • Loading branch information
abuts authored and martyngigg committed Apr 10, 2013
1 parent 0049380 commit f125460
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 30 deletions.
21 changes: 13 additions & 8 deletions Code/Mantid/Framework/Kernel/src/DiskBuffer.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "MantidKernel/DiskBuffer.h"
#include "MantidKernel/System.h"
#include <Poco/ScopedLock.h>
#include <iostream>
#include <sstream>

Expand Down Expand Up @@ -66,12 +67,12 @@ namespace Kernel
if(item->getBufPostion()) // already in the buffer and probably have changed its size in memory
{
// forget old memory size
m_mutex.lock();
m_mutex.lock();
m_writeBufferUsed-=item->getBufferSize();
// add new size
size_t newMemorySize =item->getDataMemorySize();
m_writeBufferUsed+=newMemorySize;
m_mutex.unlock();
m_mutex.unlock();
item->setBufferSize(newMemorySize);
}
else
Expand Down Expand Up @@ -103,19 +104,22 @@ namespace Kernel
void DiskBuffer::objectDeleted(ISaveable * item)
{
// have it ever been in the buffer?
m_mutex.lock();
auto opt2it = item->getBufPostion();
if(opt2it)
{
m_mutex.lock();
m_writeBufferUsed -=item->getBufferSize();
m_toWriteBuffer.erase(*opt2it);
m_mutex.unlock();
m_writeBufferUsed -=item->getBufferSize();
m_toWriteBuffer.erase(*opt2it);
}
else
{
m_mutex.unlock();
return;
}

// indicate to the object that it is not stored in memory any more
item->clearBufferState();
// indicate to the object that it is not stored in memory any more
item->clearBufferState();
m_mutex.unlock();
//std::cout << "DiskBuffer deleting ID " << item->getId() << "; new size " << m_writeBuffer.size() << std::endl;

// Mark the amount of space used on disk as free
Expand Down Expand Up @@ -146,6 +150,7 @@ namespace Kernel
auto it_end = m_toWriteBuffer.end();

ISaveable * obj = NULL;

for (; it != it_end; ++it)
{
obj = *it;
Expand Down
44 changes: 22 additions & 22 deletions Code/Mantid/Framework/Kernel/test/DiskBufferTest.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class SaveableTesterWithFile : public Saveable

for (size_t i=mPos; i< mPos+mMem; i++)
fakeFile[i] = m_ch;
streamMutex.unlock();

(const_cast<SaveableTesterWithFile *>(this))->setFilePosition(mPos,mMem,true);
Expand Down Expand Up @@ -156,7 +156,7 @@ class DiskBufferTest : public CxxTest::TestSuite
}

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

/** Extreme case with nothing writable but exceeding the writable buffer */
void xest_noWriteBuffer_nothingWritableWasSaved()
void test_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 xest_writesOutInFileOrder()
void test_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 xest_objectDeleted()
void test_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 xest_thread_safety()
void test_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 xest_freeBlock_mergesWithPrevious()
void test_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 xest_freeBlock_mergesWithNext()
void test_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 xest_freeBlock_mergesWithBothNeighbours()
void test_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 xest_freeBlock_threadSafety()
void test_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 xxest_defragFreeBlocks()
//void xtest_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 xest_relocate_when_shrinking()
void test_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 xest_relocate_when_growing()
void test_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 xest_allocate_from_empty_freeMap()
void test_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 xest_allocate_and_relocate()
void test_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 xest_allocate_with_file_manually()
void test_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 xest_allocate_with_file()
void test_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 xest_withFakeSeeking_withWriteBuffer()
void test_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 xest_withFakeSeeking_noWriteBuffer()
void test_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 xest_withFakeSeeking_growingData()
void test_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 xest_withFakeSeeking_growingData_savingWithoutUsingMRU()
void test_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 xest_freeBlock()
void test_freeBlock()
{
CPUTimer tim;
DiskBuffer dbuf(0);
Expand Down

0 comments on commit f125460

Please sign in to comment.