Skip to content
This repository
Browse code

refactor: test for missing adapters in dataclientadapter base class

  • Loading branch information...
commit e37304e225cdc802293786547834879ed7e69df8 1 parent 7383211
Chris Williams authored
6 pelican/core/AbstractAdaptingDataClient.h
@@ -29,9 +29,9 @@ class AbstractAdaptingDataClient : public AbstractDataClient
29 29 public:
30 30 //PELICAN_CONSTRUCT_TYPES(const ConfigNode&, const DataTypes&, const Config*)
31 31 AbstractAdaptingDataClient( const ConfigNode& configNode,
32   - const QList<DataRequirements>& types,
33   - const Config* config,
34   - FactoryConfig<AbstractAdapter>* adapterFactory );
  32 + const DataTypes& types,
  33 + const Config* config
  34 + );
35 35 ~AbstractAdaptingDataClient();
36 36
37 37 /// Returns the type of data associated with the data name
28 pelican/core/AbstractDataClient.h
@@ -9,6 +9,7 @@
9 9 #include "pelican/utility/FactoryRegistrar.h"
10 10 #include "pelican/utility/Config.h"
11 11 #include "pelican/utility/ConfigNode.h"
  12 +#include "pelican/utility/FactoryConfig.h"
12 13
13 14 #include <QtCore/QHash>
14 15 #include <QtCore/QList>
@@ -64,15 +65,17 @@ class AbstractDataClient
64 65 typedef QHash<QString, DataBlob*> DataBlobHash;
65 66
66 67 public:
67   - PELICAN_CONSTRUCT_TYPES(const ConfigNode&, const DataTypes&, const Config*)
68 68
69 69 /// Data client constructor.
70 70 AbstractDataClient(const ConfigNode& configNode, const DataTypes& types,
71   - const Config* config);
  71 + const Config* config
  72 + );
72 73
73 74 /// Data client destructor.
74 75 virtual ~AbstractDataClient();
75 76
  77 + PELICAN_CONSTRUCT_TYPES(const ConfigNode&, const DataTypes&, const Config*)
  78 +
76 79 public:
77 80 /// Retrieves data requested by pipelines and fills the given data hash,
78 81 /// and returns another hash of valid data.
@@ -80,18 +83,17 @@ class AbstractDataClient
80 83 virtual DataBlobHash getData(DataBlobHash&) = 0;
81 84
82 85 /// Returns the list of data requirements for each pipeline.
83   - const QList<DataRequirements>& dataRequirements()
84   - { return _dataReqs.dataRequirements(); }
  86 + const QList<DataRequirements>& dataRequirements() { return _dataRequirements; }
85 87
86   - /// Returns the type of data associated with the data name
87   - /// (stream/service/unknown)
88   - AbstractAdapter::AdapterType_t type(const QString& dataName) const
89   - { return _dataReqs.type(dataName); }
90 88
91 89 protected:
92 90 /// Writes a message to the log.
93 91 void log(const QString& msg);
94 92
  93 + /// Returns a pointer to the configuration node.
  94 + const ConfigNode& configNode() const {return _configNode;}
  95 +
  96 +/*
95 97 /// Adapts (de-serialises) stream data.
96 98 DataBlobHash adaptStream(QIODevice& device, const StreamData* d,
97 99 DataBlobHash& dataHash);
@@ -100,8 +102,6 @@ class AbstractDataClient
100 102 DataBlobHash adaptService(QIODevice& device, const DataChunk* sd,
101 103 DataBlobHash& dataHash);
102 104
103   - /// Returns a pointer to the configuration node.
104   - const ConfigNode& configNode() const {return _configNode;}
105 105
106 106 /// Returns the adapter for service data of the required type.
107 107 AbstractServiceAdapter* serviceAdapter(const QString& type) const
@@ -110,12 +110,12 @@ class AbstractDataClient
110 110 /// Returns the adapter for stream data of the required type.
111 111 AbstractStreamAdapter* streamAdapter(const QString& type) const
112 112 { return _dataReqs.streamAdapter(type); }
113   -
114   - private:
115   - ConfigNode _configNode; ///< The configuration node for the data client.
116   - DataTypes _dataReqs; ///< The DataTypes and requirements.
  113 +*/
