RTBKit
0.9
Open-source framework to create real-time ad bidding systems.
|
00001 /* mock_banker_persistence.cc 00002 Wolfgang Sourdeau, 14 December 2012 00003 Copyright (c) 2012 Datacratic. All rights reserved. 00004 00005 Mock banker persistence for testing classes that depend on persistence 00006 storage. 00007 */ 00008 00009 #include <iostream> 00010 #include <jml/utils/exc_assert.h> 00011 00012 #include "mock_banker_persistence.h" 00013 00014 using namespace std; 00015 00016 namespace RTBKIT { 00017 00018 MockBankerPersistence:: 00019 MockBankerPersistence() 00020 : disableSaves(false) 00021 { 00022 } 00023 00024 void 00025 MockBankerPersistence:: 00026 prepareLoad(shared_ptr<Accounts> accounts, 00027 BankerPersistence::PersistenceCallbackStatus status, 00028 std::string info) 00029 { 00030 accountsQ.push_back(accounts); 00031 statusQ.push_back(status); 00032 infoQ.push_back(info); 00033 opsQ.push_back(2); 00034 } 00035 00036 void 00037 MockBankerPersistence:: 00038 prepareSave(BankerPersistence::PersistenceCallbackStatus status, 00039 std::string info) 00040 { 00041 ExcAssertEqual(disableSaves, false); 00042 statusQ.push_back(status); 00043 infoQ.push_back(info); 00044 opsQ.push_back(1); 00045 } 00046 00047 void 00048 MockBankerPersistence:: 00049 loadAll(const std::string & topLevelKey, OnLoadedCallback onLoaded) 00050 { 00051 int op = opsQ.front(); 00052 if (op == 2) { 00053 opsQ.pop_front(); 00054 onLoaded(accountsQ.front(), statusQ.front(), infoQ.front()); 00055 accountsQ.pop_front(); 00056 statusQ.pop_front(); 00057 infoQ.pop_front(); 00058 } 00059 else { 00060 throw ML::Exception("operation code must be 2"); 00061 } 00062 } 00063 00064 void 00065 MockBankerPersistence:: 00066 saveAll(const Accounts & toSave, OnSavedCallback onSaved) 00067 { 00068 if (disableSaves) { 00069 onSaved(BankerPersistence::SUCCESS, ""); 00070 cerr << __FUNCTION__ << ": invocation ignored" << endl; 00071 return; 00072 } 00073 int op = opsQ.front(); 00074 if (op == 1) { 00075 opsQ.pop_front(); 00076 onSaved(statusQ.front(), infoQ.front()); 00077 statusQ.pop_front(); 00078 infoQ.pop_front(); 00079 } 00080 else { 00081 throw ML::Exception("operation code must be 1"); 00082 } 00083 } 00084 00085 } // namespace RTBKIT