FakeClient.hpp 4.44 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/****************************************************************************** 
 *
 * 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.
 *
 * 
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/
23

24
#pragma once
25

26
#include "castor/tape/tapeserver/client/ClientInterface.hpp"
27
#include "castor/tape/tapegateway/FilesToRecallList.hpp"
28
29
#include "castor/tape/tapegateway/FileToRecallStruct.hpp"

30
31
#include <memory>
#include <gtest/gtest.h>
32
#include <gmock/gmock.h>
33

34
namespace unitTests{
35
36
37
38
  using namespace castor::tape;
  const int init_value=-1;
  const unsigned int nbFile=5;

39
class FakeClient : public castor::tape::tapeserver::client::ClientInterface
40
41
42
{

public:
43
44
45
  FakeClient(int nbCalls=0):m_current(0)
          /*current_succes_migration(init_value),current_failled_migration(init_value),
          current_succes_recall(0),current_failled_recall(0)*/{
46
47
48
49
50
51
52
53
54
55
56
    for(int n=0;n<nbCalls;++n) {
      std::auto_ptr<tapegateway::FilesToRecallList> ptr(new tapegateway::FilesToRecallList());
      for(unsigned int i=0;i<nbFile;++i)
      {
        ptr->filesToRecall().push_back(new tapegateway::FileToRecallStruct);
        ptr->filesToRecall().back()->setFileid(i);
        ptr->filesToRecall().back()->setBlockId0(1*i);
        ptr->filesToRecall().back()->setBlockId1(2*i);
        ptr->filesToRecall().back()->setBlockId2(3*i);
        ptr->filesToRecall().back()->setBlockId3(4*i);
        ptr->filesToRecall().back()->setFseq(255+i);
57
        ptr->filesToRecall().back()->setPath("/tmp/pipo");
58
59
60
61
62
63
64
65
        ptr->filesToRecall().back()->setFileTransactionId(666+i);
        ptr->filesToRecall().back()->setFilesToRecallList(ptr.get());
    }
    lists.push_back(ptr.release());
    }
    lists.push_back(NULL);
  }
  virtual void reportMigrationResults(tapegateway::FileMigrationReportList & migrationReport,
66
  RequestReport& report) {
67
68
  }
  
David COME's avatar
David COME committed
69
  virtual void reportRecallResults(tapegateway::FileRecallReportList & recallReport,
70
  RequestReport& report) {
David COME's avatar
David COME committed
71
  }
72
  
73
74
75
   tapegateway::FilesToMigrateList *getFilesToMigrate(uint64_t files, uint64_t bytes, RequestReport &report){
     return NULL;
  }
76
77
78
79
80
  //workaround to use assertion inside a function returning something else than void
  //see http://code.google.com/p/googletest/wiki/AdvancedGuide#Assertion_Placement
  void assertion(){ASSERT_EQ(true,static_cast<unsigned int>(m_current)<lists.size());}
  
  virtual tapegateway::FilesToRecallList * getFilesToRecall(uint64_t files,
81
  uint64_t bytes, RequestReport &report)  
82
83
84
85
86
87
88
89
90
91
92
  {
    
    report.transactionId=666;
    report.connectDuration=42;
    report.sendRecvDuration=21;
    assertion();
    return lists[m_current++];
 
  }
  
  virtual void reportEndOfSessionWithError(const std::string & errorMsg, int errorCode, 
93
  RequestReport &transactionReport)  {
David COME's avatar
David COME committed
94
  };
95
 
96
  virtual void reportEndOfSession(RequestReport &report)  {}
97
98
99
100
private:
  std::vector<tapegateway::FilesToRecallList*> lists;
  int m_current;
};
101
102
103
104
105
106
107
108
109
110
111
112
113




    
  class MockClient : public castor::tape::tapeserver::client::ClientInterface {
  public:
    MOCK_METHOD3(getFilesToRecall, tapegateway::FilesToRecallList* (uint64_t files,uint64_t bytes, RequestReport &report));
    MOCK_METHOD2(reportMigrationResults, void (tapegateway::FileMigrationReportList & migrationReport,RequestReport &report));
    
    MOCK_METHOD3(reportEndOfSessionWithError, void(const std::string & errorMsg, int errorCode, RequestReport &transactionReport));
    MOCK_METHOD1(reportEndOfSession, void(RequestReport &transactionReport));
    MOCK_METHOD2(reportRecallResults,void(tapegateway::FileRecallReportList & recallReport,RequestReport &report));
114
    MOCK_METHOD3(getFilesToMigrate,tapegateway::FilesToMigrateList *(uint64_t, uint64_t, RequestReport &));
115
116
  };
  
117
118
119
}