117 114
118 115 protected:
  116 + ConfigNode _configNode; ///< The configuration node for the data client.
  117 + QList<DataRequirements> _dataRequirements;
  118 + //DataTypes _dataReqs; ///< The DataTypes and requirements.
119 119 const Config* _config;
120 120 QSet<QString> _requireSet;
121 121 };
5 pelican/core/DataClientFactory.h
@@ -6,6 +6,7 @@
6 6 */
7 7
8 8 #include "pelican/core/AbstractDataClient.h"
  9 +#include "pelican/core/AbstractAdapterFactory.h"
9 10 #include "pelican/utility/FactoryConfig.h"
10 11
11 12 #include <QtCore/QList>
@@ -31,12 +32,12 @@ class DataRequirements;
31 32 class DataClientFactory : public FactoryConfig<AbstractDataClient>
32 33 {
33 34 private:
34   - FactoryConfig<AbstractAdapter>* _adapterFactory;
  35 + AbstractAdapterFactory* _adapterFactory;
35 36
36 37 public:
37 38 /// Constructs the data client factory.
38 39 DataClientFactory(const Config* config, const QString& section,
39   - const QString& group, FactoryConfig<AbstractAdapter>* aFactory)
  40 + const QString& group, AbstractAdapterFactory* aFactory)
40 41 : FactoryConfig<AbstractDataClient>(config, section, group),
41 42 _adapterFactory(aFactory) {}
42 43
3  pelican/core/DataTypes.h
@@ -52,6 +52,9 @@ class DataTypes
52 52 /// Return the adapter type associated with the given data stream.
53 53 AbstractAdapter::AdapterType_t type(const QString& dataName) const;
54 54
  55 + /// return true is the object maps an adapter to the specified type
  56 + bool adapterAvailable( const QString& type ) const;
  57 +
55 58 private:
56 59 QList<DataRequirements> _dataRequirements;
57 60 QHash<QString,AbstractAdapter*> _adapters;
7 pelican/core/DirectStreamDataClient.h
@@ -5,7 +5,7 @@
5 5 * @file DirectStreamDataClient.h
6 6 */
7 7
8   -#include "pelican/core/AbstractDataClient.h"
  8 +#include "pelican/core/AbstractAdaptingDataClient.h"
