NdmcMetricTest.cpp
Go to the documentation of this file.
1 #include "NdmcMetricTest.h"
2 using namespace NDMC_NAMESPACE;
3 
4 /**
5  * Register the NdmcMetricTest suite in the registry of suites in a "folder"
6  * of name "NovaDAQMonitorClient". Store the folder in the default registry path.
7  * $Id: NdmcMetricTest.cpp,v 1.20 2017/08/08 20:21:10 dingpf Exp $
8  */
10 CPPUNIT_REGISTRY_ADD_TO_DEFAULT("NovaDAQMonitorClient");
11 
12 /**
13  * A public method to setUp the environment for the test. This will be invoked before
14  * every test in the fixture to get a fresh start.
15  */
17 
18  _configFile = getConfigFullFilePathName("unittest/gmond.conf");
20 
21 }
22 /**
23  * A public method to tearDown the environment for the test. This will be invoked after
24  * every test in the fixture to clean up allocated memory.
25  */
27  std::cout.flush();
28 }
29 
30 /**
31  * A test method to test that NdmcMetric::instance()
32  * works correctly.
33  */
35 
36  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCtor." << std::endl;
37 
38  std::string name="dummy";
39  std::string unit="bytes";
40  ganglia_slope_t slope = GANGLIA_SLOPE_POSITIVE;
41 
42  NdmcMetric<uint32_t> metric(name.c_str(),unit.c_str(),VALUE,15,5,slope);
43  CPPUNIT_ASSERT(metric.getName() == name);
44  CPPUNIT_ASSERT(metric.getUnit() == unit);
45  CPPUNIT_ASSERT(metric.getMetricType() == VALUE);
46  CPPUNIT_ASSERT(metric.getMaxDeltaTime() == 15);
47  CPPUNIT_ASSERT(metric.getLifeTime() == 5);
48  CPPUNIT_ASSERT(metric.getSlope() == slope);
49  CPPUNIT_ASSERT(metric.getType() == "uint32");
50  CPPUNIT_ASSERT(metric.getValue() == 0);
51  CPPUNIT_ASSERT(metric.getSumW() == 0);
52  CPPUNIT_ASSERT(metric.getNW() == 0);
53  CPPUNIT_ASSERT(metric.getSumWX() == 0);
54  CPPUNIT_ASSERT(metric.getSumWXSq() == 0);
55  CPPUNIT_ASSERT(metric.isValueSet() == false);
56  CPPUNIT_ASSERT(metric.getPartition() == -1);
57  CPPUNIT_ASSERT(metric.getApplicationName() == "");
58  CPPUNIT_ASSERT(metric.getGroupName() == "");
59  CPPUNIT_ASSERT(metric.getMetricName() == metric.getName());
60  uint32_t lastValueSent = 99;
61  CPPUNIT_ASSERT(metric.getLastValueSent(lastValueSent) == false);
62  CPPUNIT_ASSERT(lastValueSent == 99);
63 
64  int32_t partition = 2;
65  std::string appName = "dcmapp";
66  std::string groupName = "dcmapp P2";
67  NdmcMetric<uint32_t> metric2(name.c_str(),unit.c_str(),VALUE,15,5,slope,
68  partition, appName, groupName);
69  CPPUNIT_ASSERT(metric2.getName() == name);
70  CPPUNIT_ASSERT(metric2.getUnit() == unit);
71  CPPUNIT_ASSERT(metric2.getMetricType() == VALUE);
72  CPPUNIT_ASSERT(metric2.getMaxDeltaTime() == 15);
73  CPPUNIT_ASSERT(metric2.getLifeTime() == 5);
74  CPPUNIT_ASSERT(metric2.getSlope() == slope);
75  CPPUNIT_ASSERT(metric2.getType() == "uint32");
76  CPPUNIT_ASSERT(metric2.getValue() == 0);
77  CPPUNIT_ASSERT(metric2.getSumW() == 0);
78  CPPUNIT_ASSERT(metric2.getNW() == 0);
79  CPPUNIT_ASSERT(metric2.getSumWX() == 0);
80  CPPUNIT_ASSERT(metric2.getSumWXSq() == 0);
81  CPPUNIT_ASSERT(metric2.isValueSet() == false);
82  CPPUNIT_ASSERT(metric2.getPartition() == partition);
83  CPPUNIT_ASSERT(metric2.getApplicationName() == appName);
84  CPPUNIT_ASSERT(metric2.getGroupName() == groupName);
85  CPPUNIT_ASSERT(metric2.getMetricName() == "dummy_Adcmapp_P2");
86 
87 }
88 
89 /**
90  * A test method to test that NdmcMetric::getType
91  * works correctly for uint32_t.
92  */
94 
95  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeUint32_t." << std::endl;
96 
97  std::string name="dummy";
98  NdmcMetric<uint32_t> metric(name.c_str());
99  CPPUNIT_ASSERT(metric.getType() == "uint32");
100 
101 }
102 
103 /**
104  * A test method to test that NdmcMetric::getType
105  * works correctly for int32_t.
106  */
108 
109  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeInt32_t." << std::endl;
110 
111  std::string name="dummy";
112  NdmcMetric<int32_t> metric(name.c_str());
113  CPPUNIT_ASSERT(metric.getType() == "int32");
114 
115 }
116 
117 /**
118  * A test method to test that NdmcMetric::getType
119  * works correctly for uint16_t.
120  */
122 
123  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeUint16_t." << std::endl;
124 
125  std::string name="dummy";
126  NdmcMetric<uint16_t> metric(name.c_str());
127  CPPUNIT_ASSERT(metric.getType() == "uint16");
128 
129 }
130 
131 /**
132  * A test method to test that NdmcMetric::getType
133  * works correctly for int16_t.
134  */
136 
137  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeInt16_t." << std::endl;
138 
139  std::string name="dummy";
140  NdmcMetric<int16_t> metric(name.c_str());
141  CPPUNIT_ASSERT(metric.getType() == "int16");
142 
143 }
144 
145 /**
146  * A test method to test that NdmcMetric::getType
147  * works correctly for uint8_t.
148  */
150 
151  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeUint8_t." << std::endl;
152 
153  std::string name="dummy";
154  NdmcMetric<uint8_t> metric(name.c_str());
155  CPPUNIT_ASSERT(metric.getType() == "uint8");
156 
157 }
158 
159 /**
160  * A test method to test that NdmcMetric::getType
161  * works correctly for int8_t.
162  */
164 
165  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeInt8_t." << std::endl;
166 
167  std::string name="dummy";
168  NdmcMetric<int8_t> metric(name.c_str());
169  CPPUNIT_ASSERT(metric.getType() == "int8");
170 
171 }
172 
173 
174 /**
175  * A test method to test that NdmcMetric::getType
176  * works correctly for float.
177  */
179 
180  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeFloat." << std::endl;
181 
182  std::string name="dummy";
183  NdmcMetric<float> metric(name.c_str());
184  CPPUNIT_ASSERT(metric.getType() == "float");
185 
186 
187 }
188 
189 /**
190  * A test method to test that NdmcMetric::getType
191  * works correctly for double.
192  */
194 
195  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeDouble." << std::endl;
196 
197  std::string name="dummy";
198  NdmcMetric<double> metric(name.c_str());
199  CPPUNIT_ASSERT(metric.getType() == "double");
200 
201 }
202 
203 /**
204  * A test method to test that NdmcMetric::getType
205  * works correctly for unknown type.
206  */
208 
209  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetTypeUnknown." << std::endl;
210 
211  std::string name="dummy";
212  NdmcMetric<uint64_t> metric(name.c_str()); /**< 64-bit not supported by Ganglia */
213  CPPUNIT_ASSERT(metric.getType() == "Unknown");
214 
215 }
216 
217 /**
218  * A test method to test that NdmcMetric::setValue
219  * works correctly for a metric of type VALUE.
220  */
222 
223  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetValueMetricTypeVALUE." << std::endl;
224 
225  std::string name="dummy";
226  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",VALUE);
227 
228  CPPUNIT_ASSERT(metricUInt32.isValueSet() == false);
229 
230  CPPUNIT_ASSERT(metricUInt32.setValue(10));
231  CPPUNIT_ASSERT(metricUInt32.getValue() == 10);
232  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
233 
234  NdmcMetric<double> metricDouble(name.c_str(),"unit",VALUE);
235  CPPUNIT_ASSERT(metricDouble.setValue(15.));
236  CPPUNIT_ASSERT(metricDouble.getValue() == 15.);
237  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
238  CPPUNIT_ASSERT(metricDouble.setValue(-15.));
239  CPPUNIT_ASSERT(metricDouble.getValue() == -15.);
240  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
241 
242  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",VALUE);
243  CPPUNIT_ASSERT(metricInt32.setValue(-1));
244  CPPUNIT_ASSERT(metricInt32.getValue() == -1);
245  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
246  CPPUNIT_ASSERT(metricInt32.setValue(15));
247  CPPUNIT_ASSERT(metricInt32.getValue() == 15);
248  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
249 
250 }
251 
252 /**
253  * A test method to test that NdmcMetric::_calculateSendValue
254  * works correctly for a metric of type VALUE.
255  */
257 
258  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCalculateSendValueMetricTypeVALUE." << std::endl;
259 
260  std::string name="dummy";
261  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",VALUE);
262  CPPUNIT_ASSERT(metricUInt32.setValue(10));
263  uint32_t sendValueUInt32 = 0;
264  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32) == true);
265  CPPUNIT_ASSERT(sendValueUInt32 == 10);
266 
267 
268  NdmcMetric<double> metricDouble(name.c_str(),"unit",VALUE);
269  CPPUNIT_ASSERT(metricDouble.setValue(15.));
270  CPPUNIT_ASSERT(metricDouble.setValue(-15));
271  double sendValueDouble = 0;
272  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble) == true);
273  CPPUNIT_ASSERT(sendValueDouble == -15.);
274 
275  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",VALUE);
276  CPPUNIT_ASSERT(metricInt32.setValue(-1));
277  CPPUNIT_ASSERT(metricInt32.setValue(15));
278  int32_t sendValueInt32 = 0;
279  CPPUNIT_ASSERT(metricInt32._calculateSendValue(sendValueInt32) == true);
280  CPPUNIT_ASSERT(sendValueInt32 == 15);
281 
282 }
283 
284 /**
285  * A test method to test that NdmcMetric::setValue
286  * works correctly for a metric of type COUNTER.
287  */
289 
290  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetValueMetricTypeCOUNTER." << std::endl;
291 
292  std::string name="dummy";
293  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",COUNTER);
294  CPPUNIT_ASSERT(metricUInt32.isValueSet() == false);
295 
296  CPPUNIT_ASSERT(metricUInt32.setValue(10));
297  CPPUNIT_ASSERT(metricUInt32.getValue() == 10);
298  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
299  CPPUNIT_ASSERT(metricUInt32.setValue(10));
300  CPPUNIT_ASSERT(metricUInt32.getValue() == 20);
301  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
302 
303 
304  NdmcMetric<double> metricDouble(name.c_str(),"unit",COUNTER);
305  CPPUNIT_ASSERT(metricDouble.isValueSet() == false);
306  CPPUNIT_ASSERT(metricDouble.setValue(15.));
307  CPPUNIT_ASSERT(metricDouble.getValue() == 15.);
308  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
309  CPPUNIT_ASSERT(metricDouble.setValue(-15.));
310  CPPUNIT_ASSERT(metricDouble.getValue() == 0.);
311  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
312 
313 
314  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",COUNTER);
315  CPPUNIT_ASSERT(metricInt32.isValueSet() == false);
316  CPPUNIT_ASSERT(metricInt32.setValue(-1));
317  CPPUNIT_ASSERT(metricInt32.getValue() == -1);
318  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
319  CPPUNIT_ASSERT(metricInt32.setValue(15));
320  CPPUNIT_ASSERT(metricInt32.getValue() == 14);
321  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
322 
323 }
324 
325 /**
326  * A test method to test that NdmcMetric::_calculateSendValue
327  * works correctly for a metric of type COUNTER.
328  */
330 
331  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCalculateSendValueMetricTypeCOUNTER."
332  << std::endl;
333 
334  std::string name="dummy";
335  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",COUNTER);
336  CPPUNIT_ASSERT(metricUInt32.setValue(10));
337  uint32_t sendValueUInt32 = 0;
338  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32) == true);
339  CPPUNIT_ASSERT(sendValueUInt32 == 10);
340 
341 
342  NdmcMetric<double> metricDouble(name.c_str(),"unit",COUNTER);
343  CPPUNIT_ASSERT(metricDouble.setValue(15.));
344  CPPUNIT_ASSERT(metricDouble.setValue(-15));
345  double sendValueDouble = 0;
346  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble) == true);
347  CPPUNIT_ASSERT(sendValueDouble == 0.);
348 
349  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",COUNTER);
350  CPPUNIT_ASSERT(metricInt32.setValue(-1));
351  CPPUNIT_ASSERT(metricInt32.setValue(15));
352  int32_t sendValueInt32 = 0;
353  CPPUNIT_ASSERT(metricInt32._calculateSendValue(sendValueInt32) == true);
354  CPPUNIT_ASSERT(sendValueInt32 == 14);
355 
356 }
357 
358 /**
359  * A test method to test that NdmcMetric::setValue
360  * works correctly for a metric of type RATE.
361  */
363 
364  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetValueMetricTypeRATE." << std::endl;
365 
366  std::string name="dummy";
367  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",RATE);
368  CPPUNIT_ASSERT(metricUInt32.isValueSet() == false);
369 
370  CPPUNIT_ASSERT(metricUInt32.setValue(10));
371  CPPUNIT_ASSERT(metricUInt32.getValue() == 10);
372  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
373  CPPUNIT_ASSERT(metricUInt32.setValue(10));
374  CPPUNIT_ASSERT(metricUInt32.getValue() == 20);
375  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
376 
377 
378  NdmcMetric<double> metricDouble(name.c_str(),"unit",RATE);
379  CPPUNIT_ASSERT(metricDouble.isValueSet() == false);
380  CPPUNIT_ASSERT(metricDouble.setValue(15.));
381  CPPUNIT_ASSERT(metricDouble.getValue() == 15.);
382  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
383  CPPUNIT_ASSERT(metricDouble.setValue(-15.));
384  CPPUNIT_ASSERT(metricDouble.getValue() == 0.);
385  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
386 
387  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",RATE);
388  CPPUNIT_ASSERT(metricInt32.isValueSet() == false);
389  CPPUNIT_ASSERT(metricInt32.setValue(-1));
390  CPPUNIT_ASSERT(metricInt32.getValue() == -1);
391  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
392  CPPUNIT_ASSERT(metricInt32.setValue(15));
393  CPPUNIT_ASSERT(metricInt32.getValue() == 14);
394  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
395 
396 }
397 
398 /**
399  * A test method to test that NdmcMetric::_calculateSendValue
400  * works correctly for a metric of type RATE.
401  */
403 
404  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCalculateSendValueMetricTypeRATE."
405  << std::endl;
406 
407  std::string name="dummy";
408  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",RATE);
409  CPPUNIT_ASSERT(metricUInt32.setValue(10));
410  uint32_t sendValueUInt32 = 0;
411  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32,9.) == true);
412  CPPUNIT_ASSERT(sendValueUInt32 == 1);
413  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32,15.) == true);
414  CPPUNIT_ASSERT(sendValueUInt32 == 0);
415 
416 
417  NdmcMetric<double> metricDouble(name.c_str(),"unit",RATE);
418  CPPUNIT_ASSERT(metricDouble.setValue(15.));
419  CPPUNIT_ASSERT(metricDouble.setValue(-15));
420  double sendValueDouble = 0;
421  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble,10.) == true);
422  CPPUNIT_ASSERT(sendValueDouble == 0.);
423  CPPUNIT_ASSERT(metricDouble.setValue(5.));
424  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble,10.) == true);
425  CPPUNIT_ASSERT(sendValueDouble == 0.5);
426  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble,0.) == false);
427 
428  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",RATE);
429  CPPUNIT_ASSERT(metricInt32.setValue(-1));
430  CPPUNIT_ASSERT(metricInt32.setValue(15));
431  int32_t sendValueInt32 = 0;
432  CPPUNIT_ASSERT(metricInt32._calculateSendValue(sendValueInt32,10) == true);
433  CPPUNIT_ASSERT(sendValueInt32 == 1);
434 
435 }
436 
437 /**
438  * A test method to test that NdmcMetric::setValue
439  * works correctly for a metric of type AVERAGE.
440  */
442 
443  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetValueMetricTypeAVERAGE." << std::endl;
444 
445  std::string name="dummy";
446  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",AVERAGE);
447  CPPUNIT_ASSERT(metricUInt32.isValueSet() == false);
448 
449  CPPUNIT_ASSERT(metricUInt32.setValue(10));
450  CPPUNIT_ASSERT(metricUInt32.getSumWX() == 10);
451  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
452  CPPUNIT_ASSERT(metricUInt32.setValue(10,2.));
453  CPPUNIT_ASSERT(metricUInt32.getSumWX() == 30);
454  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
455 
456 
457  NdmcMetric<double> metricDouble(name.c_str(),"unit",AVERAGE);
458 
459  CPPUNIT_ASSERT(metricDouble.isValueSet() == false);
460  CPPUNIT_ASSERT(metricDouble.setValue(15.));
461  CPPUNIT_ASSERT(metricDouble.getSumWX() == 15.);
462  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
463  CPPUNIT_ASSERT(metricDouble.setValue(-15.,2.));
464  CPPUNIT_ASSERT(metricDouble.getSumWX() == -15.);
465  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
466 
467  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",AVERAGE);
468 
469  CPPUNIT_ASSERT(metricInt32.isValueSet() == false);
470  CPPUNIT_ASSERT(metricInt32.setValue(-1));
471  CPPUNIT_ASSERT(metricInt32.getSumWX() == -1);
472  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
473  CPPUNIT_ASSERT(metricInt32.setValue(15,2));
474  CPPUNIT_ASSERT(metricInt32.getSumWX() == 29);
475  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
476 
477 }
478 
479 /**
480  * A test method to test that NdmcMetric::_calculateSendValue
481  * works correctly for a metric of type AVERAGE.
482  */
484 
485  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCalculateSendValueMetricTypeAVERAGE."
486  << std::endl;
487 
488  std::string name="dummy";
489  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",AVERAGE);
490  CPPUNIT_ASSERT(metricUInt32.setValue(10));
491  CPPUNIT_ASSERT(metricUInt32.setValue(10,2.));
492  uint32_t sendValueUInt32 = 0;
493  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32) == true);
494  CPPUNIT_ASSERT(sendValueUInt32 == 10);
495 
496 
497  NdmcMetric<double> metricDouble(name.c_str(),"unit",AVERAGE);
498  CPPUNIT_ASSERT(metricDouble.setValue(15.));
499  CPPUNIT_ASSERT(metricDouble.setValue(-15.,2.));
500  double sendValueDouble = 0;
501  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble) == true);
502  CPPUNIT_ASSERT(sendValueDouble == -5.);
503 
504  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",AVERAGE);
505  CPPUNIT_ASSERT(metricInt32.setValue(-1));
506  CPPUNIT_ASSERT(metricInt32.setValue(15,2));
507  int32_t sendValueInt32 = 0;
508  CPPUNIT_ASSERT(metricInt32._calculateSendValue(sendValueInt32) == true);
509  CPPUNIT_ASSERT(sendValueInt32 == 9);
510 
511 }
512 
513 /**
514  * A test method to test that NdmcMetric::setValue
515  * works correctly for a metric of type MINIMUM.
516  */
518 
519  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetValueMetricTypeMINIMUM." << std::endl;
520 
521  std::string name="dummy";
522  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",MINIMUM);
523  CPPUNIT_ASSERT(metricUInt32.isValueSet() == false);
524 
525  CPPUNIT_ASSERT(metricUInt32.setValue(10));
526  CPPUNIT_ASSERT(metricUInt32.getValue() == 10);
527  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
528  CPPUNIT_ASSERT(metricUInt32.setValue(10));
529  CPPUNIT_ASSERT(metricUInt32.getValue() == 10);
530  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
531 
532 
533  NdmcMetric<double> metricDouble(name.c_str(),"unit",MINIMUM);
534 
535  CPPUNIT_ASSERT(metricDouble.isValueSet() == false);
536  CPPUNIT_ASSERT(metricDouble.setValue(15.));
537  CPPUNIT_ASSERT(metricDouble.getValue() == 15.);
538  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
539  CPPUNIT_ASSERT(metricDouble.setValue(-15.));
540  CPPUNIT_ASSERT(metricDouble.getValue() == -15.);
541  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
542 
543  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",MINIMUM);
544 
545  CPPUNIT_ASSERT(metricInt32.isValueSet() == false);
546  CPPUNIT_ASSERT(metricInt32.setValue(-1));
547  CPPUNIT_ASSERT(metricInt32.getValue() == -1);
548  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
549  CPPUNIT_ASSERT(metricInt32.setValue(15));
550  CPPUNIT_ASSERT(metricInt32.getValue() == -1);
551  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
552 
553 }
554 
555 /**
556  * A test method to test that NdmcMetric::_calculateSendValue
557  * works correctly for a metric of type MINIMUM.
558  */
560 
561  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCalculateSendValueMetricTypeMINIMUM."
562  << std::endl;
563 
564  std::string name="dummy";
565  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",MINIMUM);
566  CPPUNIT_ASSERT(metricUInt32.setValue(10));
567  CPPUNIT_ASSERT(metricUInt32.setValue(10));
568  uint32_t sendValueUInt32 = 0;
569  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32) == true);
570  CPPUNIT_ASSERT(sendValueUInt32 == 10);
571 
572 
573  NdmcMetric<double> metricDouble(name.c_str(),"unit",MINIMUM);
574  CPPUNIT_ASSERT(metricDouble.setValue(15.));
575  CPPUNIT_ASSERT(metricDouble.setValue(-15));
576  double sendValueDouble = 0;
577  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble) == true);
578  CPPUNIT_ASSERT(sendValueDouble == -15.);
579 
580  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",MINIMUM);
581  CPPUNIT_ASSERT(metricInt32.setValue(-1));
582  CPPUNIT_ASSERT(metricInt32.setValue(15));
583  int32_t sendValueInt32 = 0;
584  CPPUNIT_ASSERT(metricInt32._calculateSendValue(sendValueInt32) == true);
585  CPPUNIT_ASSERT(sendValueInt32 == -1);
586 
587 }
588 
589 /**
590  * A test method to test that NdmcMetric::setValue
591  * works correctly for a metric of type MAXIMUM.
592  */
594 
595  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetValueMetricTypeMAXIMUM." << std::endl;
596 
597  std::string name="dummy";
598  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",MAXIMUM);
599  CPPUNIT_ASSERT(metricUInt32.isValueSet() == false);
600 
601  CPPUNIT_ASSERT(metricUInt32.setValue(10));
602  CPPUNIT_ASSERT(metricUInt32.getValue() == 10);
603  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
604  CPPUNIT_ASSERT(metricUInt32.setValue(10));
605  CPPUNIT_ASSERT(metricUInt32.getValue() == 10);
606  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
607 
608 
609  NdmcMetric<double> metricDouble(name.c_str(),"unit",MAXIMUM);
610 
611  CPPUNIT_ASSERT(metricDouble.isValueSet() == false);
612  CPPUNIT_ASSERT(metricDouble.setValue(15.));
613  CPPUNIT_ASSERT(metricDouble.getValue() == 15.);
614  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
615  CPPUNIT_ASSERT(metricDouble.setValue(-15.));
616  CPPUNIT_ASSERT(metricDouble.getValue() == 15.);
617  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
618 
619  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",MAXIMUM);
620 
621  CPPUNIT_ASSERT(metricInt32.isValueSet() == false);
622  CPPUNIT_ASSERT(metricInt32.setValue(-1));
623  CPPUNIT_ASSERT(metricInt32.getValue() == -1);
624  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
625  CPPUNIT_ASSERT(metricInt32.setValue(15));
626  CPPUNIT_ASSERT(metricInt32.getValue() == 15);
627  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
628 
629 }
630 
631 /**
632  * A test method to test that NdmcMetric::_calculateSendValue
633  * works correctly for a metric of type MAXIMUM.
634  */
636 
637  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCalculateSendValueMetricTypeMAXIMUM."
638  << std::endl;
639 
640  std::string name="dummy";
641  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",MAXIMUM);
642  CPPUNIT_ASSERT(metricUInt32.setValue(10));
643  CPPUNIT_ASSERT(metricUInt32.setValue(10));
644  uint32_t sendValueUInt32 = 0;
645  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32) == true);
646  CPPUNIT_ASSERT(sendValueUInt32 == 10);
647 
648 
649  NdmcMetric<double> metricDouble(name.c_str(),"unit",MAXIMUM);
650  CPPUNIT_ASSERT(metricDouble.setValue(15.));
651  CPPUNIT_ASSERT(metricDouble.setValue(-15));
652  double sendValueDouble = 0;
653  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble) == true);
654  CPPUNIT_ASSERT(sendValueDouble == 15.);
655 
656  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",MAXIMUM);
657  CPPUNIT_ASSERT(metricInt32.setValue(-1));
658  CPPUNIT_ASSERT(metricInt32.setValue(15));
659  int32_t sendValueInt32 = 0;
660  CPPUNIT_ASSERT(metricInt32._calculateSendValue(sendValueInt32) == true);
661  CPPUNIT_ASSERT(sendValueInt32 == 15);
662 
663 }
664 
665 /**
666  * A test method to test that NdmcMetric::setValue
667  * works correctly for a metric of type STDEV.
668  */
670 
671  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetValueMetricTypeSTDEV." << std::endl;
672 
673  std::string name="dummy";
674  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",STDEV);
675  CPPUNIT_ASSERT(metricUInt32.isValueSet() == false);
676 
677  CPPUNIT_ASSERT(metricUInt32.setValue(10));
678  CPPUNIT_ASSERT(metricUInt32.getSumWX() == 10);
679  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
680  CPPUNIT_ASSERT(metricUInt32.setValue(10,2.));
681  CPPUNIT_ASSERT(metricUInt32.getSumWX() == 30);
682  CPPUNIT_ASSERT(metricUInt32.isValueSet() == true);
683 
684 
685  NdmcMetric<double> metricDouble(name.c_str(),"unit",STDEV);
686 
687  CPPUNIT_ASSERT(metricDouble.isValueSet() == false);
688  CPPUNIT_ASSERT(metricDouble.setValue(15.));
689  CPPUNIT_ASSERT(metricDouble.getSumWX() == 15.);
690  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
691  CPPUNIT_ASSERT(metricDouble.setValue(-15.,2.));
692  CPPUNIT_ASSERT(metricDouble.getSumWX() == -15.);
693  CPPUNIT_ASSERT(metricDouble.isValueSet() == true);
694 
695  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",STDEV);
696 
697  CPPUNIT_ASSERT(metricInt32.isValueSet() == false);
698  CPPUNIT_ASSERT(metricInt32.setValue(-1));
699  CPPUNIT_ASSERT(metricInt32.getSumWX() == -1);
700  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
701  CPPUNIT_ASSERT(metricInt32.setValue(15,2));
702  CPPUNIT_ASSERT(metricInt32.getSumWX() == 29);
703  CPPUNIT_ASSERT(metricInt32.isValueSet() == true);
704 
705 }
706 
707 /**
708  * A test method to test that NdmcMetric::_calculateSendValue
709  * works correctly for a metric of type STDEV.
710  */
712 
713  ::mf::LogInfo("unittest") << "NdmcMetricTest::testCalculateSendValueMetricTypeSTDEV."
714  << std::endl;
715 
716  std::string name="dummy";
717  NdmcMetric<uint32_t> metricUInt32(name.c_str(),"unit",STDEV);
718  CPPUNIT_ASSERT(metricUInt32.setValue(10));
719  CPPUNIT_ASSERT(metricUInt32.setValue(10,2.));
720  uint32_t sendValueUInt32 = 0;
721  CPPUNIT_ASSERT(metricUInt32._calculateSendValue(sendValueUInt32) == true);
722  CPPUNIT_ASSERT(sendValueUInt32 == 0);
723 
724 
725  NdmcMetric<double> metricDouble(name.c_str(),"unit",STDEV);
726  CPPUNIT_ASSERT(metricDouble.setValue(15.));
727  CPPUNIT_ASSERT(metricDouble.setValue(-15.));
728  double sendValueDouble = 0;
729  CPPUNIT_ASSERT(metricDouble._calculateSendValue(sendValueDouble) == true);
730  CPPUNIT_ASSERT(int(sendValueDouble*1000) == 21213);
731 
732  NdmcMetric<int32_t> metricInt32(name.c_str(),"unit",STDEV);
733  CPPUNIT_ASSERT(metricInt32.setValue(-1));
734  CPPUNIT_ASSERT(metricInt32.setValue(15));
735  CPPUNIT_ASSERT(metricInt32.setValue(15));
736  int32_t sendValueInt32 = 0;
737  CPPUNIT_ASSERT(metricInt32._calculateSendValue(sendValueInt32) == true);
738  CPPUNIT_ASSERT(sendValueInt32 == 9);
739 
740 }
741 
742 /**
743  * A test method to test that NdmcMetric::getLastValueSent method works correctly.
744  */
746 
747  ::mf::LogInfo("unittest") << "NdmcMetricTest::testGetLastValueSent." << std::endl;
748  NdmcMetric<uint32_t> metric("dummy","unit",RATE);
749  uint32_t lastValueSent=0;
750  CPPUNIT_ASSERT(metric.getLastValueSent(lastValueSent) == false);
751  CPPUNIT_ASSERT(metric.setValue(10));
752  uint32_t sendValue = 0;
753  CPPUNIT_ASSERT(metric._calculateSendValue(sendValue,9.) == true);
754  CPPUNIT_ASSERT(sendValue == 1);
755  metric._lastValueSent = sendValue;
756  metric._valueHasBeenSent = true;
757  CPPUNIT_ASSERT(metric.getLastValueSent(lastValueSent) == true);
758  CPPUNIT_ASSERT(lastValueSent == sendValue);
759 
760  CPPUNIT_ASSERT(metric._calculateSendValue(sendValue,15.) == true);
761  CPPUNIT_ASSERT(sendValue== 0);
762  metric._lastValueSent = sendValue;
763  CPPUNIT_ASSERT(metric.getLastValueSent(lastValueSent) == true);
764  CPPUNIT_ASSERT(lastValueSent == sendValue);
765 
766 }
767 
768 /**
769  * A test method to test that NdmcMetric::setPartition works correctly.
770  */
772 
773  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetPartition."
774  << std::endl;
775 
776  std::string name="dummy";
777  NdmcMetric<uint32_t> metric(name.c_str(),"unit",STDEV);
778 
779  int32_t partition = 0;
780  metric.setPartition(partition);
781  CPPUNIT_ASSERT(metric.getPartition() == partition);
782  CPPUNIT_ASSERT(metric.getApplicationName() == "");
783  CPPUNIT_ASSERT(metric.getGroupName() == "");
784  CPPUNIT_ASSERT(metric.getMetricName() == "dummy_P0");
785 
786 }
787 
788 /**
789  * A test method to test that NdmcMetric::setApplicationName works correctly.
790  */
792 
793  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetApplicationName."
794  << std::endl;
795 
796  std::string name="dummy";
797  NdmcMetric<uint32_t> metric(name.c_str(),"unit",STDEV);
798 
799  std::string appName = "MyApp";
800  metric.setApplicationName(appName);
801  CPPUNIT_ASSERT(metric.getApplicationName() == "myapp"); // converts to lowercase
802  CPPUNIT_ASSERT(metric.getMetricName() == "dummy_Amyapp");
803  CPPUNIT_ASSERT(metric.getPartition() == -1);
804  CPPUNIT_ASSERT(metric.getGroupName() == "");
805 
806  int32_t partition = 0;
807  metric.setPartition(partition);
808  CPPUNIT_ASSERT(metric.getApplicationName() == "myapp");
809  CPPUNIT_ASSERT(metric.getPartition() == partition);
810  CPPUNIT_ASSERT(metric.getGroupName() == "");
811  CPPUNIT_ASSERT(metric.getMetricName() == "dummy_Amyapp_P0");
812 
813 }
814 
815 /**
816  * A test method to test that NdmcMetric::setGroupName works correctly.
817  */
819 
820  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetGroupName."
821  << std::endl;
822 
823  std::string name="dummy";
824  NdmcMetric<uint32_t> metric(name.c_str(),"unit",STDEV);
825 
826  std::string groupName = "MyGroup";
827  metric.setGroupName(groupName);
828  CPPUNIT_ASSERT(metric.getApplicationName() == "");
829  CPPUNIT_ASSERT(metric.getMetricName() == "dummy");
830  CPPUNIT_ASSERT(metric.getPartition() == -1);
831  CPPUNIT_ASSERT(metric.getGroupName() == groupName);
832 
833 }
834 
835 /**
836  * A test method to test that NdmcMetric::setTitle works correctly.
837  */
839 
840  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetTitle."
841  << std::endl;
842 
843  std::string name="dummy";
844  NdmcMetric<uint32_t> metric(name.c_str(),"unit",STDEV);
845  CPPUNIT_ASSERT(metric.getTitle() == "");
846 
847  std::string title = "MyTitle";
848  metric.setTitle(title);
849  CPPUNIT_ASSERT(metric.getTitle() == title);
850 
851 }
852 
853 /**
854  * A test method to test that NdmcMetric::setDescription works correctly.
855  */
857 
858  ::mf::LogInfo("unittest") << "NdmcMetricTest::testSetDescription."
859  << std::endl;
860 
861  std::string name="dummy";
862  NdmcMetric<uint32_t> metric(name.c_str(),"unit",STDEV);
863  CPPUNIT_ASSERT(metric.getDescription() == "");
864 
865  std::string description = "MyDescription";
866  metric.setDescription(description);
867  CPPUNIT_ASSERT(metric.getDescription() == description);
868 
869 }
870 
871 
872 
CPPUNIT_REGISTRY_ADD_TO_DEFAULT("NovaDAQMonitorClient")
void testCalculateSendValueMetricTypeCOUNTER()
const XML_Char * name
Definition: expat.h:151
void testGetTypeUint16_t()
void testCalculateSendValueMetricTypeRATE()
void testCalculateSendValueMetricTypeSTDEV()
void testSetValueMetricTypeMINIMUM()
void testGetLastValueSent()
Definition: Ndmc.h:39
Definition: Ndmc.h:37
void testSetValueMetricTypeCOUNTER()
void testCalculateSendValueMetricTypeMAXIMUM()
void testCalculateSendValueMetricTypeMINIMUM()
void testSetValueMetricTypeVALUE()
void testCalculateSendValueMetricTypeVALUE()
static void setCONFIGFILE(std::string configfile)
Definition: Ndmc.h:38
T _lastValueSent
Definition: NdmcMetric.h:103
Definition: Ndmc.h:36
NDMC_NAMESPACE_BEGIN std::string getConfigFullFilePathName(std::string configFile)
void testSetValueMetricTypeSTDEV()
void testSetApplicationName()
bool setValue(T value, double weight=1., int npar=0, double *par=0)
Definition: NdmcMetric.h:326
void testSetValueMetricTypeMAXIMUM()
bool _valueHasBeenSent
Definition: NdmcMetric.h:104
void testGetTypeUint32_t()
Definition: Ndmc.h:40
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Definition: Ndmc.h:41
bool _calculateSendValue(T &sendValue, double timeSinceLastSend=0)
Definition: NdmcMetric.h:453
void testSetValueMetricTypeAVERAGE()
void testCalculateSendValueMetricTypeAVERAGE()
CPPUNIT_TEST_SUITE_NAMED_REGISTRATION(NdmcMetricTest,"NovaDAQMonitorClient")
Definition: Ndmc.h:35
bool getLastValueSent(T &lastValueSent) const
Definition: NdmcMetric.h:197
void testSetValueMetricTypeRATE()