1 // SALOME TestContainer : test of container creation and its life cycle
3 // Copyright (C) 2003 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
4 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU Lesser General Public
8 // License as published by the Free Software Foundation; either
9 // version 2.1 of the License.
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // Lesser General Public License for more details.
16 // You should have received a copy of the GNU Lesser General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 // See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
24 // File : TestContainer.cxx
25 // Author : Paul RASCLE, EDF - MARC TAJCHMAN, CEA
29 #include "utilities.h"
32 #include <SALOMEconfig.h>
33 #include "SALOME_NamingService.hxx"
34 #include "SALOME_ContainerManager.hxx"
35 #include "SALOME_LifeCycleCORBA.hxx"
36 #include "NamingService_WaitForServerReadiness.hxx"
38 #include "Utils_ORB_INIT.hxx"
39 #include "Utils_SINGLETON.hxx"
40 #include "Utils_SALOME_Exception.hxx"
41 #include "Utils_CommException.hxx"
44 int main (int argc, char * argv[])
46 map<string, int> cycle;
47 map<string, int> first;
48 Engines::Container_ptr cont;
49 Engines::Component_ptr compo;
53 // Initializing omniORB
54 ORB_INIT &init = *SINGLETON_<ORB_INIT>::Instance() ;
55 CORBA::ORB_ptr orb = init( argc , argv ) ;
57 SALOME_NamingService *_NS=new SALOME_NamingService(orb);
59 CORBA::Object_var obj = _NS->Resolve(SALOME_ContainerManager::_ContainerManagerNameInNS);
60 ASSERT( !CORBA::is_nil(obj));
61 Engines::ContainerManager_var _ContManager=Engines::ContainerManager::_narrow(obj);
63 Engines::MachineParameters p;
69 p.nb_proc_per_node = 1;
74 for(int i=0;i<10;i++){
75 sprintf(st,"cycl_%d",i);
76 p.container_name = CORBA::string_dup(st);
77 cont = _ContManager->StartContainer(p,Engines::P_CYCL);
78 if(CORBA::is_nil(cont)) error = true;
81 for(int i=0;i<10;i++){
82 sprintf(st,"first_%d",i);
83 p.container_name = CORBA::string_dup(st);
84 cont = _ContManager->StartContainer(p,Engines::P_FIRST);
85 if(CORBA::is_nil(cont)) error = true;
88 p.container_name = CORBA::string_dup("best");
89 cont = _ContManager->StartContainer(p,Engines::P_BEST);
90 if(CORBA::is_nil(cont)) bestImplemented = false;
91 else bestImplemented = true;
93 SALOME_LifeCycleCORBA LCC(_NS);
94 compo = LCC.FindOrLoad_Component("FactoryServer","GEOM");
95 if(CORBA::is_nil(compo)) error = true;
96 compo = LCC.FindOrLoad_Component("FactoryServer","GEOM");
97 if(CORBA::is_nil(compo)) error = true;
99 _NS->Change_Directory("/Containers");
101 vector<string> vec = _NS->list_directory_recurs();
102 list<string> lstCont;
103 for(vector<string>::iterator iter = vec.begin();iter!=vec.end();iter++){
104 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
105 Engines::Container_var cont=Engines::Container::_narrow(obj);
106 if(!CORBA::is_nil(cont)){
107 cycle[cont->getHostName()]=0;
108 first[cont->getHostName()]=0;
109 lstCont.push_back((*iter));
112 for(list<string>::iterator iter=lstCont.begin();iter!=lstCont.end();iter++){
113 CORBA::Object_var obj=_NS->Resolve((*iter).c_str());
114 Engines::Container_var cont=Engines::Container::_narrow(obj);
115 if(!CORBA::is_nil(cont)){
116 if(strncmp(basename(cont->name()),"cycl",4)==0)
117 cycle[cont->getHostName()]++;
118 if(strncmp(basename(cont->name()),"first",5)==0)
119 first[cont->getHostName()]++;
122 _ContManager->ShutdownContainers();
128 for(map<string,int>::iterator iter=cycle.begin();iter!=cycle.end();iter++){
129 if(strcmp((*iter).first.c_str(),"localhost")!=0){
130 if(cycle[(*iter).first]<cmin) cmin=cycle[(*iter).first];
131 if(cycle[(*iter).first]>cmax) cmax=cycle[(*iter).first];
132 if(first[(*iter).first]<fmin) fmin=first[(*iter).first];
133 if(first[(*iter).first]>fmax) fmax=first[(*iter).first];
136 if( ((cmax-cmin) <= 1) && (fmax == 10) && !error ){
141 msg = "TEST OK but FindBest not implemented!";