9 9
10 10 namespace pelican {
11 11
@@ -30,12 +30,13 @@ class Config;
30 30 * Add the chunkers using the addChunker() method in a derived class
31 31 * constructor.
32 32 */
33   -class DirectStreamDataClient : public AbstractDataClient
  33 +class DirectStreamDataClient : public AbstractAdaptingDataClient
34 34 {
35 35 public:
36 36 /// Constructs the direct stream data client.
37 37 DirectStreamDataClient(const ConfigNode& configNode,
38   - const DataTypes& types, const Config* config);
  38 + const DataTypes& types, const Config* config
  39 + );
39 40
40 41 /// Destroys the direct stream data client.
41 42 virtual ~DirectStreamDataClient();
4 pelican/core/FileDataClient.h
@@ -5,7 +5,7 @@
5 5 * @file FileDataClient.h
6 6 */
7 7
8   -#include "pelican/core/AbstractDataClient.h"
  8 +#include "pelican/core/AbstractAdaptingDataClient.h"
9 9 #include <QtCore/QHash>
10 10 #include <QtCore/QString>
11 11 class QFile;
@@ -30,7 +30,7 @@ class DataTypes;
30 30 * makes it available to the pipelines via the pipeline driver.
31 31 */
32 32
33   -class FileDataClient : public AbstractDataClient
  33 +class FileDataClient : public AbstractAdaptingDataClient
34 34 {
35 35 public:
36 36 /// Data client constructor.
7 pelican/core/PelicanServerClient.h
@@ -5,7 +5,7 @@
5 5 * @file PelicanServerClient.h
6 6 */
7 7
8   -#include "AbstractDataClient.h"
  8 +#include "AbstractAdaptingDataClient.h"
9 9 #include <boost/shared_ptr.hpp>
10 10 using boost::shared_ptr;
11 11
@@ -29,12 +29,13 @@ class ServiceDataRequest;
29 29 * @details
30 30 */
31 31
32   -class PelicanServerClient : public AbstractDataClient
  32 +class PelicanServerClient : public AbstractAdaptingDataClient
33 33 {
34 34 public:
35 35 /// Construct and initialise the Pelican server client.
36 36 PelicanServerClient(const ConfigNode& configNode,
37   - const DataTypes& types, const Config* config);
  37 + const DataTypes& types, const Config* config
  38 + );
38 39
39 40 virtual ~PelicanServerClient();
40 41
5 pelican/core/PipelineApplication.h
@@ -21,6 +21,7 @@ class AbstractDataClient;
21 21 class Config;
22 22 class PipelineDriver;
23 23 class DataClientFactory;
  24 +class AbstractAdapterFactory;
24 25 class OutputStreamManager;
25 26 class PipelineSwitcher;
26 27
@@ -92,7 +93,7 @@ class PipelineApplication
92 93 ~PipelineApplication();
93 94
94 95 /// Return a pointer to the adapter factory.
95   - FactoryConfig<AbstractAdapter>* adapterFactory();
  96 + AbstractAdapterFactory* adapterFactory();
96 97
97 98 /// Return a pointer to the client factory.
98 99 DataClientFactory* clientFactory();
@@ -150,7 +151,7 @@ class PipelineApplication
150 151 // Base nodes to define configuration file.
151 152 Config::TreeAddress _osmanagerBase;
152 153
153   - FactoryConfig<AbstractAdapter>* _adapterFactory;
  154 + AbstractAdapterFactory* _adapterFactory;
154 155 DataClientFactory* _clientFactory;
155 156 FactoryConfig<AbstractModule>* _moduleFactory;
156 157 };
32 pelican/core/src/AbstractAdaptingDataClient.cpp
@@ -12,31 +12,17 @@ namespace pelican {
12 12 *@details AbstractAdaptingDataClient
13 13 */
14 14 AbstractAdaptingDataClient::AbstractAdaptingDataClient( const ConfigNode& configNode,
15   - const QList<DataRequirements>& requirements,
16   - const Config* config, FactoryConfig<AbstractAdapter>* adapterFactory )
17   - : AbstractDataClient( configNode, requirements, config, adapterFactory )
  15 + const DataTypes& requirements,
  16 + const Config* config )
  17 + : AbstractDataClient( configNode, requirements, config )
18 18 {
19   - _dataReqs.addData(requirements);
20   -
21   - // Find the configuration information for adapters.
22   - QHash<QString, QString> adapterNames = configNode.getOptionHash("data", "type", "adapter");
23   -
24   - // Construct the adapters and add them to the DataTypes structure.
25   - foreach (const DataRequirements& req, requirements)
26   - {
27   - QSet<QString> all = req.allData();
28   - foreach (const QString& dataType, all)
29   - {
30   - if (!adapterNames.contains(dataType))
31   - throw QString("DataClientFactory: Unable to find adapter for "
32   - "data type '%1'.").arg(dataType);
33   - AbstractAdapter* adapter =
34   - _adapterFactory->create(adapterNames.value(dataType),
35   - configNode.getNamedOption("data","name","") );
36   - _dataReqs.setAdapter(dataType, adapter);
37   - }
  19 + _dataReqs = requirements;
  20 + // check we have adapters for each type
  21 + foreach (const QString& dataType, _requireSet) {
  22 + if (!_dataReqs.adapterAvailable(dataType))
  23 + throw QString("AbstractAdaptingDataClient: Unable to find adapter for "
  24 + "data type '%1'.").arg(dataType);
38 25 }
39   -
40 26 }
41 27
42 28 /**
12 pelican/core/src/AbstractDataClient.cpp
@@ -25,11 +25,13 @@ namespace pelican {
25 25 * @param[in] config \todo needs description
26 26 */
27 27 AbstractDataClient::AbstractDataClient(const ConfigNode& configNode,
28   - const DataTypes& types, const Config* config)
29   -: _configNode(configNode), _dataReqs(types), _config(config)
  28 + const DataTypes& types, const Config* config )
  29 +: _configNode(configNode), _config(config)
30 30 {
  31 + _dataRequirements = types.dataRequirements();
  32 +
31 33 // Quick sanity check.
32   - if (_dataReqs.dataRequirements().size() == 0)
  34 + if (_dataRequirements.size() == 0)
33 35 throw QString("AbstractDataClient: No data requirements specified");
34 36
35 37 // Construct the total set of requirements.
@@ -65,6 +67,7 @@ void AbstractDataClient::log(const QString& msg)
65 67 *
66 68 * @return
67 69 */
  70 +/*
68 71 AbstractDataClient::DataBlobHash AbstractDataClient::adaptStream(
69 72 QIODevice& device, const StreamData* sd, DataBlobHash& dataHash)
70 73 {
@@ -80,6 +83,7 @@ AbstractDataClient::DataBlobHash AbstractDataClient::adaptStream(
80 83
81 84 return validData;
82 85 }
  86 +*/
83 87
84 88 /**
85 89 * @details
@@ -90,7 +94,6 @@ AbstractDataClient::DataBlobHash AbstractDataClient::adaptStream(
90 94 * @param dataHash
91 95 *
92 96 * @return
93   - */
94 97 AbstractDataClient::DataBlobHash AbstractDataClient::adaptService(
95 98 QIODevice& device, const DataChunk* d, DataBlobHash& dataHash)
96 99 {
@@ -104,5 +107,6 @@ AbstractDataClient::DataBlobHash AbstractDataClient::adaptService(
104 107 validData.insert(type, dataHash.value(type));
105 108 return validData;
106 109 }
  110 + */
107 111
108 112 } // namespace pelican
19 pelican/core/src/DataClientFactory.cpp
@@ -34,19 +34,22 @@ AbstractDataClient* DataClientFactory::create(const QString& type,
34 34 QSet<QString> all = req.allData();
35 35 foreach (const QString& dataType, all)
36 36 {
37   - if (!adapterNames.contains(dataType))
38   - throw QString("DataClientFactory: Unable to find adapter for "
39   - "data type '%1'.").arg(dataType);
40   - AbstractAdapter* adapter =
41   - _adapterFactory->create(adapterNames.value(dataType),
42   - conf(type, name).getNamedOption("data","name","") );
43   - dataTypes.setAdapter(dataType, adapter);
  37 + //if (!adapterNames.contains(dataType))
  38 + // throw QString("DataClientFactory: Unable to find adapter for "
  39 + // "data type '%1'.").arg(dataType);
  40 + if (adapterNames.contains(dataType)) {
  41 + AbstractAdapter* adapter =
  42 + _adapterFactory->create(adapterNames.value(dataType),
  43 + conf(type, name).getNamedOption("data","name","") );
  44 + dataTypes.setAdapter(dataType, adapter);
  45 + }
44 46 }
45 47 }
46 48
47 49 // Call the base class implementation and set the data requirements.
48 50 AbstractDataClient* client = FactoryConfig<AbstractDataClient>::create(
49   - type, dataTypes, _config, name);
  51 + type, dataTypes, _config , name);
  52 +
50 53 return client;
51 54 }
52 55
4 pelican/core/src/DataTypes.cpp
@@ -88,4 +88,8 @@ const QList<DataRequirements>& DataTypes::dataRequirements() const
88 88 return _dataRequirements;
89 89 }
90 90
  91 +bool DataTypes::adapterAvailable( const QString& type ) const {
  92 + return _adapters.contains(type);
  93 +}
  94 +
