2 #include "LifeCycleCORBATest.hxx"
3 #include "SALOME_LifeCycleCORBA.hxx"
4 #include "Utils_ORB_INIT.hxx"
5 #include "Utils_SINGLETON.hxx"
15 // --- uncomment to have some traces on standard error
16 // (useful only when adding new tests...)
20 #define MYDEVTRACE {std::cerr << __FILE__ << " [" << __LINE__ << "] : ";}
21 #define DEVTRACE(msg) {MYDEVTRACE; std::cerr<<msg<<std::endl<<std::flush;}
27 #define TRACEFILE "/tmp/traceUnitTest.log"
29 // ============================================================================
32 * - delete preexisting trace classes if any
34 * Get or initialize the orb
35 * Create a SALOME_NamingService instance
37 // ============================================================================
40 LifeCycleCORBATest::setUp()
42 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
44 bp1->deleteInstance(bp1);
47 char *theFileName = TRACEFILE;
53 CPPUNIT_ASSERT(! setenv("SALOME_trace",s.c_str(),1)); // 1: overwrite
56 // traceFile.open(theFileName, ios::out | ios::trunc);
57 traceFile.open(theFileName, ios::out | ios::app);
58 CPPUNIT_ASSERT(traceFile); // file created empty, then closed
61 bp1 = LocalTraceBufferPool::instance();
64 // --- Get or initialize the orb
68 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
69 ASSERT(SINGLETON_<ORB_INIT>::IsAlreadyExisting());
70 _orb = init(_argc , _argv ) ;
72 // --- Create a SALOME_NamingService instance
77 // ============================================================================
79 * - delete trace classes
81 // ============================================================================
84 LifeCycleCORBATest::tearDown()
87 LocalTraceBufferPool* bp1 = LocalTraceBufferPool::instance();
89 bp1->deleteInstance(bp1);
92 // ============================================================================
94 * Check FindOrLoad_Component.
95 * - get a local container (no hostname given),
96 * load an engine, check that the CORBA object is not null.
99 // ============================================================================
102 LifeCycleCORBATest::testFindOrLoad_Component_LaunchContainer()
104 SALOME_LifeCycleCORBA _LCC(&_NS);
106 // --- get a local container,
107 // load an engine, check that the CORBA object is not null
109 string containerName = "myContainer";
110 Engines::Component_var mycompo =
111 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
112 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
116 Engines::TestComponent_var m1;
117 m1 = Engines::TestComponent::_narrow(mycompo);
118 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
121 // ============================================================================
123 * Check FindOrLoad_Component.
124 * - Call 2 times FindOrLoad_Component with the same parameters
125 * - check if we get the same engine
127 // ============================================================================
130 LifeCycleCORBATest::testFindOrLoad_Component_SameInstance()
132 SALOME_LifeCycleCORBA _LCC(&_NS);
134 // --- get a local container,
135 // load an engine, check that the CORBA object is not null
137 string containerName = "myContainer";
139 Engines::Component_var mycompo1 =
140 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
141 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
143 Engines::Component_var mycompo2 =
144 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
145 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2));
149 Engines::TestComponent_var m1;
150 m1 = Engines::TestComponent::_narrow(mycompo1);
151 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
153 Engines::TestComponent_var m2;
154 m2 = Engines::TestComponent::_narrow(mycompo2);
155 CPPUNIT_ASSERT(!CORBA::is_nil(m2));
157 // --- check equality of instance names
159 string name1 = m1->instanceName();
160 string name2 = m2->instanceName();
161 CPPUNIT_ASSERT_EQUAL(name1, name2);
164 // ============================================================================
166 * Check FindOrLoad_Component with Python Component on C++ Container
167 * load an engine, check that the CORBA object is not null.
170 // ============================================================================
173 LifeCycleCORBATest::testFindOrLoad_Component_PythonInCppContainer()
175 SALOME_LifeCycleCORBA _LCC(&_NS);
177 // --- get a local container,
178 // load an engine, check that the CORBA object is not null
180 string containerName = "myContainer";
182 Engines::Component_var mycompo1 =
183 _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy");
184 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
188 Engines::TestComponent_var m1;
189 m1 = Engines::TestComponent::_narrow(mycompo1);
190 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
193 // ============================================================================
195 * Check FindOrLoad_Component with Python Component on C++ Container
196 * - Call 2 times FindOrLoad_Component with the same parameters
197 * - check if we get the same engine
199 // ============================================================================
202 LifeCycleCORBATest::testFindOrLoad_Component_PythonSameInstance()
204 SALOME_LifeCycleCORBA _LCC(&_NS);
206 // --- get a local container (with a name based on local hostname),
207 // load an engine, check that the CORBA object is not null
209 string containerName = "myContainer";
211 Engines::Component_var mycompo1 =
212 _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy");
213 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
215 Engines::Component_var mycompo2 =
216 _LCC.FindOrLoad_Component(containerName.c_str(),"SALOME_TestComponentPy");
217 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2));
221 Engines::TestComponent_var m1;
222 m1 = Engines::TestComponent::_narrow(mycompo1);
223 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
225 Engines::TestComponent_var m2;
226 m2 = Engines::TestComponent::_narrow(mycompo2);
227 CPPUNIT_ASSERT(!CORBA::is_nil(m2));
229 // --- check equality of instance names
231 string name1 = m1->instanceName();
232 string name2 = m2->instanceName();
233 CPPUNIT_ASSERT_EQUAL(name1, name2);
236 // ============================================================================
238 * Check FindOrLoad_Component with a component name not in catalog.
239 * See list of catalog given to module catalog server.
240 * Here, we work with KERNEL_SRC/resources/KERNELCatalog.xml that contains
241 * only KERNEL, SalomeTestComponent and SALOME_TestComponentPy
243 // ============================================================================
246 LifeCycleCORBATest::testFindOrLoad_Component_UnknownInCatalog()
248 SALOME_LifeCycleCORBA _LCC(&_NS);
250 // --- get a local container (with a name based on local hostname),
251 // load an engine, check that the CORBA object is not null
253 string containerName = "myContainer";
255 Engines::Component_var mycompo1 =
256 _LCC.FindOrLoad_Component(containerName.c_str(),"MyNewComponent");
257 CPPUNIT_ASSERT(CORBA::is_nil(mycompo1));
260 // ============================================================================
262 * Check FindOrLoad_Component with hostname given
263 * - get a local container : getHostName()/componentName,
264 * load an engine, check that the CORBA object is not null.
267 // ============================================================================
270 LifeCycleCORBATest::testFindOrLoad_Component_LaunchContainerHostname()
272 SALOME_LifeCycleCORBA _LCC(&_NS);
274 // --- get a local container (with a name based on local hostname),
275 // load an engine, check that the CORBA object is not null
277 string containerName = GetHostname();
278 containerName += "/theContainer";
279 DEVTRACE("containerName = " << containerName);
280 Engines::Component_var mycompo =
281 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
282 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
286 Engines::TestComponent_var m1;
287 m1 = Engines::TestComponent::_narrow(mycompo);
288 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
291 // ============================================================================
293 * Check FindOrLoad_Component with and without local hostname given.
294 * We must get the same container, the same instance of component
296 // ============================================================================
299 LifeCycleCORBATest::testFindOrLoad_Component_SameContainer()
301 SALOME_LifeCycleCORBA _LCC(&_NS);
303 // --- get a local container (with a name based on local hostname),
304 // load an engine, check that the CORBA object is not null
306 string containerName = "aContainer";
308 Engines::Component_var mycompo1 =
309 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
310 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo1));
312 containerName = GetHostname();
313 containerName += "/aContainer";
314 DEVTRACE("containerName = " << containerName);
315 Engines::Component_var mycompo2 =
316 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
317 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo2));
321 Engines::TestComponent_var m1;
322 m1 = Engines::TestComponent::_narrow(mycompo1);
323 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
325 Engines::TestComponent_var m2;
326 m2 = Engines::TestComponent::_narrow(mycompo2);
327 CPPUNIT_ASSERT(!CORBA::is_nil(m2));
329 // --- check equality of instance names
331 string name1 = m1->instanceName();
332 string name2 = m2->instanceName();
333 CPPUNIT_ASSERT_EQUAL(name1, name2);
335 // --- check containers are the same servant (same container name+hostname)
337 Engines::Container_var c1 = m1->GetContainerRef();
338 CPPUNIT_ASSERT(!CORBA::is_nil(c1));
339 Engines::Container_var c2 = m2->GetContainerRef();
340 CPPUNIT_ASSERT(!CORBA::is_nil(c1));
341 string cname1 = c1->name();
342 string cname2 = c2->name();
343 CPPUNIT_ASSERT_EQUAL(cname1, cname2);
344 string hostname1 = c1->getHostName();
345 string hostname2 = c2->getHostName();
346 CPPUNIT_ASSERT_EQUAL(hostname1, hostname2);
347 CORBA::Long pidc1 = c1->getPID();
348 CORBA::Long pidc2 = c2->getPID();
349 CPPUNIT_ASSERT_EQUAL(pidc1, pidc2);
352 // ============================================================================
354 * Check FindOrLoad_Component: check behaviour when ask for an unknown computer
355 * We must catch a Salome Exception with "unknown host" message
357 // ============================================================================
360 LifeCycleCORBATest::testFindOrLoad_Component_UnknownMachine()
362 SALOME_LifeCycleCORBA _LCC(&_NS);
364 // --- try to get a distant container on an unknown machine (not existing)
365 // check that the CORBA object is null
367 string containerName = "aFarAwayComputer";
368 containerName += "/theContainer";
369 // CPPUNIT_ASSERT_THROW(Engines::Component_var mycompo =
370 // _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");,SALOME::SALOME_Exception);
373 Engines::Component_var mycompo =
374 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
376 catch(const SALOME::SALOME_Exception &ex)
378 CPPUNIT_ASSERT(true);
379 // string expectedMessage = "BAD PARAM";
382 // string actualMessage = os.str();
383 // DEVTRACE("actual Exception Message = " << actualMessage);
384 // CPPUNIT_ASSERT(actualMessage.find(expectedMessage) != string::npos);
388 // ============================================================================
390 * Check FindOrLoad_Component, empty params must give an instance
392 // ============================================================================
395 LifeCycleCORBATest::testFindOrLoad_Component_ParamsEmpty()
397 SALOME_LifeCycleCORBA _LCC(&_NS);
399 Engines::MachineParameters params;
401 Engines::Component_var mycompo =
402 _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
403 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
407 Engines::TestComponent_var m1;
408 m1 = Engines::TestComponent::_narrow(mycompo);
411 // ============================================================================
413 * Check FindOrLoad_Component params = local container
415 // ============================================================================
418 LifeCycleCORBATest::testFindOrLoad_Component_ParamsLocalContainer()
420 SALOME_LifeCycleCORBA _LCC(&_NS);
422 Engines::MachineParameters params;
424 string hostname=GetHostname();
425 params.hostname=hostname.c_str();
426 Engines::Component_var mycompo =
427 _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
428 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
432 Engines::TestComponent_var m1;
433 m1 = Engines::TestComponent::_narrow(mycompo);
435 // --- check that container is on local computer
437 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
438 Engines::Container_var c1 = m1->GetContainerRef();
439 CPPUNIT_ASSERT(!CORBA::is_nil(c1));
440 string hostname1 = c1->getHostName();
441 CPPUNIT_ASSERT_EQUAL(hostname1, GetHostname());
445 // ============================================================================
447 * Check FindOrLoad_Component params = containerName
449 // ============================================================================
452 LifeCycleCORBATest::testFindOrLoad_Component_ParamsContainerName()
454 SALOME_LifeCycleCORBA _LCC(&_NS);
456 Engines::MachineParameters params;
458 string containerName = "myContainer";
459 params.container_name = containerName.c_str();
460 Engines::Component_var mycompo =
461 _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
462 CPPUNIT_ASSERT(!CORBA::is_nil(mycompo));
466 Engines::TestComponent_var m1;
467 m1 = Engines::TestComponent::_narrow(mycompo);
469 // --- check that container has good name
471 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
472 Engines::Container_var c1 = m1->GetContainerRef();
473 CPPUNIT_ASSERT(!CORBA::is_nil(c1));
474 string hostname1 = c1->getHostName();
475 CPPUNIT_ASSERT_EQUAL(hostname1, GetHostname());
476 string cname1 = c1->name();
477 CPPUNIT_ASSERT(cname1.find(containerName) != string::npos);
480 // ============================================================================
482 * Check FindOrLoad_Component on remote computer
484 // ============================================================================
487 LifeCycleCORBATest::testFindOrLoad_Component_RemoteComputer()
489 SALOME_LifeCycleCORBA _LCC(&_NS);
491 string remoteHost = GetRemoteHost();
493 string containerName = remoteHost;
494 containerName += "/aContainer";
495 DEVTRACE("containerName = " << containerName);
496 Engines::Component_var mycompo1 =
497 _LCC.FindOrLoad_Component(containerName.c_str(),"SalomeTestComponent");
498 CPPUNIT_ASSERT_MESSAGE("Test validity requires connection to remote "\
499 "computers from ResourcesCatalog",
500 !CORBA::is_nil(mycompo1));
504 Engines::TestComponent_var m1;
505 m1 = Engines::TestComponent::_narrow(mycompo1);
507 // --- check that container is on good computer
509 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
510 Engines::Container_var c1 = m1->GetContainerRef();
511 CPPUNIT_ASSERT(!CORBA::is_nil(c1));
512 string hostname1 = c1->getHostName();
513 CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost);
516 // ============================================================================
518 * Check FindOrLoad_Component with params on remote computer
519 * params empty except hostname
521 // ============================================================================
524 LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer()
526 SALOME_LifeCycleCORBA _LCC(&_NS);
528 string remoteHost = GetRemoteHost();
530 Engines::MachineParameters params;
532 params.hostname = remoteHost.c_str();
534 Engines::Component_var mycompo1 =
535 _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
536 CPPUNIT_ASSERT_MESSAGE("Test validity requires connection to remote "\
537 "computers from ResourcesCatalog",
538 !CORBA::is_nil(mycompo1));
542 Engines::TestComponent_var m1;
543 m1 = Engines::TestComponent::_narrow(mycompo1);
545 // --- check that container is on good computer
547 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
548 Engines::Container_var c1 = m1->GetContainerRef();
549 CPPUNIT_ASSERT(!CORBA::is_nil(c1));
550 string hostname1 = c1->getHostName();
551 CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost);
554 // ============================================================================
556 * Check FindOrLoad_Component with params on remote computer
557 * params empty except hostname and container_name
559 // ============================================================================
562 LifeCycleCORBATest::testFindOrLoad_Component_ParamsRemoteComputer2()
564 SALOME_LifeCycleCORBA _LCC(&_NS);
566 string remoteHost = GetRemoteHost();
568 Engines::MachineParameters params;
570 params.hostname = remoteHost.c_str();
571 params.container_name = "anotherContainer";
573 Engines::Component_var mycompo1 =
574 _LCC.FindOrLoad_Component(params,"SalomeTestComponent");
575 CPPUNIT_ASSERT_MESSAGE("Test validity requires connection to remote "\
576 "computers from ResourcesCatalog",
577 !CORBA::is_nil(mycompo1));
581 Engines::TestComponent_var m1;
582 m1 = Engines::TestComponent::_narrow(mycompo1);
584 // --- check that container is on good computer
586 CPPUNIT_ASSERT(!CORBA::is_nil(m1));
587 Engines::Container_var c1 = m1->GetContainerRef();
588 CPPUNIT_ASSERT(!CORBA::is_nil(c1));
589 string hostname1 = c1->getHostName();
590 CPPUNIT_ASSERT_EQUAL(hostname1, remoteHost);
595 // ============================================================================
597 * Check FindOrLoad_Component params = containerName
599 // ============================================================================
602 // LifeCycleCORBATest::testFindOrLoad_Component_()
613 // ============================================================================
615 * Get a remote HostName in the Resource Catalog
617 // ============================================================================
619 string LifeCycleCORBATest::GetRemoteHost()
621 SALOME_LifeCycleCORBA _LCC(&_NS);
623 CORBA::Object_var obj = _NS.Resolve("/ContainerManager");
624 CPPUNIT_ASSERT(!CORBA::is_nil(obj));
625 Engines::ContainerManager_var containerManager =
626 Engines::ContainerManager::_narrow(obj);
627 CPPUNIT_ASSERT(!CORBA::is_nil(containerManager));
629 Engines::MachineParameters params;
630 _LCC.preSet(params); // empty params to get all the machines
632 Engines::MachineList_var hostList =
633 containerManager->GetFittingResources(params,"SalomeTestComponent");
634 CPPUNIT_ASSERT(hostList->length() > 1);
636 string localHost = GetHostname();
638 for (unsigned int i=0; i < hostList->length(); i++)
640 const char* aMachine = hostList[i];
641 string machine(aMachine);
642 if (machine != localHost)
644 remoteHost = machine;
648 CPPUNIT_ASSERT(remoteHost != "");