本文整理汇总了Golang中github.com/cockroachdb/cockroach/util/hlc.NewManualClock函数的典型用法代码示例。如果您正苦于以下问题:Golang NewManualClock函数的具体用法?Golang NewManualClock怎么用?Golang NewManualClock使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了NewManualClock函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: TestMultiRangeScanReverseScanInconsistent
// TestMultiRangeScanReverseScanInconsistent verifies that a Scan/ReverseScan
// across ranges that doesn't require read consistency will set a timestamp
// using the clock local to the distributed sender.
func TestMultiRangeScanReverseScanInconsistent(t *testing.T) {
defer leaktest.AfterTest(t)
s, db := setupMultipleRanges(t, "b")
defer s.Stop()
// Write keys "a" and "b", the latter of which is the first key in the
// second range.
keys := []string{"a", "b"}
ts := []time.Time{}
for i, key := range keys {
b := &client.Batch{}
b.Put(key, "value")
if err := db.Run(b); err != nil {
t.Fatal(err)
}
ts = append(ts, b.Results[0].Rows[0].Timestamp())
log.Infof("%d: %s", i, b.Results[0].Rows[0].Timestamp())
}
// Do an inconsistent Scan/ReverseScan from a new DistSender and verify
// it does the read at its local clock and doesn't receive an
// OpRequiresTxnError. We set the local clock to the timestamp of
// the first key to verify it's used to read only key "a".
manual := hlc.NewManualClock(ts[1].UnixNano() - 1)
clock := hlc.NewClock(manual.UnixNano)
ds := kv.NewDistSender(&kv.DistSenderContext{Clock: clock}, s.Gossip())
// Scan.
sa := roachpb.NewScan(roachpb.Key("a"), roachpb.Key("c"), 0).(*roachpb.ScanRequest)
reply, err := client.SendWrappedWith(ds, nil, roachpb.BatchRequest_Header{
ReadConsistency: roachpb.INCONSISTENT,
}, sa)
if err != nil {
t.Fatal(err)
}
sr := reply.(*roachpb.ScanResponse)
if l := len(sr.Rows); l != 1 {
t.Fatalf("expected 1 row; got %d", l)
}
if key := string(sr.Rows[0].Key); keys[0] != key {
t.Errorf("expected key %q; got %q", keys[0], key)
}
// ReverseScan.
rsa := roachpb.NewReverseScan(roachpb.Key("a"), roachpb.Key("c"), 0).(*roachpb.ReverseScanRequest)
reply, err = client.SendWrappedWith(ds, nil, roachpb.BatchRequest_Header{
ReadConsistency: roachpb.INCONSISTENT,
}, rsa)
if err != nil {
t.Fatal(err)
}
rsr := reply.(*roachpb.ReverseScanResponse)
if l := len(rsr.Rows); l != 1 {
t.Fatalf("expected 1 row; got %d", l)
}
if key := string(rsr.Rows[0].Key); keys[0] != key {
t.Errorf("expected key %q; got %q", keys[0], key)
}
}
开发者ID:rohanahata,项目名称:cockroach,代码行数:63,代码来源:dist_sender_server_test.go
示例2: TestRejectFutureCommand
// TestRejectFutureCommand verifies that lease holders reject commands that
// would cause a large time jump.
func TestRejectFutureCommand(t *testing.T) {
defer leaktest.AfterTest(t)()
const maxOffset = 100 * time.Millisecond
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
clock.SetMaxOffset(maxOffset)
mtc := multiTestContext{
clock: clock,
}
mtc.Start(t, 1)
defer mtc.Stop()
// First do a write. The first write will advance the clock by MaxOffset
// because of the read cache's low water mark.
getArgs := putArgs([]byte("b"), []byte("b"))
if _, err := client.SendWrapped(rg1(mtc.stores[0]), nil, &getArgs); err != nil {
t.Fatal(err)
}
if now := clock.Now(); now.WallTime != int64(maxOffset) {
t.Fatalf("expected clock to advance to 100ms; got %s", now)
}
// The logical clock has advanced past the physical clock; increment
// the "physical" clock to catch up.
manual.Increment(int64(maxOffset))
startTime := manual.UnixNano()
// Commands with a future timestamp that is within the MaxOffset
// bound will be accepted and will cause the clock to advance.
for i := int64(0); i < 3; i++ {
incArgs := incrementArgs([]byte("a"), 5)
ts := hlc.ZeroTimestamp.Add(startTime+((i+1)*30)*int64(time.Millisecond), 0)
if _, err := client.SendWrappedWith(rg1(mtc.stores[0]), nil, roachpb.Header{Timestamp: ts}, &incArgs); err != nil {
t.Fatal(err)
}
}
if now := clock.Now(); now.WallTime != int64(190*time.Millisecond) {
t.Fatalf("expected clock to advance to 190ms; got %s", now)
}
// Once the accumulated offset reaches MaxOffset, commands will be rejected.
incArgs := incrementArgs([]byte("a"), 11)
ts := hlc.ZeroTimestamp.Add(int64((time.Duration(startTime)+maxOffset+1)*time.Millisecond), 0)
if _, err := client.SendWrappedWith(rg1(mtc.stores[0]), nil, roachpb.Header{Timestamp: ts}, &incArgs); err == nil {
t.Fatalf("expected clock offset error but got nil")
}
// The clock remained at 190ms and the final command was not executed.
if now := clock.Now(); now.WallTime != int64(190*time.Millisecond) {
t.Errorf("expected clock to advance to 190ms; got %s", now)
}
val, _, err := engine.MVCCGet(context.Background(), mtc.engines[0], roachpb.Key("a"), clock.Now(), true, nil)
if err != nil {
t.Fatal(err)
}
if v := mustGetInt(val); v != 15 {
t.Errorf("expected 15, got %v", v)
}
}
开发者ID:yangxuanjia,项目名称:cockroach,代码行数:62,代码来源:client_replica_test.go
示例3: TestScannerAddToQueues
// TestScannerAddToQueues verifies that ranges are added to and
// removed from multiple queues.
func TestScannerAddToQueues(t *testing.T) {
const count = 3
iter := newTestIterator(count)
q1, q2 := &testQueue{}, &testQueue{}
s := newRangeScanner(1*time.Millisecond, iter)
s.AddQueues(q1, q2)
mc := hlc.NewManualClock(0)
clock := hlc.NewClock(mc.UnixNano)
stopper := util.NewStopper(0)
// Start queue and verify that all ranges are added to both queues.
s.Start(clock, stopper)
if err := util.IsTrueWithin(func() bool {
return q1.count() == count && q2.count() == count
}, 50*time.Millisecond); err != nil {
t.Error(err)
}
// Remove first range and verify it does not exist in either range.
rng := iter.remove(0)
s.RemoveRange(rng)
if err := util.IsTrueWithin(func() bool {
return q1.count() == count-1 && q2.count() == count-1
}, 10*time.Millisecond); err != nil {
t.Error(err)
}
// Stop scanner and verify both queues are stopped.
stopper.Stop()
if !q1.isDone() || !q2.isDone() {
t.Errorf("expected all queues to stop; got %t, %t", q1.isDone(), q2.isDone())
}
}
开发者ID:josephwinston,项目名称:cockroach,代码行数:35,代码来源:scanner_test.go
示例4: createTestStoreWithoutStart
// createTestStoreWithoutStart creates a test store using an in-memory
// engine without starting the store. It returns the store, the store
// clock's manual unix nanos time and a stopper. The caller is
// responsible for stopping the stopper upon completion.
func createTestStoreWithoutStart(t *testing.T) (*Store, *hlc.ManualClock, *stop.Stopper) {
stopper := stop.NewStopper()
// Setup fake zone config handler.
config.TestingSetupZoneConfigHook(stopper)
rpcContext := rpc.NewContext(&base.Context{}, hlc.NewClock(hlc.UnixNano), stopper)
ctx := TestStoreContext
ctx.Gossip = gossip.New(rpcContext, gossip.TestInterval, gossip.TestBootstrap)
ctx.StorePool = NewStorePool(ctx.Gossip, TestTimeUntilStoreDeadOff, stopper)
manual := hlc.NewManualClock(0)
ctx.Clock = hlc.NewClock(manual.UnixNano)
eng := engine.NewInMem(roachpb.Attributes{}, 10<<20, stopper)
ctx.Transport = multiraft.NewLocalRPCTransport(stopper)
stopper.AddCloser(ctx.Transport)
sender := &testSender{}
ctx.DB = client.NewDB(sender)
store := NewStore(ctx, eng, &roachpb.NodeDescriptor{NodeID: 1})
sender.store = store
if err := store.Bootstrap(roachpb.StoreIdent{NodeID: 1, StoreID: 1}, stopper); err != nil {
t.Fatal(err)
}
if err := store.BootstrapRange(nil); err != nil {
t.Fatal(err)
}
return store, manual, stopper
}
开发者ID:GokulSrinivas,项目名称:cockroach,代码行数:29,代码来源:store_test.go
示例5: TestScannerTiming
// TestScannerTiming verifies that ranges are scanned, regardless
// of how many, to match scanInterval.
//
// TODO(spencer): in order to make this test not take too much time,
// we're running these loops at speeds where clock ticks may be
// an issue on virtual machines used for continuous integration.
func TestScannerTiming(t *testing.T) {
const count = 3
const runTime = 50 * time.Millisecond
const maxError = 7500 * time.Microsecond
durations := []time.Duration{
5 * time.Millisecond,
12500 * time.Microsecond,
}
for i, duration := range durations {
iter := newTestIterator(count)
q := &testQueue{}
s := newRangeScanner(duration, iter)
s.AddQueues(q)
mc := hlc.NewManualClock(0)
clock := hlc.NewClock(mc.UnixNano)
stopper := util.NewStopper(0)
defer stopper.Stop()
s.Start(clock, stopper)
time.Sleep(runTime)
avg := iter.avgScan()
log.Infof("%d: average scan: %s\n", i, avg)
if avg.Nanoseconds()-duration.Nanoseconds() > maxError.Nanoseconds() ||
duration.Nanoseconds()-avg.Nanoseconds() > maxError.Nanoseconds() {
t.Errorf("expected %s, got %s: exceeds max error of %s", duration, avg, maxError)
}
}
}
开发者ID:josephwinston,项目名称:cockroach,代码行数:34,代码来源:scanner_test.go
示例6: createTestBookie
// createTestBookie creates a new bookie, stopper and manual clock for testing.
func createTestBookie(reservationTimeout time.Duration) (*stop.Stopper, *hlc.ManualClock, *bookie) {
stopper := stop.NewStopper()
mc := hlc.NewManualClock(0)
clock := hlc.NewClock(mc.UnixNano)
b := newBookie(clock, reservationTimeout, stopper)
return stopper, mc, b
}
开发者ID:JKhawaja,项目名称:cockroach,代码行数:8,代码来源:reservation_test.go
示例7: createTestStoreWithoutStart
// createTestStoreWithoutStart creates a test store using an in-memory
// engine without starting the store. It returns the store, the store
// clock's manual unix nanos time and a stopper. The caller is
// responsible for stopping the stopper upon completion.
func createTestStoreWithoutStart(t *testing.T) (*Store, *hlc.ManualClock, *stop.Stopper) {
stopper := stop.NewStopper()
rpcContext := rpc.NewContext(rootTestBaseContext, hlc.NewClock(hlc.UnixNano), stopper)
ctx := TestStoreContext
ctx.Gossip = gossip.New(rpcContext, gossip.TestInterval, gossip.TestBootstrap)
manual := hlc.NewManualClock(0)
ctx.Clock = hlc.NewClock(manual.UnixNano)
eng := engine.NewInMem(proto.Attributes{}, 10<<20)
ctx.Transport = multiraft.NewLocalRPCTransport()
stopper.AddCloser(ctx.Transport)
sender := &testSender{}
var err error
if ctx.DB, err = client.Open("//[email protected]", client.SenderOpt(sender)); err != nil {
t.Fatal(err)
}
store := NewStore(ctx, eng, &proto.NodeDescriptor{NodeID: 1})
sender.store = store
if err := store.Bootstrap(proto.StoreIdent{NodeID: 1, StoreID: 1}, stopper); err != nil {
t.Fatal(err)
}
if err := store.BootstrapRange(); err != nil {
t.Fatal(err)
}
return store, manual, stopper
}
开发者ID:backend2use,项目名称:cockroachdb,代码行数:29,代码来源:store_test.go
示例8: Start
func (m *multiTestContext) Start(t *testing.T, numStores int) {
if m.manualClock == nil {
m.manualClock = hlc.NewManualClock(0)
}
if m.clock == nil {
m.clock = hlc.NewClock(m.manualClock.UnixNano)
}
if m.gossip == nil {
rpcContext := rpc.NewContext(m.clock, rpc.LoadInsecureTLSConfig())
m.gossip = gossip.New(rpcContext, gossip.TestInterval, "")
}
if m.transport == nil {
m.transport = multiraft.NewLocalRPCTransport()
}
if m.sender == nil {
m.sender = kv.NewLocalSender()
}
if m.db == nil {
txnSender := kv.NewTxnCoordSender(m.sender, m.clock, false)
m.db = client.NewKV(txnSender, nil)
m.db.User = storage.UserRoot
}
for i := 0; i < numStores; i++ {
m.addStore(t)
}
}
开发者ID:josephwinston,项目名称:cockroach,代码行数:27,代码来源:client_test.go
示例9: TestTimestampCacheReadVsWrite
// TestTimestampCacheReadVsWrite verifies that the timestamp cache
// can differentiate between read and write timestamp.
func TestTimestampCacheReadVsWrite(t *testing.T) {
defer leaktest.AfterTest(t)
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
tc := NewTimestampCache(clock)
// Add read-only non-txn entry at current time.
ts1 := clock.Now()
tc.Add(roachpb.Key("a"), roachpb.Key("b"), ts1, nil, true)
// Add two successive txn entries; one read-only and one read-write.
txn1ID := uuid.NewUUID4()
txn2ID := uuid.NewUUID4()
ts2 := clock.Now()
tc.Add(roachpb.Key("a"), nil, ts2, txn1ID, true)
ts3 := clock.Now()
tc.Add(roachpb.Key("a"), nil, ts3, txn2ID, false)
// Fetching with no transaction gets latest values.
if rTS, wTS := tc.GetMax(roachpb.Key("a"), nil, nil); !rTS.Equal(ts2) || !wTS.Equal(ts3) {
t.Errorf("expected %s %s; got %s %s", ts2, ts3, rTS, wTS)
}
// Fetching with txn ID "1" gets original for read and most recent for write.
if rTS, wTS := tc.GetMax(roachpb.Key("a"), nil, txn1ID); !rTS.Equal(ts1) || !wTS.Equal(ts3) {
t.Errorf("expected %s %s; got %s %s", ts1, ts3, rTS, wTS)
}
// Fetching with txn ID "2" gets ts2 for read and low water mark for write.
if rTS, wTS := tc.GetMax(roachpb.Key("a"), nil, txn2ID); !rTS.Equal(ts2) || !wTS.Equal(tc.lowWater) {
t.Errorf("expected %s %s; got %s %s", ts2, tc.lowWater, rTS, wTS)
}
}
开发者ID:welfeng2016,项目名称:cockroach,代码行数:33,代码来源:timestamp_cache_test.go
示例10: TestTxnCoordSenderSingleRoundtripTxn
// TestTxnCoordSenderSingleRoundtripTxn checks that a batch which completely
// holds the writing portion of a Txn (including EndTransaction) does not
// launch a heartbeat goroutine at all.
func TestTxnCoordSenderSingleRoundtripTxn(t *testing.T) {
defer leaktest.AfterTest(t)
stopper := stop.NewStopper()
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
clock.SetMaxOffset(20)
ts := NewTxnCoordSender(senderFn(func(_ context.Context, ba proto.BatchRequest) (*proto.BatchResponse, *proto.Error) {
return ba.CreateReply().(*proto.BatchResponse), nil
}), clock, false, nil, stopper)
// Stop the stopper manually, prior to trying the transaction. This has the
// effect of returning a NodeUnavailableError for any attempts at launching
// a heartbeat goroutine.
stopper.Stop()
var ba proto.BatchRequest
put := &proto.PutRequest{}
put.Key = proto.Key("test")
ba.Add(put)
ba.Add(&proto.EndTransactionRequest{})
ba.Txn = &proto.Transaction{Name: "test"}
_, pErr := ts.Send(context.Background(), ba)
if pErr != nil {
t.Fatal(pErr)
}
}
开发者ID:freakynit,项目名称:cockroach,代码行数:30,代码来源:txn_coord_sender_test.go
示例11: TestClockOffsetMetrics
func TestClockOffsetMetrics(t *testing.T) {
defer leaktest.AfterTest(t)()
t.Skip()
stopper := stop.NewStopper()
defer stopper.Stop()
// Create a RemoteClockMonitor with a hand-picked offset.
offset := RemoteOffset{
Offset: 13,
Uncertainty: 7,
MeasuredAt: 6,
}
clock := hlc.NewClock(hlc.NewManualClock(123).UnixNano)
clock.SetMaxOffset(20 * time.Nanosecond)
monitor := newRemoteClockMonitor(clock, time.Hour)
monitor.mu.offsets = map[string]RemoteOffset{
"0": offset,
}
if err := monitor.VerifyClockOffset(); err != nil {
t.Fatal(err)
}
reg := monitor.Registry()
expLower := offset.Offset - offset.Uncertainty
if a, e := reg.GetGauge("lower-bound-nanos").Value(), expLower; a != e {
t.Errorf("lower bound %d != expected %d", a, e)
}
expHigher := offset.Offset + offset.Uncertainty
if a, e := reg.GetGauge("upper-bound-nanos").Value(), expHigher; a != e {
t.Errorf("upper bound %d != expected %d", a, e)
}
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:33,代码来源:clock_offset_test.go
示例12: TestTimestampCacheWithTxnID
// TestTimestampCacheWithTxnID verifies that timestamps matching
// the specified txn ID are ignored.
func TestTimestampCacheWithTxnID(t *testing.T) {
defer leaktest.AfterTest(t)
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
tc := NewTimestampCache(clock)
// Add two successive txn entries.
txn1ID := uuid.NewUUID4()
txn2ID := uuid.NewUUID4()
ts1 := clock.Now()
tc.Add(roachpb.Key("a"), roachpb.Key("c"), ts1, txn1ID, true)
ts2 := clock.Now()
// This entry will remove "a"-"b" from the cache.
tc.Add(roachpb.Key("b"), roachpb.Key("d"), ts2, txn2ID, true)
// Fetching with no transaction gets latest value.
if ts, _ := tc.GetMax(roachpb.Key("b"), nil, nil); !ts.Equal(ts2) {
t.Errorf("expected %s; got %s", ts2, ts)
}
// Fetching with txn ID "1" gets most recent.
if ts, _ := tc.GetMax(roachpb.Key("b"), nil, txn1ID); !ts.Equal(ts2) {
t.Errorf("expected %s; got %s", ts2, ts)
}
// Fetching with txn ID "2" skips most recent.
if ts, _ := tc.GetMax(roachpb.Key("b"), nil, txn2ID); !ts.Equal(ts1) {
t.Errorf("expected %s; got %s", ts1, ts)
}
}
开发者ID:welfeng2016,项目名称:cockroach,代码行数:30,代码来源:timestamp_cache_test.go
示例13: TestBuildEndpointListRemoveStagnantClocks
// TestBuildEndpointListRemoveStagnantClocks tests the side effect of removing
// older offsets when we build an endpoint list.
func TestBuildEndpointListRemoveStagnantClocks(t *testing.T) {
defer leaktest.AfterTest(t)()
offsets := map[string]RemoteOffset{
"0": {Offset: 0, Uncertainty: 10, MeasuredAt: 11},
"stagnant0": {Offset: 1, Uncertainty: 10, MeasuredAt: 0},
"1": {Offset: 2, Uncertainty: 10, MeasuredAt: 20},
"stagnant1": {Offset: 3, Uncertainty: 10, MeasuredAt: 9},
}
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
clock.SetMaxOffset(5 * time.Nanosecond)
remoteClocks := newRemoteClockMonitor(clock)
// The stagnant offsets older than this will be removed.
remoteClocks.monitorInterval = 10 * time.Nanosecond
remoteClocks.mu.offsets = offsets
remoteClocks.mu.lastMonitoredAt = time.Unix(0, 10) // offsets measured before this will be removed.
remoteClocks.buildEndpointList()
_, ok0 := offsets["stagnant0"]
_, ok1 := offsets["stagnant1"]
if ok0 || ok1 {
t.Errorf("expected stagant offsets removed, instead offsets: %v", offsets)
}
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:29,代码来源:clock_offset_test.go
示例14: TestScannerTiming
// TestScannerTiming verifies that ranges are scanned, regardless
// of how many, to match scanInterval.
func TestScannerTiming(t *testing.T) {
defer leaktest.AfterTest(t)()
const count = 3
const runTime = 100 * time.Millisecond
const maxError = 7500 * time.Microsecond
durations := []time.Duration{
15 * time.Millisecond,
25 * time.Millisecond,
}
for i, duration := range durations {
util.SucceedsSoon(t, func() error {
ranges := newTestRangeSet(count, t)
q := &testQueue{}
s := newReplicaScanner(duration, 0, ranges)
s.AddQueues(q)
mc := hlc.NewManualClock(0)
clock := hlc.NewClock(mc.UnixNano)
stopper := stop.NewStopper()
s.Start(clock, stopper)
time.Sleep(runTime)
stopper.Stop()
avg := s.avgScan()
log.Infof("%d: average scan: %s", i, avg)
if avg.Nanoseconds()-duration.Nanoseconds() > maxError.Nanoseconds() ||
duration.Nanoseconds()-avg.Nanoseconds() > maxError.Nanoseconds() {
return errors.Errorf("expected %s, got %s: exceeds max error of %s", duration, avg, maxError)
}
return nil
})
}
}
开发者ID:YuleiXiao,项目名称:cockroach,代码行数:34,代码来源:scanner_test.go
示例15: TestBuildEndpointListRemoveStagnantClocks
// TestBuildEndpointListRemoveStagnantClocks tests the side effect of removing
// older offsets when we build an endpoint list.
func TestBuildEndpointListRemoveStagnantClocks(t *testing.T) {
offsets := map[string]proto.RemoteOffset{
"0": {Offset: 0, Error: 10, MeasuredAt: 11},
"stagnant0": {Offset: 1, Error: 10, MeasuredAt: 0},
"1": {Offset: 2, Error: 10, MeasuredAt: 20},
"stagnant1": {Offset: 3, Error: 10, MeasuredAt: 9},
}
// The stagnant offsets older than 10ns ago will be removed.
monitorInterval = 10 * time.Nanosecond
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
clock.SetMaxOffset(5 * time.Nanosecond)
remoteClocks := &RemoteClockMonitor{
offsets: offsets,
lClock: clock,
lastMonitoredAt: 10, // offsets measured before this will be removed.
}
remoteClocks.buildEndpointList()
_, ok0 := offsets["stagnant0"]
_, ok1 := offsets["stagnant1"]
if ok0 || ok1 {
t.Errorf("expected stagant offsets removed, instead offsets: %v", offsets)
}
}
开发者ID:josephwinston,项目名称:cockroach,代码行数:31,代码来源:clock_offset_test.go
示例16: TestFindOffsetWithLargeError
// TestFindOffsetWithLargeError tests a case where offset errors are
// bigger than the max offset (e.g., a case where heartbeat messages
// to the node are having high latency).
func TestFindOffsetWithLargeError(t *testing.T) {
defer leaktest.AfterTest(t)()
maxOffset := 100 * time.Nanosecond
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
clock.SetMaxOffset(maxOffset)
offsets := map[string]RemoteOffset{}
// Offsets are bigger than maxOffset, but Errors are also bigger than Offset.
offsets["0"] = RemoteOffset{Offset: 110, Uncertainty: 300}
offsets["1"] = RemoteOffset{Offset: 120, Uncertainty: 300}
offsets["2"] = RemoteOffset{Offset: 130, Uncertainty: 300}
remoteClocks := newRemoteClockMonitor(clock)
remoteClocks.mu.offsets = offsets
interval, err := remoteClocks.findOffsetInterval()
if err != nil {
t.Fatal(err)
}
expectedInterval := clusterOffsetInterval{lowerbound: -270, upperbound: 510}
if interval != expectedInterval {
t.Errorf("expected interval %v, instead %v", expectedInterval, interval)
}
// The interval is still considered healthy.
assertIntervalHealth(true, interval, maxOffset, t)
}
开发者ID:cuongdo,项目名称:cockroach,代码行数:30,代码来源:clock_offset_test.go
示例17: TestScannerStats
// TestScannerStats verifies that stats accumulate from all ranges.
func TestScannerStats(t *testing.T) {
defer leaktest.AfterTest(t)
const count = 3
ranges := newTestRangeSet(count, t)
q := &testQueue{}
stopper := util.NewStopper()
defer stopper.Stop()
s := newRangeScanner(1*time.Millisecond, 0, ranges, nil)
s.AddQueues(q)
mc := hlc.NewManualClock(0)
clock := hlc.NewClock(mc.UnixNano)
// At start, scanner stats should be blank for MVCC, but have accurate number of ranges.
if rc := s.Stats().RangeCount; rc != count {
t.Errorf("range count expected %d; got %d", count, rc)
}
if vb := s.Stats().MVCC.ValBytes; vb != 0 {
t.Errorf("value bytes expected %d; got %d", 0, vb)
}
s.Start(clock, stopper)
// We expect a full run to accumulate stats from all ranges.
if err := util.IsTrueWithin(func() bool {
if rc := s.Stats().RangeCount; rc != count {
return false
}
if vb := s.Stats().MVCC.ValBytes; vb != count*2 {
return false
}
return true
}, 100*time.Millisecond); err != nil {
t.Error(err)
}
}
开发者ID:Hellblazer,项目名称:cockroach,代码行数:33,代码来源:scanner_test.go
示例18: TestTimestampCacheMergeInto
func TestTimestampCacheMergeInto(t *testing.T) {
defer leaktest.AfterTest(t)
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
testCases := []struct {
useClear bool
expLen int
}{
{true, 3},
{false, 5},
}
for _, test := range testCases {
tc1 := NewTimestampCache(clock)
tc2 := NewTimestampCache(clock)
bfTS := clock.Now()
tc2.Add(roachpb.Key("b"), roachpb.Key("f"), bfTS, nil, true)
adTS := clock.Now()
tc1.Add(roachpb.Key("a"), roachpb.Key("d"), adTS, nil, true)
beTS := clock.Now()
tc1.Add(roachpb.Key("b"), roachpb.Key("e"), beTS, nil, true)
aaTS := clock.Now()
tc2.Add(roachpb.Key("aa"), nil, aaTS, nil, true)
cTS := clock.Now()
tc1.Add(roachpb.Key("c"), nil, cTS, nil, true)
tc1.MergeInto(tc2, test.useClear)
if tc2.cache.Len() != test.expLen {
t.Errorf("expected merged length of %d; got %d", test.expLen, tc2.cache.Len())
}
if !tc2.latest.Equal(tc1.latest) {
t.Errorf("expected latest to be updated to %s; got %s", tc1.latest, tc2.latest)
}
if rTS, _ := tc2.GetMax(roachpb.Key("a"), nil, nil); !rTS.Equal(adTS) {
t.Error("expected \"a\" to have adTS timestamp")
}
if rTS, _ := tc2.GetMax(roachpb.Key("b"), nil, nil); !rTS.Equal(beTS) {
t.Error("expected \"b\" to have beTS timestamp")
}
if test.useClear {
if rTS, _ := tc2.GetMax(roachpb.Key("aa"), nil, nil); !rTS.Equal(adTS) {
t.Error("expected \"aa\" to have adTS timestamp")
}
} else {
if rTS, _ := tc2.GetMax(roachpb.Key("aa"), nil, nil); !rTS.Equal(aaTS) {
t.Error("expected \"aa\" to have aaTS timestamp")
}
if rTS, _ := tc2.GetMax(roachpb.Key("a"), roachpb.Key("c"), nil); !rTS.Equal(aaTS) {
t.Error("expected \"a\"-\"c\" to have aaTS timestamp")
}
}
}
}
开发者ID:kaustubhkurve,项目名称:cockroach,代码行数:60,代码来源:timestamp_cache_test.go
示例19: TestTimestampCacheNoEviction
// TestTimestampCacheNoEviction verifies that even after
// the MinTSCacheWindow interval, if the cache has not hit
// its size threshold, it will not evict entries.
func TestTimestampCacheNoEviction(t *testing.T) {
defer leaktest.AfterTest(t)()
manual := hlc.NewManualClock(0)
clock := hlc.NewClock(manual.UnixNano)
clock.SetMaxOffset(maxClockOffset)
tc := newTimestampCache(clock)
// Increment time to the maxClockOffset low water mark + 1.
manual.Set(maxClockOffset.Nanoseconds() + 1)
aTS := clock.Now()
tc.add(roachpb.Key("a"), nil, aTS, nil, true)
tc.AddRequest(cacheRequest{
reads: []roachpb.Span{{Key: roachpb.Key("c")}},
timestamp: aTS,
})
// Increment time by the MinTSCacheWindow and add another key.
manual.Increment(MinTSCacheWindow.Nanoseconds())
tc.add(roachpb.Key("b"), nil, clock.Now(), nil, true)
tc.AddRequest(cacheRequest{
reads: []roachpb.Span{{Key: roachpb.Key("d")}},
timestamp: clock.Now(),
})
// Verify that the cache still has 4 entries in it
if l, want := tc.len(), 4; l != want {
t.Errorf("expected %d entries to remain, got %d", want, l)
}
}
开发者ID:CubeLite,项目名称:cockroach,代码行数:32,代码来源:timestamp_cache_test.go
示例20: TestBaseQueueAddRemove
// TestBaseQueueAddRemove adds then removes a range; ensure range is not processed.
func TestBaseQueueAddRemove(t *testing.T) {
defer leaktest.AfterTest(t)
r := &Range{}
if err := r.setDesc(&proto.RangeDescriptor{RaftID: 1}); err != nil {
t.Fatal(err)
}
testQueue := &testQueueImpl{
shouldQueueFn: func(now proto.Timestamp, r *Range) (shouldQueue bool, priority float64) {
shouldQueue = true
priority = 1.0
return
},
}
bq := newBaseQueue("test", testQueue, 2)
stopper := stop.NewStopper()
mc := hlc.NewManualClock(0)
clock := hlc.NewClock(mc.UnixNano)
bq.Start(clock, stopper)
defer stopper.Stop()
bq.MaybeAdd(r, proto.ZeroTimestamp)
bq.MaybeRemove(r)
time.Sleep(5 * time.Millisecond)
if pc := atomic.LoadInt32(&testQueue.processed); pc > 0 {
t.Errorf("expected processed count of 0; got %d", pc)
}
}
开发者ID:Gardenya,项目名称:cockroach,代码行数:29,代码来源:queue_test.go
注:本文中的github.com/cockroachdb/cockroach/util/hlc.NewManualClock函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论