91 95 } // namespace pelican
5 pelican/core/src/DirectStreamDataClient.cpp
@@ -21,8 +21,9 @@ class ConfigNode;
21 21 * @details Constructs the DirectStreamDataClient.
22 22 */
23 23 DirectStreamDataClient::DirectStreamDataClient(const ConfigNode& configNode,
24   - const DataTypes& types, const Config* config)
25   -: AbstractDataClient(configNode, types, config)
  24 + const DataTypes& types, const Config* config
  25 + )
  26 + : AbstractAdaptingDataClient(configNode, types, config )
26 27 {
27 28 // Initialise members.
28 29 _started = false;
4 pelican/core/src/FileDataClient.cpp
@@ -15,8 +15,8 @@ namespace pelican {
15 15 * This creates a new file data client.
16 16 */
17 17 FileDataClient::FileDataClient(const ConfigNode& configNode,
18   - const DataTypes& types, const Config* config) :
19   - AbstractDataClient(configNode, types, config)
  18 + const DataTypes& types, const Config* config)
  19 + : AbstractAdaptingDataClient(configNode, types, config)
20 20 {
21 21 // Get the configuration options.
22 22 _getConfig();
5 pelican/core/src/PelicanServerClient.cpp
@@ -35,8 +35,9 @@ namespace pelican {
35 35 * @param config
36 36 */
37 37 PelicanServerClient::PelicanServerClient(const ConfigNode& configNode,
38   - const DataTypes& types, const Config* config)
39   - : AbstractDataClient(configNode, types, config), _protocol(0)
  38 + const DataTypes& types, const Config* config
  39 + )
  40 + : AbstractAdaptingDataClient(configNode, types, config), _protocol(0)
40 41 {
41 42 _protocol = new PelicanClientProtocol;
42 43
8 pelican/core/src/PipelineApplication.cpp
@@ -4,6 +4,7 @@
4 4 #include "pelican/core/PipelineApplication.h"
5 5 #include "pelican/core/PipelineDriver.h"
6 6 #include "pelican/core/DataClientFactory.h"
  7 +#include "pelican/core/AbstractAdapterFactory.h"
7 8 #include "boost/program_options.hpp"
8 9 #include "pelican/utility/Config.h"
9 10 #include "pelican/utility/ConfigNode.h"
@@ -59,8 +60,9 @@ void PipelineApplication::init()
59 60 pipelineConfig << Config::NodeId("pipelineConfig","");
60 61
61 62 // initialise the factories
62   - _adapterFactory = new FactoryConfig<AbstractAdapter>(config(),
63   - "pipeline", "adapters");
  63 + //_adapterFactory = new FactoryConfig<AbstractAdapter>(config(),
  64 + // "pipeline", "adapters");
  65 + _adapterFactory = new AbstractAdapterFactory(config(), "pipeline", "adapters");
64 66 _clientFactory = new DataClientFactory(config(), "pipeline", "clients",
65 67 adapterFactory() );
66 68 _moduleFactory = new FactoryConfig<AbstractModule>(config(), "pipeline", "modules");
@@ -86,7 +88,7 @@ PipelineApplication::~PipelineApplication()
86 88 * @details
87 89 * Returns a pointer to the application's adapter factory.
88 90 */
89   -FactoryConfig<AbstractAdapter>* PipelineApplication::adapterFactory()
  91 +AbstractAdapterFactory* PipelineApplication::adapterFactory()
90 92 {
91 93 return _adapterFactory;
92 94 }
7 pelican/core/test/src/DirectStreamDataClientTest.cpp
... ... @@ -1,6 +1,7 @@
1 1 #include "pelican/core/test/DirectStreamDataClientTest.h"
2 2
3 3 #include "pelican/core/AbstractAdapter.h"
  4 +#include "pelican/core/AbstractAdapterFactory.h"
4 5 #include "pelican/core/DataClientFactory.h"
5 6 #include "pelican/core/DirectStreamDataClient.h"
6 7 #include "pelican/data/DataBlob.h"
@@ -110,7 +111,7 @@ void DirectStreamDataClientTest::test_singleChunker()
110 111 EmulatorDriver emulator(new RealUdpEmulator(*_emulatorConfig1));
111 112
112 113 // Create the adapter factory.
113   - FactoryConfig<AbstractAdapter> adapterFactory(_config, "pipeline", "adapters");
  114 + AbstractAdapterFactory adapterFactory(_config, "pipeline", "adapters");
114 115
115 116 // Create the data client factory.
116 117 DataClientFactory clientFactory(_config, "pipeline", "clients", &adapterFactory);
@@ -162,7 +163,7 @@ void DirectStreamDataClientTest::test_twoChunkersMultipleStarts()
162 163 EmulatorDriver emulator2(new RealUdpEmulator(*_emulatorConfig2));
163 164
164 165 // Create the adapter factory.
165   - FactoryConfig<AbstractAdapter> adapterFactory(_config,
  166 + AbstractAdapterFactory adapterFactory(_config,
166 167 "pipeline", "adapters");
167 168
168 169 // Create the data client factory.
@@ -218,7 +219,7 @@ void DirectStreamDataClientTest::test_twoChunkersSingleStart()
218 219 EmulatorDriver emulator2(new RealUdpEmulator(*_emulatorConfig2));
219 220
220 221 // Create the adapter factory.
221   - FactoryConfig<AbstractAdapter> adapterFactory(_config,
  222 + AbstractAdapterFactory adapterFactory(_config,
222 223 "pipeline", "adapters");
223 224
224 225 // Create the data client factory.
5 pelican/core/test/src/FileDataClientTest.cpp
@@ -6,8 +6,10 @@
6 6 #include "pelican/data/DataRequirements.h"
7 7 #include "pelican/data/DataBlob.h"
8 8 #include "pelican/core/DataTypes.h"
  9 +#include "pelican/core/test/TestStreamAdapter.h"
9 10
10 11 namespace pelican {
  12 +using test::TestStreamAdapter;
11 13
12 14 CPPUNIT_TEST_SUITE_REGISTRATION( FileDataClientTest );
13 15 /**
@@ -79,6 +81,7 @@ void FileDataClientTest::test_method()
79 81 CPPUNIT_ASSERT_THROW(client = new FileDataClient(configNode, dt, 0), QString);
80 82 delete client;
81 83 }
  84 + TestStreamAdapter streamAdapter;
82 85 QString stream1("stream1");
83 86 QString version1("version1");
84 87 DataRequirements req;
@@ -92,6 +95,7 @@ void FileDataClientTest::test_method()
92 95 lreq.append(req);
93 96 DataTypes dt;
94 97 dt.addData(lreq);
  98 + dt.setAdapter(stream1,&streamAdapter);
95 99 FileDataClient client(configNode, dt, 0);
96 100
97 101 QHash<QString, DataBlob*> dataHash;
@@ -106,6 +110,7 @@ void FileDataClientTest::test_method()
106 110 lreq.append(req);
107 111 DataTypes types;
108 112 types.addData(lreq);
  113 + types.setAdapter(stream1,&streamAdapter);
109 114 FileDataClient client(configNode, types, &config);
110 115
111 116 QHash<QString, DataBlob*> dataHash;
4 pelican/core/test/src/PelicanServerClientTest.cpp
@@ -77,6 +77,7 @@ void PelicanServerClientTest::test_getData()
77 77 CPPUNIT_ASSERT_THROW(client = new PelicanServerClient(configNode, dt, 0), QString);
78 78 delete client;
79 79 }
  80 + TestStreamAdapter streamAdapter;
80 81 QString stream1("stream1");
81 82 QString version1("version1");
82 83 DataRequirements req;
@@ -90,8 +91,8 @@ void PelicanServerClientTest::test_getData()
90 91 lreq.append(req);
91 92 DataTypes dt;
92 93 dt.addData(lreq);
  94 + dt.setAdapter(stream1,&streamAdapter);
93 95 PelicanServerClient client(configNode, dt, 0);
94   -
95 96 QHash<QString, DataBlob*> dataHash;
96 97 CPPUNIT_ASSERT_THROW(client.getData(dataHash), QString );
97 98 }
@@ -106,6 +107,7 @@ void PelicanServerClientTest::test_getData()
106 107 lreq.append(req);
107 108 DataTypes dt;
108 109 dt.addData(lreq);
  110 + dt.setAdapter(stream1,&streamAdapter);
109 111 PelicanServerClient client(configNode, dt, 0);
110 112
111 113 QHash<QString, DataBlob*> dataHash;
1  pelican/core/test/src/PelicanServerClientTestMT.cpp
@@ -89,6 +89,7 @@ void PelicanServerClientTestMT::test_getData()
89 89 lreq.append(req);
90 90 DataTypes dt;
91 91 dt.addData(lreq);
  92 + dt.setAdapter(service1, &serviceAdapter);
92 93 PelicanServerClient client(configNode, dt, 0);
93 94 client.setPort(port);
94 95
2  pelican/core/test/src/directClientMain.cpp
@@ -63,7 +63,7 @@ int main(int argc, char** argv)
63 63 config.setFromString(pipelineXml);
64 64
65 65 // Create the adapter factory.
66   - FactoryConfig<AbstractAdapter> adapterFactory(&config, "pipeline", "adapters");
  66 + AbstractAdapterFactory adapterFactory(&config, "pipeline", "adapters");
67 67
68 68 // Create the data client factory.
69 69 DataClientFactory clientFactory(&config, "pipeline", "clients", &adapterFactory);

0 comments on commit e37304e

Please sign in to comment.
Something went wrong with that request. Please try again.