QGIS API Documentation  3.14.0-Pi (9f7028fd23)
qgstestutils.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  qgstestutils.cpp
3  --------------------
4  begin : January 2018
5  copyright : (C) 2018 by Nyall Dawson
6  email : [email protected]
7  ***************************************************************************
8  * *
9  * This program is free software; you can redistribute it and/or modify *
10  * it under the terms of the GNU General Public License as published by *
11  * the Free Software Foundation; either version 2 of the License, or *
12  * (at your option) any later version. *
13  * *
14  ***************************************************************************/
15 
16 #include "qgstestutils.h"
17 #include "qgsvectordataprovider.h"
18 #include "qgsconnectionpool.h"
19 #include <QtConcurrentMap>
22 
23 static void getFeaturesForProvider( const QPair< QgsVectorDataProvider *, QgsFeatureRequest > &pair )
24 {
25  QgsFeatureIterator it = pair.first->getFeatures( pair.second );
26  QgsFeature f;
27  while ( it.nextFeature( f ) )
28  {
29 
30  }
31 }
32 
33 bool QgsTestUtils::testProviderIteratorThreadSafety( QgsVectorDataProvider *provider, const QgsFeatureRequest &request )
34 {
35  constexpr int JOBS_TO_RUN = 100;
36  QList< QPair< QgsVectorDataProvider *, QgsFeatureRequest > > jobs;
37  jobs.reserve( JOBS_TO_RUN );
38  for ( int i = 0; i < JOBS_TO_RUN; ++i )
39  {
40  jobs.append( qMakePair( provider, request ) );
41  }
42 
43  //freaking hammer the provider with a ton of concurrent requests.
44  //thread unsafe providers... you better be ready!!!!
45  QtConcurrent::blockingMap( jobs, getFeaturesForProvider );
46 
47  return true;
48 }
49 
50 
qgsconnectionpool.h
QgsFeatureRequest
Definition: qgsfeaturerequest.h:75
qgsvectordataprovider.h
QgsFeatureIterator::nextFeature
bool nextFeature(QgsFeature &f)
Definition: qgsfeatureiterator.h:373
qgstestutils.h
QgsVectorDataProvider
Definition: qgsvectordataprovider.h:58
QgsFeature
Definition: qgsfeature.h:55
QgsFeatureIterator
Definition: qgsfeatureiterator.h:263