Test for multithread (concurrent) index ForEach and FeatureType loading from file.

This commit is contained in:
vng 2012-01-30 18:18:29 +03:00 committed by Alex Zolotarev
parent 55a1b6b3cb
commit 9176ae5056
3 changed files with 108 additions and 9 deletions

View file

@ -1,5 +1,3 @@
#include "../../base/SRC_FIRST.hpp"
#include "../../testing/testing.hpp"
#include "../../platform/platform.hpp"
@ -37,7 +35,7 @@ protected:
m_dbgString = f.DebugString(m_scale);
CHECK(m_dbgString == f.DebugString(m_scale), ());
// Feature that hasn't any geometry for m_scale returns empty DebugString().
// Feature that doesn't have any geometry for m_scale returns empty DebugString().
return (!f.IsEmptyGeometry(m_scale) && feature::IsDrawableForIndex(f, m_scale));
}
@ -277,12 +275,10 @@ namespace
src1.InitClassificator();
src1.AddMap(file);
feature::DataHeader mapInfo;
ModelReaderPtr reader = GetPlatform().GetReader(file);
mapInfo.Load(FilesContainerR(reader).GetReader(HEADER_FILE_TAG));
vector<m2::RectD> rects;
rects.push_back(mapInfo.GetBounds());
rects.push_back(src1.GetWorldRect());
ModelReaderPtr reader = GetPlatform().GetReader(file);
while (!rects.empty())
{
@ -327,7 +323,7 @@ namespace
}
}
UNIT_TEST(IndexForEachTest)
UNIT_TEST(ForEach_QueryResults)
{
RunTestForChoice("minsk-pass");
//RunTestForChoice("london-center");

View file

@ -24,3 +24,4 @@ SOURCES += \
map_foreach_test.cpp \
debug_features_test.cpp \
draw_processor_test.cpp \
multithread_map_test.cpp \

View file

@ -0,0 +1,102 @@
#include "../../testing/testing.hpp"
#include "../../map/feature_vec_model.hpp"
#include "../../base/thread.hpp"
namespace
{
typedef model::FeaturesFetcher SourceT;
class FeaturesLoader : public threads::IRoutine
{
SourceT const & m_src;
int m_scale;
// Get random rect inside m_src.
m2::RectD GetRandomRect() const
{
int const count = max(1, rand() % 50);
int const x = rand() % count;
int const y = rand() % count;
m2::RectD const r = m_src.GetWorldRect();
double const sizeX = r.SizeX() / count;
double const sizeY = r.SizeY() / count;
double const minX = r.minX() + x * sizeX;
double const minY = r.minY() + y * sizeY;
return m2::RectD(minX, minY, minX + sizeX, minY + sizeY);
}
public:
FeaturesLoader(SourceT const & src) : m_src(src) {}
virtual void Do()
{
size_t const count = 2000;
for (size_t i = 0; i < count; ++i)
{
m2::RectD const r = GetRandomRect();
m_scale = scales::GetScaleLevel(r);
m_src.ForEachFeature_TileDrawing(r, *this, m_scale);
}
}
void operator() (FeatureType const & f)
{
// Force load feature.
// We check asserts here. There is no any other constrains here.
(void)f.IsEmptyGeometry(m_scale);
}
};
void RunTest(string const & file)
{
SourceT src;
src.InitClassificator();
src.AddMap(file + DATA_FILE_EXTENSION);
// Check that country rect is valid and not infinity.
m2::RectD const r = src.GetWorldRect();
TEST ( r.IsValid(), () );
m2::RectD world(MercatorBounds::minX, MercatorBounds::minY,
MercatorBounds::maxX, MercatorBounds::maxY);
world.Inflate(-10.0, -10.0);
TEST ( world.IsRectInside(r), () );
srand(666);
size_t const count = 20;
vector<pair<threads::Thread *, FeaturesLoader *> > pool;
pool.resize(count);
for (size_t i = 0; i < count; ++i)
{
pool[i].second = new FeaturesLoader(src);
pool[i].first = new threads::Thread();
pool[i].first->Create(pool[i].second);
}
for (size_t i = 0; i < count; ++i)
{
pool[i].first->Join();
delete pool[i].first;
delete pool[i].second;
}
}
}
UNIT_TEST(Threading_ForEachFeature)
{
RunTest("minsk-pass");
}