go mod vendor # for other packages

This commit is contained in:
Zhen Wang
2019-06-04 12:15:47 -07:00
parent 43663b2d8b
commit fa804088e9
62 changed files with 4143 additions and 2539 deletions
+4 -5
View File
@@ -1,4 +1,4 @@
Apache License
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
@@ -178,7 +178,7 @@ Apache License
APPENDIX: How to apply the Apache License to your work.
To apply the Apache License to your work, attach the following
boilerplate notice, with the fields enclosed by brackets "{}"
boilerplate notice, with the fields enclosed by brackets "[]"
replaced with your own identifying information. (Don't include
the brackets!) The text should be enclosed in the appropriate
comment syntax for the file format. We also recommend that a
@@ -186,7 +186,7 @@ Apache License
same "printed page" as the copyright notice for easier
identification within third-party archives.
Copyright {yyyy} {name of copyright owner}
Copyright [yyyy] [name of copyright owner]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
@@ -198,5 +198,4 @@ Apache License
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.
limitations under the License.
+7 -2
View File
@@ -1,7 +1,7 @@
clock
Copyright (c) 2015-Present CloudFoundry.org Foundation, Inc. All Rights Reserved.
This project contains software that is Copyright (c) 2015 Pivotal Software, Inc.
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
@@ -13,3 +13,8 @@ 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.
This project may include a number of subcomponents with separate
copyright notices and license terms. Your use of these subcomponents
is subject to the terms and conditions of each subcomponent's license,
as noted in the LICENSE file.
+25 -13
View File
@@ -1,6 +1,7 @@
package fakeclock
import (
"errors"
"sync"
"time"
@@ -9,19 +10,21 @@ import (
type timeWatcher interface {
timeUpdated(time.Time)
shouldFire(time.Time) bool
repeatable() bool
}
type FakeClock struct {
now time.Time
watchers map[timeWatcher]int
watchers map[timeWatcher]struct{}
cond *sync.Cond
}
func NewFakeClock(now time.Time) *FakeClock {
return &FakeClock{
now: now,
watchers: make(map[timeWatcher]int),
watchers: make(map[timeWatcher]struct{}),
cond: &sync.Cond{L: &sync.Mutex{}},
}
}
@@ -69,6 +72,10 @@ func (clock *FakeClock) After(d time.Duration) <-chan time.Time {
}
func (clock *FakeClock) NewTicker(d time.Duration) clock.Ticker {
if d <= 0 {
panic(errors.New("duration must be greater than zero"))
}
timer := newFakeTimer(clock, d, true)
clock.addTimeWatcher(timer)
@@ -92,11 +99,21 @@ func (clock *FakeClock) increment(duration time.Duration, waitForWatchers bool,
now := clock.now.Add(duration)
clock.now = now
watchers := make([]timeWatcher, 0, len(clock.watchers))
watchers := make([]timeWatcher, 0)
newWatchers := map[timeWatcher]struct{}{}
for w, _ := range clock.watchers {
watchers = append(watchers, w)
fire := w.shouldFire(now)
if fire {
watchers = append(watchers, w)
}
if !fire || w.repeatable() {
newWatchers[w] = struct{}{}
}
}
clock.watchers = newWatchers
clock.cond.L.Unlock()
for _, w := range watchers {
@@ -106,22 +123,17 @@ func (clock *FakeClock) increment(duration time.Duration, waitForWatchers bool,
func (clock *FakeClock) addTimeWatcher(tw timeWatcher) {
clock.cond.L.Lock()
clock.watchers[tw]++
clock.watchers[tw] = struct{}{}
clock.cond.L.Unlock()
tw.timeUpdated(clock.Now())
// force the timer to fire
clock.Increment(0)
clock.cond.Broadcast()
}
func (clock *FakeClock) removeTimeWatcher(tw timeWatcher) {
clock.cond.L.Lock()
count := clock.watchers[tw]
count--
if count <= 0 {
delete(clock.watchers, tw)
} else {
clock.watchers[tw] = count
}
delete(clock.watchers, tw)
clock.cond.L.Unlock()
}
+26 -17
View File
@@ -31,16 +31,19 @@ func (ft *fakeTimer) C() <-chan time.Time {
return ft.channel
}
func (ft *fakeTimer) Reset(d time.Duration) bool {
func (ft *fakeTimer) reset(d time.Duration) bool {
currentTime := ft.clock.Now()
ft.mutex.Lock()
active := !ft.completionTime.IsZero()
ft.completionTime = currentTime.Add(d)
ft.mutex.Unlock()
return active
}
func (ft *fakeTimer) Reset(d time.Duration) bool {
active := ft.reset(d)
ft.clock.addTimeWatcher(ft)
return active
}
@@ -54,25 +57,31 @@ func (ft *fakeTimer) Stop() bool {
return active
}
func (ft *fakeTimer) timeUpdated(now time.Time) {
var fire bool
func (ft *fakeTimer) shouldFire(now time.Time) bool {
ft.mutex.Lock()
if !ft.completionTime.IsZero() {
fire = now.After(ft.completionTime) || now.Equal(ft.completionTime)
defer ft.mutex.Unlock()
if ft.completionTime.IsZero() {
return false
}
ft.mutex.Unlock()
if fire {
select {
case ft.channel <- now:
ft.Stop()
return now.After(ft.completionTime) || now.Equal(ft.completionTime)
}
default:
}
func (ft *fakeTimer) repeatable() bool {
return ft.repeat
}
if ft.repeat {
ft.Reset(ft.duration)
}
func (ft *fakeTimer) timeUpdated(now time.Time) {
select {
case ft.channel <- now:
default:
// drop on the floor. timers have a buffered channel anyway. according to
// godoc of the `time' package a ticker can loose ticks in case of a slow
// receiver
}
if ft.repeatable() {
ft.reset(ft.duration)
}
}
+1
View File
@@ -0,0 +1 @@
package fakeclock // import "code.cloudfoundry.org/clock/fakeclock"
+1
View File
@@ -0,0 +1 @@
package clock // import "code.cloudfoundry.org/clock"