File: TestEnv.cc

package info (click to toggle)
xrootd 5.9.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 25,956 kB
  • sloc: cpp: 244,425; sh: 2,691; python: 1,980; ansic: 1,027; perl: 814; makefile: 272
file content (125 lines) | stat: -rw-r--r-- 4,787 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
//------------------------------------------------------------------------------
// Copyright (c) 2011-2012 by European Organization for Nuclear Research (CERN)
// Author: Lukasz Janyst <ljanyst@cern.ch>
//------------------------------------------------------------------------------
// XRootD is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// XRootD is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with XRootD.  If not, see <http://www.gnu.org/licenses/>.
//------------------------------------------------------------------------------

#include "TestEnv.hh"
#include "XrdCl/XrdClOptimizers.hh"

namespace XrdClTests {

XrdSysMutex     TestEnv::sEnvMutex;
XrdCl::Env *TestEnv::sEnv       = 0;
XrdCl::Log *TestEnv::sLog       = 0;

//------------------------------------------------------------------------------
// Constructor
//------------------------------------------------------------------------------
TestEnv::TestEnv()
{
  PutString( "MainServerURL",    "localhost:10940" );
  PutString( "Manager1URL",      "localhost:10941" );
  PutString( "Manager2URL",      "localhost:10942" );
  PutString( "Server1URL",       "localhost:10943" );
  PutString( "Server2URL",       "localhost:10944" );
  PutString( "Server3URL",       "localhost:10945" );
  PutString( "Server4URL",       "localhost:10946" );
  PutString( "DiskServerURL",    "localhost:10940" );
  PutString( "DataPath",         "/data"         );
  PutString( "RemoteFile",       "/data/cb4aacf1-6f28-42f2-b68a-90a73460f424.dat" );
  PutString( "LocalFile",        "/data/testFile.dat" );
  PutString( "MultiIPServerURL", "multiip:1099" );
  PutString( "LocalDataPath",    "../cluster/data" );
  ImportString( "MainServerURL",    "XRDTEST_MAINSERVERURL" );
  ImportString( "DiskServerURL",    "XRDTEST_DISKSERVERURL" );
  ImportString( "Manager1URL",      "XRDTEST_MANAGER1URL" );
  ImportString( "Manager2URL",      "XRDTEST_MANAGER2URL" );
  ImportString( "Server1URL",       "XRDTEST_SERVER1URL" );
  ImportString( "Server2URL",       "XRDTEST_SERVER2URL" );
  ImportString( "Server3URL",       "XRDTEST_SERVER3URL" );
  ImportString( "Server4URL",       "XRDTEST_SERVER4URL" );
  ImportString( "DataPath",         "XRDTEST_DATAPATH" );
  ImportString( "LocalFile",        "XRDTEST_LOCALFILE" );
  ImportString( "RemoteFile",       "XRDTEST_REMOTEFILE" );
  ImportString( "MultiIPServerURL", "XRDTEST_MULTIIPSERVERURL" );
}

//------------------------------------------------------------------------------
// Get default client environment
//------------------------------------------------------------------------------
XrdCl::Env *TestEnv::GetEnv()
{
  if( !sEnv )
  {
    XrdSysMutexHelper scopedLock( sEnvMutex );
    if( sEnv )
      return sEnv;
    sEnv = new TestEnv();
  }
  return sEnv;
}

XrdCl::Log *TestEnv::GetLog()
{
  //----------------------------------------------------------------------------
  // This is actually thread safe because it is first called from
  // a static initializer in a thread safe context
  //----------------------------------------------------------------------------
  if( unlikely( !sLog ) )
    sLog = new XrdCl::Log();
  return sLog;
}

//------------------------------------------------------------------------------
// Release the environment
//------------------------------------------------------------------------------
void TestEnv::Release()
{
  delete sEnv;
  sEnv = 0;
//  delete sLog;
//  sLog = 0;
}
}

//------------------------------------------------------------------------------
// Finalizer
//------------------------------------------------------------------------------
namespace
{
  static struct EnvInitializer
  {
    //--------------------------------------------------------------------------
    // Initializer
    //--------------------------------------------------------------------------
    EnvInitializer()
    {
      using namespace XrdCl;
      Log *log = XrdClTests::TestEnv::GetLog();
      char *level = getenv( "XRDTEST_LOGLEVEL" );
      if( level )
        log->SetLevel( level );
    }

    //--------------------------------------------------------------------------
    // Finalizer
    //--------------------------------------------------------------------------
    ~EnvInitializer()
    {
      XrdClTests::TestEnv::Release();
    }
  } initializer;
}