Line data Source code
1 : /*
2 : * (C) Copyright 2011 Marek Dopiera
3 : *
4 : * This file is part of CoherentDB.
5 : *
6 : * CoherentDB is free software: you can redistribute it and/or modify it
7 : * under the terms of the GNU General Public License as published by
8 : * the Free Software Foundation, either version 3 of the License, or
9 : * (at your option) any later version.
10 : *
11 : * CoherentDB is distributed in the hope that it will be useful, but
12 : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : * General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU General Public
17 : * License along with CoherentDB. If not, see
18 : * http://www.gnu.org/licenses/.
19 : */
20 :
21 : #ifndef JOURNAL_MOCKS_15914
22 : #define JOURNAL_MOCKS_15914
23 :
24 : #include <map>
25 : #include <boost/shared_ptr.hpp>
26 :
27 : #include <util/worker_pool.h>
28 : #include <journal/journal.h>
29 :
30 : namespace coherent {
31 : namespace journal {
32 : namespace unittests {
33 :
34 : class journal_worker;
35 : class journal_worker_factory;
36 :
37 : class in_mem_journal : public journal
38 : {
39 : public:
40 : in_mem_journal();
41 : ~in_mem_journal();
42 :
43 : virtual void insert(
44 : owner_id_t owner,
45 : util::multi_buffer const & buf,
46 : insert_cb & cb
47 : ) throw();
48 :
49 : virtual void erase(
50 : owner_id_t owner,
51 : handle_t handle,
52 : erase_cb & erase
53 : ) throw();
54 :
55 : // should be called before any insert or erase
56 : virtual void recover(
57 : recovery_dispatcher & dispatcher
58 : ) throw(recovery_dispatcher);
59 :
60 : private:
61 : struct internal_req : public util::virtual_dest
62 0 : {
63 : virtual void execute(in_mem_journal & journal) = 0;
64 : };
65 :
66 : struct insert_req : public internal_req
67 0 : {
68 : insert_req(
69 : owner_id_t owner,
70 : util::multi_buffer const & buf,
71 : insert_cb & cb
72 : );
73 : virtual void execute(in_mem_journal & journal);
74 :
75 : owner_id_t const owner;
76 : util::multi_buffer const & buf;
77 : insert_cb & cb;
78 : };
79 :
80 : struct erase_req : public internal_req
81 0 : {
82 : erase_req(
83 : owner_id_t const owner,
84 : handle_t const handle,
85 : erase_cb & cb
86 : );
87 : virtual void execute(in_mem_journal & journal);
88 :
89 : owner_id_t const owner;
90 : handle_t const handle;
91 : erase_cb & cb;
92 : };
93 :
94 : public:
95 : typedef boost::shared_ptr<internal_req> req_ptr;
96 : private:
97 : typedef std::pair<owner_id_t, handle_t> map_key_t;
98 : typedef boost::shared_ptr<util::buffer> buffer_ptr;
99 : typedef std::map<map_key_t, buffer_ptr> mapt_t;
100 : typedef util::worker_pool<req_ptr> workers_t;
101 :
102 : friend class journal_worker;
103 : friend class journal_worker_factory;
104 :
105 : mapt_t contents;
106 : workers_t workers;
107 :
108 : };
109 :
110 : //does not have any error handling
111 : class sync_journal_wrapper
112 : {
113 : public:
114 : typedef journal::owner_id_t owner_id_t;
115 : typedef journal::handle_t handle_t;
116 : typedef journal::recovery_dispatcher recovery_dispatcher;
117 :
118 : sync_journal_wrapper(journal & journal);
119 :
120 : handle_t insert(
121 : owner_id_t owner,
122 : util::multi_buffer const & buf
123 : );
124 :
125 : void erase(
126 : owner_id_t owner,
127 : handle_t handle
128 : );
129 :
130 : void recover(
131 : recovery_dispatcher & dispatcher
132 : );
133 :
134 : private:
135 : journal & impl;
136 : };
137 :
138 : } // namespace unittests
139 : } // namespace journal
140 : } // namespace coherent
141 :
142 : #endif /* JOURNAL_MOCKS_15914 */
143 :
|