aboutsummaryrefslogtreecommitdiffstats
path: root/storage/src/tests/distributor/ownership_transfer_safe_time_point_calculator_test.cpp
blob: 06cfbcbfac1183701ae64d4915a448c0771e7ad7 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include <vespa/storage/distributor/ownership_transfer_safe_time_point_calculator.h>
#include <vespa/vespalib/gtest/gtest.h>

namespace storage::distributor {

using CalcType = OwnershipTransferSafeTimePointCalculator;
using TimePoint = vespalib::system_time;

using namespace std::literals::chrono_literals;

TEST(OwnershipTransferSafeTimePointCalculatorTest, generated_safe_time_point_rounds_up_to_nearest_second) {
    EXPECT_EQ(TimePoint(6s), CalcType(1s).safeTimePoint(TimePoint(4001ms)));
    EXPECT_EQ(TimePoint(6s), CalcType(1s).safeTimePoint(TimePoint(4999ms)));
    EXPECT_EQ(TimePoint(6s), CalcType(1s).safeTimePoint(TimePoint(4000ms)));
    EXPECT_EQ(TimePoint(7s), CalcType(2s).safeTimePoint(TimePoint(4001ms)));
    EXPECT_EQ(TimePoint(7s), CalcType(2s).safeTimePoint(TimePoint(4999ms)));
}

TEST(OwnershipTransferSafeTimePointCalculatorTest, zero_clock_skew_returns_epoch) {
    EXPECT_EQ(TimePoint(0s), CalcType(0s).safeTimePoint(TimePoint(4001ms)));
}

}