blob: 0fd729326016b2ead7b3437d821f4b39857fdb11 (
plain)
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
|
// Copyright (C) 2022 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
#ifndef GENERIC_CONFIG_BACKEND_RECOVERY_H
#define GENERIC_CONFIG_BACKEND_RECOVERY_H
#include <util/reconnect_ctl.h>
#include <database/server_collection.h>
#include <dhcpsrv/config_backend_dhcp4_mgr.h>
#include <dhcpsrv/testutils/generic_backend_unittest.h>
namespace isc {
namespace dhcp {
namespace test {
/// @brief Test fixture for verifying config backend database connection
/// loss-recovery behavior.
class GenericConfigBackendDbLostCallbackTest : public ::testing::Test {
public:
/// @brief Constructor
GenericConfigBackendDbLostCallbackTest();
/// @brief Destructor
virtual ~GenericConfigBackendDbLostCallbackTest();
/// @brief Abstract method for destroying the back end specific schema
virtual void destroySchema() = 0;
/// @brief Abstract method for creating the back end specific schema
virtual void createSchema() = 0;
/// @brief Abstract method which returns a valid back end specific connection
/// string
virtual std::string validConnectionString() = 0;
/// @brief Abstract method which returns an invalid back end specific connection
/// string
virtual std::string invalidConnectionString() = 0;
/// @brief Abstract method which registers a CB backend type.
virtual void registerBackendType() = 0;
/// @brief Abstract method which unregisters a CB backend type.
virtual void unregisterBackendType() = 0;
/// @brief Abstract method which sets the IOService instance in the CB
/// implementation object.
///
/// @param io_service pointer to the IOService instance to use. It may be
/// an empty pointer.
virtual void setConfigBackendImplIOService(isc::asiolink::IOServicePtr io_service) = 0;
/// @brief Abstract method which sets the IOService instance in the CB
virtual void addBackend(const std::string& access) = 0;
/// @brief Abstract method which sets the IOService instance in the CB
virtual db::ServerCollection getAllServers() = 0;
/// @brief Prepares the class for a test.
///
/// Invoked by gtest prior test entry, we create the
/// appropriate schema and create a basic DB manager to
/// wipe out any prior instance
virtual void SetUp();
/// @brief Pre-text exit clean up
///
/// Invoked by gtest upon test exit, we destroy the schema
/// we created.
virtual void TearDown();
/// @brief Verifies the CB manager's behavior if DB connection can not be
/// established but succeeds on retry
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies that connectivity is unavailable
/// and then recovered on retry:
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked
void testRetryOpenDbLostAndRecoveredCallback();
/// @brief Verifies the CB manager's behavior if DB connection can not be
/// established but fails on retry
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies that connectivity is unavailable
/// and then fails again on retry:
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked
void testRetryOpenDbLostAndFailedCallback();
/// @brief Verifies the CB manager's behavior if DB connection can not be
/// established but succeeds on retry
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies that connectivity is unavailable
/// and then recovered on retry:
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked after two reconnect
/// attempts (once failing and second triggered by timer)
void testRetryOpenDbLostAndRecoveredAfterTimeoutCallback();
/// @brief Verifies the CB manager's behavior if DB connection can not be
/// established but fails on retry
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies that connectivity is unavailable
/// and then fails again on retry:
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked after two reconnect
/// attempts (once failing and second triggered by timer)
void testRetryOpenDbLostAndFailedAfterTimeoutCallback();
/// @brief Verifies open failures do NOT invoke db lost callback
///
/// The db lost callback should only be invoked after successfully
/// opening the DB and then subsequently losing it. Failing to
/// open should be handled directly by the application layer.
void testNoCallbackOnOpenFailure();
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies connectivity by issuing a known
/// valid query. Next it simulates connectivity lost by identifying and
/// closing the socket connection to the CB backend. It then reissues the
/// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked
void testDbLostAndRecoveredCallback();
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies connectivity by issuing a known
/// valid query. Next it simulates connectivity lost by identifying and
/// closing the socket connection to the CB backend. It then reissues the
/// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked
void testDbLostAndFailedCallback();
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies connectivity by issuing a known
/// valid query. Next it simulates connectivity lost by identifying and
/// closing the socket connection to the CB backend. It then reissues the
/// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbRecoveredCallback was invoked after two reconnect
/// attempts (once failing and second triggered by timer)
void testDbLostAndRecoveredAfterTimeoutCallback();
/// @brief Verifies the CB manager's behavior if DB connection is lost
///
/// This function creates a CB manager with a back end that supports
/// connectivity lost callback. It verifies connectivity by issuing a known
/// valid query. Next it simulates connectivity lost by identifying and
/// closing the socket connection to the CB backend. It then reissues the
/// query and verifies that:
/// -# The Query throws DbOperationError (rather than exiting)
/// -# The registered DbLostCallback was invoked
/// -# The registered DbFailedCallback was invoked after two reconnect
/// attempts (once failing and second triggered by timer)
void testDbLostAndFailedAfterTimeoutCallback();
/// @brief Callback function registered with the CB manager
bool db_lost_callback(util::ReconnectCtlPtr /* not_used */) {
return (++db_lost_callback_called_);
}
/// @brief Flag used to detect calls to db_lost_callback function
uint32_t db_lost_callback_called_;
/// @brief Callback function registered with the CB manager
bool db_recovered_callback(util::ReconnectCtlPtr /* not_used */) {
return (++db_recovered_callback_called_);
}
/// @brief Flag used to detect calls to db_recovered_callback function
uint32_t db_recovered_callback_called_;
/// @brief Callback function registered with the CB manager
bool db_failed_callback(util::ReconnectCtlPtr /* not_used */) {
return (++db_failed_callback_called_);
}
/// @brief Flag used to detect calls to db_failed_callback function
uint32_t db_failed_callback_called_;
/// The IOService object, used for all ASIO operations.
isc::asiolink::IOServicePtr io_service_;
};
} // namespace test
} // namespace dhcp
} // namespace isc
#endif // GENERIC_CONFIG_BACKEND_RECOVERY_H
|