Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F428
DataStorageAsynchronousTest.patch
Public
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Authored By
•
wald
Mar 17 2010, 4:48 PM
2010-03-17 16:48:49 (UTC+1)
Size
2 KB
Referenced Files
None
Subscribers
None
DataStorageAsynchronousTest.patch
View Options
Index: mitkDataStorageTest.cpp
===================================================================
--- mitkDataStorageTest.cpp (revision 21768)
+++ mitkDataStorageTest.cpp (working copy)
@@ -38,11 +38,19 @@
#include "mitkNodePredicateSource.h"
#include "mitkMessage.h"
+//for asynchronous test
+#include <itkMultiThreader.h>
+#include <mitkPointSet.h>
+
#include "mitkTestingMacros.h"
void TestDataStorage(mitk::DataStorage* ds);
+void TestAsynchronousDataStorage();
+ITK_THREAD_RETURN_TYPE AddAsynchronousNodeOne(void* helper);
+ITK_THREAD_RETURN_TYPE AddAsynchronousNodeTwo(void* helper);
+
class DSEventReceiver // Helper class for event testing
{
public:
@@ -65,7 +73,14 @@
}
};
+class ThreadingHelper //Helper class for thread lock testing
+{
+public:
+ mitk::StandaloneDataStorage* dataStorage;
+ mitk::DataNode* node;
+};
+
//## Documentation
//## main testing method
//## NOTE: the current Singleton implementation of DataTreeStorage will lead to crashes if a testcase fails
@@ -89,7 +104,9 @@
MITK_TEST_OUTPUT( << "Testing StandaloneDataStorage: ");
TestDataStorage(sds);
- // TODO: Add specific StandaloneDataStorage Tests here
+
+ TestAsynchronousDataStorage();
+
sds = NULL;
MITK_TEST_END();
@@ -727,3 +744,69 @@
ds->Remove(ds->GetAll());
MITK_TEST_CONDITION(ds->GetAll()->Size() == 0, "Checking Clear DataStorage");
}
+
+void TestAsynchronousDataStorage()
+{
+ mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New();
+ MITK_TEST_CONDITION(ds->GetAll()->Size() == 0, "Checking empty DataStorage at beginning of asynchronous test");
+
+ itk::MultiThreader::Pointer threader = itk::MultiThreader::New();
+
+ itk::ThreadFunctionType threadFunctionOne = &AddAsynchronousNodeOne;
+ itk::ThreadFunctionType threadFunctionTwo = &AddAsynchronousNodeTwo;
+
+ mitk::DataNode::Pointer node = mitk::DataNode::New();
+ mitk::PointSet::Pointer pointset = mitk::PointSet::New();
+ node->SetData(pointset);
+
+ ThreadingHelper helper;
+ helper.dataStorage = ds;
+ helper.node = node;
+
+ try
+ {
+ threader->SpawnThread( threadFunctionOne, &helper );
+ threader->SpawnThread( threadFunctionTwo, &helper );
+ }
+ catch(...)
+ {
+ MITK_WARN << "Thread spawning error";
+ }
+}
+
+ITK_THREAD_RETURN_TYPE AddAsynchronousNodeOne(void* helper)
+{
+ ThreadingHelper* data = (ThreadingHelper*)helper;
+ for (unsigned int x = 0; x < 200; x++)
+ {
+ try
+ {
+ data->dataStorage->Add(data->node);
+ }
+ catch (...)
+ {
+ MITK_WARN << "Exception occured";
+ }
+ }
+
+ return ITK_THREAD_RETURN_VALUE;
+}
+
+ITK_THREAD_RETURN_TYPE AddAsynchronousNodeTwo(void* helper)
+{
+ ThreadingHelper* data = (ThreadingHelper*)helper;
+
+ for (unsigned int x = 0; x < 200; x++)
+ {
+ try
+ {
+ data->dataStorage->Add(data->node);
+ }
+ catch (...)
+ {
+ MITK_WARN << "Exception occured";
+ }
+ }
+
+ return ITK_THREAD_RETURN_VALUE;
+}
\ No newline at end of file
File Metadata
Details
Attached
Mime Type
application/octet-stream
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
411
Default Alt Text
DataStorageAsynchronousTest.patch (2 KB)
Attached To
Mode
T3238: Write unit tests for asynchronous DataStorage access
Attached
Detach File
Event Timeline
•
wald
added a comment.
Mar 17 2010, 4:48 PM
2010-03-17 16:48:49 (UTC+1)
Comment Actions
A first approach for a asynchronous test
Log In to Comment