iceberg-cpp
Loading...
Searching...
No Matches
retry.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 <cstdint>
23#include <vector>
24
25#include "iceberg/result.h"
26#include "iceberg/util/retry_util.h"
27#include "iceberg/util/retry_util_internal.h"
28
29namespace iceberg::test {
30
31using CommitFailedRetry = retry::OnlyRetryOn<ErrorKind::kCommitFailed>;
32
33using TransientIORetry =
34 retry::OnlyRetryOn<ErrorKind::kIOError, ErrorKind::kServiceUnavailable,
35 ErrorKind::kInternalServerError>;
36
38 public:
39 using Duration = RetryTestHooks::Duration;
40 using TimePoint = RetryTestHooks::TimePoint;
41
43 hooks_.now = [this]() { return now_; };
44 hooks_.sleep_for = [this](Duration duration) {
45 sleep_durations_.push_back(duration);
46 now_ += duration;
47 };
48 hooks_.jitter = [this](int32_t base_delay_ms) {
49 observed_base_delays_ms_.push_back(base_delay_ms);
50 return base_delay_ms + jitter_offset_ms_;
51 };
52 }
53
54 void Advance(Duration duration) { now_ += duration; }
55
56 void SetJitterOffsetMs(int32_t jitter_offset_ms) {
57 jitter_offset_ms_ = jitter_offset_ms;
58 }
59
60 const RetryTestHooks& hooks() const { return hooks_; }
61
62 const std::vector<Duration>& sleep_durations() const { return sleep_durations_; }
63
64 const std::vector<int32_t>& observed_base_delays_ms() const {
65 return observed_base_delays_ms_;
66 }
67
68 private:
69 RetryTestHooks hooks_;
70 TimePoint now_{};
71 int32_t jitter_offset_ms_ = 0;
72 std::vector<Duration> sleep_durations_;
73 std::vector<int32_t> observed_base_delays_ms_;
74};
75
76} // namespace iceberg::test
Definition retry_util_internal.h:30