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
|
// Copyright 2015 The etcd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package v2store
import (
"testing"
"time"
"go.etcd.io/etcd/client/pkg/v3/testutil"
)
// TestStoreStatsGetSuccess to ensure that a successful Get is recorded in the stats.
func TestStoreStatsGetSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Get("/foo", false, false)
testutil.AssertEqual(t, uint64(1), s.Stats.GetSuccess, "")
}
// TestStoreStatsGetFail to ensure that a failed Get is recorded in the stats.
func TestStoreStatsGetFail(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Get("/no_such_key", false, false)
testutil.AssertEqual(t, uint64(1), s.Stats.GetFail, "")
}
// TestStoreStatsCreateSuccess to ensure that a successful Create is recorded in the stats.
func TestStoreStatsCreateSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
testutil.AssertEqual(t, uint64(1), s.Stats.CreateSuccess, "")
}
// TestStoreStatsCreateFail to ensure that a failed Create is recorded in the stats.
func TestStoreStatsCreateFail(t *testing.T) {
s := newStore()
s.Create("/foo", true, "", false, TTLOptionSet{ExpireTime: Permanent})
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
testutil.AssertEqual(t, uint64(1), s.Stats.CreateFail, "")
}
// TestStoreStatsUpdateSuccess to ensure that a successful Update is recorded in the stats.
func TestStoreStatsUpdateSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Update("/foo", "baz", TTLOptionSet{ExpireTime: Permanent})
testutil.AssertEqual(t, uint64(1), s.Stats.UpdateSuccess, "")
}
// TestStoreStatsUpdateFail to ensure that a failed Update is recorded in the stats.
func TestStoreStatsUpdateFail(t *testing.T) {
s := newStore()
s.Update("/foo", "bar", TTLOptionSet{ExpireTime: Permanent})
testutil.AssertEqual(t, uint64(1), s.Stats.UpdateFail, "")
}
// TestStoreStatsCompareAndSwapSuccess to ensure that a successful CAS is recorded in the stats.
func TestStoreStatsCompareAndSwapSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.CompareAndSwap("/foo", "bar", 0, "baz", TTLOptionSet{ExpireTime: Permanent})
testutil.AssertEqual(t, uint64(1), s.Stats.CompareAndSwapSuccess, "")
}
// TestStoreStatsCompareAndSwapFail to ensure that a failed CAS is recorded in the stats.
func TestStoreStatsCompareAndSwapFail(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.CompareAndSwap("/foo", "wrong_value", 0, "baz", TTLOptionSet{ExpireTime: Permanent})
testutil.AssertEqual(t, uint64(1), s.Stats.CompareAndSwapFail, "")
}
// TestStoreStatsDeleteSuccess to ensure that a successful Delete is recorded in the stats.
func TestStoreStatsDeleteSuccess(t *testing.T) {
s := newStore()
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: Permanent})
s.Delete("/foo", false, false)
testutil.AssertEqual(t, uint64(1), s.Stats.DeleteSuccess, "")
}
// TestStoreStatsDeleteFail to ensure that a failed Delete is recorded in the stats.
func TestStoreStatsDeleteFail(t *testing.T) {
s := newStore()
s.Delete("/foo", false, false)
testutil.AssertEqual(t, uint64(1), s.Stats.DeleteFail, "")
}
// TestStoreStatsExpireCount to ensure that the number of expirations is recorded in the stats.
func TestStoreStatsExpireCount(t *testing.T) {
s := newStore()
fc := newFakeClock()
s.clock = fc
s.Create("/foo", false, "bar", false, TTLOptionSet{ExpireTime: fc.Now().Add(500 * time.Millisecond)})
testutil.AssertEqual(t, uint64(0), s.Stats.ExpireCount, "")
fc.Advance(600 * time.Millisecond)
s.DeleteExpiredKeys(fc.Now())
testutil.AssertEqual(t, uint64(1), s.Stats.ExpireCount, "")
}
|