From c24d57b9c3b97f2cd7fe7a8cda48ca8ddf36cc73 Mon Sep 17 00:00:00 2001 From: Alex Suraci Date: Mon, 26 Jan 2015 10:49:00 -0800 Subject: [PATCH] timeprovider -> clock Signed-off-by: Atul Kshirsagar --- cmd/receptor/main.go | 6 +++--- cmd/receptor/main_suite_test.go | 4 ++-- event/eventfakes/fake_hub.go | 4 ++-- fake_receptor/fake_client.go | 12 +++++------ fake_receptor/fake_event_source.go | 4 ++-- fake_receptor/fake_raw_event_source.go | 4 ++-- watcher/watcher.go | 12 +++++------ watcher/watcher_test.go | 28 +++++++++++++------------- 8 files changed, 37 insertions(+), 37 deletions(-) diff --git a/cmd/receptor/main.go b/cmd/receptor/main.go index 5fb0da7..65cf327 100644 --- a/cmd/receptor/main.go +++ b/cmd/receptor/main.go @@ -22,10 +22,10 @@ import ( "github.com/cloudfoundry-incubator/runtime-schema/models" "github.com/cloudfoundry/dropsonde" "github.com/cloudfoundry/gunk/diegonats" - "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/gunk/workpool" "github.com/cloudfoundry/storeadapter/etcdstoreadapter" "github.com/nu7hatch/gouuid" + "github.com/pivotal-golang/clock" "github.com/pivotal-golang/lager" "github.com/pivotal-golang/localip" "github.com/tedsuo/ifrit" @@ -146,7 +146,7 @@ func main() { lrpChangeWatcher := watcher.NewWatcher( bbs, hub, - timeprovider.NewTimeProvider(), + clock.NewClock(), bbsWatchRetryWaitDuration, logger, ) @@ -233,7 +233,7 @@ func initializeReceptorBBS(logger lager.Logger) Bbs.ReceptorBBS { logger.Fatal("failed-to-connect-to-etcd", err) } - return Bbs.NewReceptorBBS(etcdAdapter, timeprovider.NewTimeProvider(), logger) + return Bbs.NewReceptorBBS(etcdAdapter, clock.NewClock(), logger) } func initializeServerRegistration(logger lager.Logger) (registration natbeat.RegistryMessage) { diff --git a/cmd/receptor/main_suite_test.go b/cmd/receptor/main_suite_test.go index 11a2651..42af38b 100644 --- a/cmd/receptor/main_suite_test.go +++ b/cmd/receptor/main_suite_test.go @@ -10,12 +10,12 @@ import ( Bbs "github.com/cloudfoundry-incubator/runtime-schema/bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" "github.com/cloudfoundry/gunk/diegonats" - "github.com/cloudfoundry/gunk/timeprovider" "github.com/cloudfoundry/storeadapter" "github.com/cloudfoundry/storeadapter/storerunner/etcdstorerunner" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/onsi/gomega/gexec" + "github.com/pivotal-golang/clock" "github.com/pivotal-golang/lager" "github.com/pivotal-golang/lager/lagertest" "github.com/tedsuo/ifrit" @@ -91,7 +91,7 @@ var _ = BeforeEach(func() { etcdRunner.Start() etcdAdapter = etcdRunner.Adapter() - bbs = Bbs.NewBBS(etcdAdapter, timeprovider.NewTimeProvider(), models.NewDefaultRestartCalculator(), logger) + bbs = Bbs.NewBBS(etcdAdapter, clock.NewClock(), models.NewDefaultRestartCalculator(), logger) receptorAddress = fmt.Sprintf("127.0.0.1:%d", 6700+GinkgoParallelNode()) receptorTaskHandlerAddress = fmt.Sprintf("127.0.0.1:%d", 1169+GinkgoParallelNode()) diff --git a/event/eventfakes/fake_hub.go b/event/eventfakes/fake_hub.go index 6e51c3b..f47fc16 100644 --- a/event/eventfakes/fake_hub.go +++ b/event/eventfakes/fake_hub.go @@ -12,7 +12,7 @@ type FakeHub struct { SubscribeStub func() (receptor.EventSource, error) subscribeMutex sync.RWMutex subscribeArgsForCall []struct{} - subscribeReturns struct { + subscribeReturns struct { result1 receptor.EventSource result2 error } @@ -24,7 +24,7 @@ type FakeHub struct { CloseStub func() error closeMutex sync.RWMutex closeArgsForCall []struct{} - closeReturns struct { + closeReturns struct { result1 error } RegisterCallbackStub func(func(count int)) diff --git a/fake_receptor/fake_client.go b/fake_receptor/fake_client.go index adf6e77..c72b970 100644 --- a/fake_receptor/fake_client.go +++ b/fake_receptor/fake_client.go @@ -20,7 +20,7 @@ type FakeClient struct { TasksStub func() ([]receptor.TaskResponse, error) tasksMutex sync.RWMutex tasksArgsForCall []struct{} - tasksReturns struct { + tasksReturns struct { result1 []receptor.TaskResponse result2 error } @@ -95,7 +95,7 @@ type FakeClient struct { DesiredLRPsStub func() ([]receptor.DesiredLRPResponse, error) desiredLRPsMutex sync.RWMutex desiredLRPsArgsForCall []struct{} - desiredLRPsReturns struct { + desiredLRPsReturns struct { result1 []receptor.DesiredLRPResponse result2 error } @@ -111,7 +111,7 @@ type FakeClient struct { ActualLRPsStub func() ([]receptor.ActualLRPResponse, error) actualLRPsMutex sync.RWMutex actualLRPsArgsForCall []struct{} - actualLRPsReturns struct { + actualLRPsReturns struct { result1 []receptor.ActualLRPResponse result2 error } @@ -155,14 +155,14 @@ type FakeClient struct { SubscribeToEventsStub func() (receptor.EventSource, error) subscribeToEventsMutex sync.RWMutex subscribeToEventsArgsForCall []struct{} - subscribeToEventsReturns struct { + subscribeToEventsReturns struct { result1 receptor.EventSource result2 error } CellsStub func() ([]receptor.CellResponse, error) cellsMutex sync.RWMutex cellsArgsForCall []struct{} - cellsReturns struct { + cellsReturns struct { result1 []receptor.CellResponse result2 error } @@ -178,7 +178,7 @@ type FakeClient struct { DomainsStub func() ([]string, error) domainsMutex sync.RWMutex domainsArgsForCall []struct{} - domainsReturns struct { + domainsReturns struct { result1 []string result2 error } diff --git a/fake_receptor/fake_event_source.go b/fake_receptor/fake_event_source.go index 0162497..51a3032 100644 --- a/fake_receptor/fake_event_source.go +++ b/fake_receptor/fake_event_source.go @@ -11,14 +11,14 @@ type FakeEventSource struct { NextStub func() (receptor.Event, error) nextMutex sync.RWMutex nextArgsForCall []struct{} - nextReturns struct { + nextReturns struct { result1 receptor.Event result2 error } CloseStub func() error closeMutex sync.RWMutex closeArgsForCall []struct{} - closeReturns struct { + closeReturns struct { result1 error } } diff --git a/fake_receptor/fake_raw_event_source.go b/fake_receptor/fake_raw_event_source.go index aa9866a..1fbdc07 100644 --- a/fake_receptor/fake_raw_event_source.go +++ b/fake_receptor/fake_raw_event_source.go @@ -12,14 +12,14 @@ type FakeRawEventSource struct { NextStub func() (sse.Event, error) nextMutex sync.RWMutex nextArgsForCall []struct{} - nextReturns struct { + nextReturns struct { result1 sse.Event result2 error } CloseStub func() error closeMutex sync.RWMutex closeArgsForCall []struct{} - closeReturns struct { + closeReturns struct { result1 error } } diff --git a/watcher/watcher.go b/watcher/watcher.go index 7da1a59..c0ed95f 100644 --- a/watcher/watcher.go +++ b/watcher/watcher.go @@ -10,7 +10,7 @@ import ( "github.com/cloudfoundry-incubator/receptor/serialization" "github.com/cloudfoundry-incubator/runtime-schema/bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" - "github.com/cloudfoundry/gunk/timeprovider" + "github.com/pivotal-golang/clock" "github.com/pivotal-golang/lager" "github.com/tedsuo/ifrit" ) @@ -20,7 +20,7 @@ type Watcher ifrit.Runner type watcher struct { bbs bbs.ReceptorBBS hub event.Hub - timeProvider timeprovider.TimeProvider + clock clock.Clock retryWaitDuration time.Duration logger lager.Logger } @@ -28,14 +28,14 @@ type watcher struct { func NewWatcher( bbs bbs.ReceptorBBS, hub event.Hub, - timeProvider timeprovider.TimeProvider, + clock clock.Clock, retryWaitDuration time.Duration, logger lager.Logger, ) Watcher { return &watcher{ bbs: bbs, hub: hub, - timeProvider: timeProvider, + clock: clock, retryWaitDuration: retryWaitDuration, logger: logger, } @@ -61,11 +61,11 @@ func (w *watcher) Run(signals <-chan os.Signal, ready chan<- struct{}) error { var desiredStop, actualStop chan<- bool var desiredErrors, actualErrors <-chan error - reWatchTimerDesired := w.timeProvider.NewTimer(w.retryWaitDuration) + reWatchTimerDesired := w.clock.NewTimer(w.retryWaitDuration) defer reWatchTimerDesired.Stop() reWatchTimerDesired.Stop() - reWatchTimerActual := w.timeProvider.NewTimer(w.retryWaitDuration) + reWatchTimerActual := w.clock.NewTimer(w.retryWaitDuration) defer reWatchTimerActual.Stop() reWatchTimerActual.Stop() diff --git a/watcher/watcher_test.go b/watcher/watcher_test.go index 4f7f295..0216222 100644 --- a/watcher/watcher_test.go +++ b/watcher/watcher_test.go @@ -11,9 +11,9 @@ import ( "github.com/cloudfoundry-incubator/receptor/watcher" "github.com/cloudfoundry-incubator/runtime-schema/bbs/fake_bbs" "github.com/cloudfoundry-incubator/runtime-schema/models" - "github.com/cloudfoundry/gunk/timeprovider/faketimeprovider" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" + "github.com/pivotal-golang/clock/fakeclock" "github.com/pivotal-golang/lager/lagertest" "github.com/tedsuo/ifrit" ) @@ -28,7 +28,7 @@ var _ = Describe("Watcher", func() { var ( bbs *fake_bbs.FakeReceptorBBS hub *eventfakes.FakeHub - timeProvider *faketimeprovider.FakeTimeProvider + clock *fakeclock.FakeClock receptorWatcher watcher.Watcher process ifrit.Process @@ -42,7 +42,7 @@ var _ = Describe("Watcher", func() { BeforeEach(func() { bbs = new(fake_bbs.FakeReceptorBBS) hub = new(eventfakes.FakeHub) - timeProvider = faketimeprovider.New(time.Now()) + clock = fakeclock.NewFakeClock(time.Now()) logger := lagertest.NewTestLogger("test") desiredLRPStop = make(chan bool, 1) @@ -54,7 +54,7 @@ var _ = Describe("Watcher", func() { bbs.WatchForDesiredLRPChangesReturns(desiredLRPStop, desiredLRPErrors) bbs.WatchForActualLRPChangesReturns(actualLRPStop, actualLRPErrors) - receptorWatcher = watcher.NewWatcher(bbs, hub, timeProvider, retryWaitDuration, logger) + receptorWatcher = watcher.NewWatcher(bbs, hub, clock, retryWaitDuration, logger) }) AfterEach(func() { @@ -121,22 +121,22 @@ var _ = Describe("Watcher", func() { }) It("requests a new desired watch after the retry interval", func() { - timeProvider.Increment(retryWaitDuration / 2) + clock.Increment(retryWaitDuration / 2) Consistently(bbs.WatchForDesiredLRPChangesCallCount).Should(Equal(1)) - timeProvider.Increment(retryWaitDuration * 2) + clock.Increment(retryWaitDuration * 2) Eventually(bbs.WatchForDesiredLRPChangesCallCount).Should(Equal(2)) }) Context("and the hub reports no subscribers before the retry interval elapses", func() { BeforeEach(func() { - timeProvider.Increment(retryWaitDuration / 2) + clock.Increment(retryWaitDuration / 2) callback(0) // give watcher time to clear out event loop time.Sleep(10 * time.Millisecond) }) It("does not request new watches", func() { - timeProvider.Increment(retryWaitDuration * 2) + clock.Increment(retryWaitDuration * 2) Consistently(bbs.WatchForDesiredLRPChangesCallCount).Should(Equal(1)) }) }) @@ -148,22 +148,22 @@ var _ = Describe("Watcher", func() { }) It("requests a new actual watch after the retry interval", func() { - timeProvider.Increment(retryWaitDuration / 2) + clock.Increment(retryWaitDuration / 2) Consistently(bbs.WatchForActualLRPChangesCallCount).Should(Equal(1)) - timeProvider.Increment(retryWaitDuration * 2) + clock.Increment(retryWaitDuration * 2) Eventually(bbs.WatchForActualLRPChangesCallCount).Should(Equal(2)) }) Context("and the hub reports no subscribers before the retry interval elapses", func() { BeforeEach(func() { - timeProvider.Increment(retryWaitDuration / 2) + clock.Increment(retryWaitDuration / 2) callback(0) // give watcher time to clear out event loop time.Sleep(10 * time.Millisecond) }) It("does not request new watches", func() { - timeProvider.Increment(retryWaitDuration * 2) + clock.Increment(retryWaitDuration * 2) Consistently(bbs.WatchForActualLRPChangesCallCount).Should(Equal(1)) }) }) @@ -207,7 +207,7 @@ var _ = Describe("Watcher", func() { Eventually(bbs.WatchForDesiredLRPChangesCallCount).Should(Equal(2)) desiredLRPErrors <- errors.New("second error") - Consistently(timeProvider.WatcherCount).Should(Equal(1)) + Consistently(clock.WatcherCount).Should(Equal(1)) }) }) @@ -225,7 +225,7 @@ var _ = Describe("Watcher", func() { Eventually(bbs.WatchForActualLRPChangesCallCount).Should(Equal(2)) actualLRPErrors <- errors.New("second error") - Consistently(timeProvider.WatcherCount).Should(Equal(1)) + Consistently(clock.WatcherCount).Should(Equal(1)) }) }) })