CatalogueTest.cpp 6.13 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/******************************************************************************
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program 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 General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * 
 *
21
 * @author Castor Dev team, castor-dev@cern.ch
22
23
 *****************************************************************************/

24
#include "castor/log/DummyLogger.hpp"
25
#include "castor/tape/tapeserver/daemon/Catalogue.hpp"
26
#include "castor/tape/tapeserver/daemon/ProcessForkerProxyDummy.hpp"
27
#include "castor/tape/tapeserver/system/Wrapper.hpp"
28
29
30
31
32
33
#include "castor/utils/utils.hpp"

#include <gtest/gtest.h>

namespace unitTests {

34
class castor_tape_tapeserver_daemon_CatalogueTest : public ::testing::Test {
35
36
37
38
39
40
41
42
43
protected:

  virtual void SetUp() {
  }

  virtual void TearDown() {
  }
};

44
TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, goodDayPopulate) {
45
46
  using namespace castor::tape::tapeserver::daemon;

47
48
  TpconfigLines lines;
  lines.push_back(TpconfigLine(
49
    "UNIT1", "DGN1", "DEV1", "manual@SLOT1"));
50
  lines.push_back(TpconfigLine(
51
    "UNIT2", "DGN2", "DEV2", "manual@SLOT2"));
52

53
  DriveConfigMap driveConfigs;
54
  ASSERT_NO_THROW(driveConfigs.enterTpconfigLines(lines));
55

56
57
58
  castor::log::DummyLogger log("unittest");
  ProcessForkerProxyDummy processForker;
  const std::string hostName = "";
59
  const CatalogueConfig catalogueConfig;
60
  const int netTimeout = 1;
61
  castor::tape::System::mockWrapper sysWrapper;
62
  Catalogue catalogue(netTimeout, log, processForker,
63
    hostName, catalogueConfig, sysWrapper);
64
  ASSERT_NO_THROW(catalogue.populate(driveConfigs));
Daniele Kruse's avatar
Daniele Kruse committed
65
  
66
67
68
69
70
71
72
73
  {
    std::list<std::string> fromCatalogue;
    ASSERT_NO_THROW(fromCatalogue = catalogue.getUnitNames());
    ASSERT_EQ((std::list<std::string>::size_type)2, fromCatalogue.size());
    ASSERT_EQ(std::string("UNIT1"), fromCatalogue.front());
    fromCatalogue.pop_front();
    ASSERT_EQ(std::string("UNIT2"), fromCatalogue.front());
  }
Daniele Kruse's avatar
Daniele Kruse committed
74
  
75
76
77
78
  ///////////////////
  // UNIT1 assertions
  ///////////////////

79
  const CatalogueDrive &unit1 = catalogue.findDrive("UNIT1");
80
  const DriveConfig &unit1Config = unit1.getConfig();
Daniele Kruse's avatar
Daniele Kruse committed
81
  
82
  ASSERT_EQ(std::string("DGN1"), unit1Config.getLogicalLibrary());
83
  ASSERT_EQ(std::string("DEV1"), unit1Config.getDevFilename());
Daniele Kruse's avatar
Daniele Kruse committed
84
  
85
  ASSERT_EQ(DRIVE_STATE_DOWN, unit1.getState());
86
  ASSERT_NO_THROW(unit1Config.getLibrarySlot());
87
  ASSERT_EQ(castor::mediachanger::TAPE_LIBRARY_TYPE_MANUAL,
88
89
    unit1Config.getLibrarySlot().getLibraryType());
  ASSERT_EQ(std::string("manual@SLOT1"), unit1Config.getLibrarySlot().str());
Daniele Kruse's avatar
Daniele Kruse committed
90
  
91
92
93
  ///////////////////
  // UNIT2 assertions
  ///////////////////
Daniele Kruse's avatar
Daniele Kruse committed
94
  
95
  const CatalogueDrive &unit2 = catalogue.findDrive("UNIT2");
96
  const DriveConfig &unit2Config = unit2.getConfig();
Daniele Kruse's avatar
Daniele Kruse committed
97
  
98
  ASSERT_EQ(std::string("DGN2"), unit2Config.getLogicalLibrary());
99
  ASSERT_EQ(std::string("DEV2"), unit2Config.getDevFilename());
100

101
  ASSERT_EQ(DRIVE_STATE_DOWN, unit2.getState());
102
  ASSERT_NO_THROW(unit2Config.getLibrarySlot());
103
  ASSERT_EQ(castor::mediachanger::TAPE_LIBRARY_TYPE_MANUAL,
104
105
    unit2Config.getLibrarySlot().getLibraryType());
  ASSERT_EQ(std::string("manual@SLOT2"), unit2Config.getLibrarySlot().str());
106
107
108
109
110
}

TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, duplicateUnitName) {
  using namespace castor::tape::tapeserver::daemon;

111
112
  TpconfigLines lines;
  lines.push_back(TpconfigLine(
113
    "UNIT1", "DGN1", "DEV1", "manual@SLOT1"));
114
  lines.push_back(TpconfigLine(
115
116
    "UNIT1", "DGN2", "DEV2", "manual@SLOT2"));

117
  DriveConfigMap driveConfigs;
118
119
  ASSERT_THROW(driveConfigs.enterTpconfigLines(lines),
    castor::exception::Exception);
120
121
}

122
TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, 
123
124
125
126
  getStateOfNonExistingDrive) {
  using namespace castor::tape::tapeserver::daemon;

  const std::string unitName = "DRIVE";
127
  const int netTimeout = 1;
128
129
130
  castor::log::DummyLogger log("unittest");
  ProcessForkerProxyDummy processForker;
  const std::string hostName = "";
131
  const CatalogueConfig catalogueConfig;
132
  castor::tape::System::mockWrapper sysWrapper;
133
  Catalogue catalogue(netTimeout, log, processForker,
134
    hostName, catalogueConfig, sysWrapper);
135
  ASSERT_THROW(catalogue.findDrive(unitName), castor::exception::Exception);
136
137
}

138
TEST_F(castor_tape_tapeserver_daemon_CatalogueTest, getUnitNames) {
139
  using namespace castor::tape::tapeserver::daemon;
140
141
  TpconfigLines lines;
  lines.push_back(TpconfigLine(
142
    "UNIT1", "DGN1", "DEV1", "manual@SLOT1"));
143
  lines.push_back(TpconfigLine(
144
    "UNIT2", "DGN2", "DEV2", "manual@SLOT2"));
145
  DriveConfigMap driveConfigs;
146
  ASSERT_NO_THROW(driveConfigs.enterTpconfigLines(lines));
147

148
  const int netTimeout = 1;
149
150
151
  castor::log::DummyLogger log("unittest");
  ProcessForkerProxyDummy processForker;
  const std::string hostName = "";
152
  const CatalogueConfig catalogueConfig;
153
  castor::tape::System::mockWrapper sysWrapper;
154
  Catalogue catalogue(netTimeout, log, processForker,
155
    hostName, catalogueConfig, sysWrapper);
156
  ASSERT_NO_THROW(catalogue.populate(driveConfigs));
157
158
159
160
161
162
163
164

  {
    std::list<std::string> allUnitNames;
    ASSERT_NO_THROW(allUnitNames = catalogue.getUnitNames());
    ASSERT_EQ((std::list<std::string>::size_type)2, allUnitNames.size());
    const std::string firstOfAllUnitNames = allUnitNames.front();
    allUnitNames.pop_front();
    const std::string secondOfAllUnitNames = allUnitNames.front();
Steven Murray's avatar
Steven Murray committed
165
166
167
168
    ASSERT_TRUE(firstOfAllUnitNames == "UNIT1" ||
      firstOfAllUnitNames == "UNIT2");
    ASSERT_TRUE(secondOfAllUnitNames == "UNIT1" ||
      secondOfAllUnitNames == "UNIT2");
169
170
171
    ASSERT_TRUE(firstOfAllUnitNames != secondOfAllUnitNames);
  }
}
172
} // namespace unitTests