iceberg-cpp
Loading...
Searching...
No Matches
retry_util_internal.h
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
19
20#pragma once
21
22#include <chrono>
23#include <cstdint>
24#include <functional>
25
26#include "iceberg/iceberg_export.h"
27
28namespace iceberg {
29
31 using Clock = std::chrono::steady_clock;
32 using Duration = std::chrono::milliseconds;
33 using TimePoint = Clock::time_point;
34
35 std::function<TimePoint()> now;
36 std::function<void(Duration)> sleep_for;
37 std::function<int32_t(int32_t)> jitter;
38};
39
40ICEBERG_EXPORT const RetryTestHooks* GetActiveRetryTestHooks();
41ICEBERG_EXPORT void SetActiveRetryTestHooks(const RetryTestHooks* hooks);
42
44 public:
45 explicit ScopedRetryTestHooks(const RetryTestHooks& hooks)
46 : previous_hooks_(GetActiveRetryTestHooks()) {
47 SetActiveRetryTestHooks(&hooks);
48 }
49
51 ScopedRetryTestHooks& operator=(const ScopedRetryTestHooks&) = delete;
53 ScopedRetryTestHooks& operator=(ScopedRetryTestHooks&&) = delete;
54
55 ~ScopedRetryTestHooks() { SetActiveRetryTestHooks(previous_hooks_); }
56
57 private:
58 const RetryTestHooks* previous_hooks_;
59};
60
61} // namespace iceberg
Definition retry_util_internal.h:43
Definition retry_util_internal.h:30