Skip to content

Commit

Permalink
timeprovider -> clock
Browse files Browse the repository at this point in the history
Signed-off-by: Atul Kshirsagar <[email protected]>
  • Loading branch information
vito authored and atulkc committed Jan 26, 2015
1 parent 7389915 commit c24d57b
Show file tree
Hide file tree
Showing 8 changed files with 37 additions and 37 deletions.
6 changes: 3 additions & 3 deletions cmd/receptor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -146,7 +146,7 @@ func main() {
lrpChangeWatcher := watcher.NewWatcher(
bbs,
hub,
timeprovider.NewTimeProvider(),
clock.NewClock(),
bbsWatchRetryWaitDuration,
logger,
)
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions cmd/receptor/main_suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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())
Expand Down
4 changes: 2 additions & 2 deletions event/eventfakes/fake_hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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))
Expand Down
12 changes: 6 additions & 6 deletions fake_receptor/fake_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand All @@ -178,7 +178,7 @@ type FakeClient struct {
DomainsStub func() ([]string, error)
domainsMutex sync.RWMutex
domainsArgsForCall []struct{}
domainsReturns struct {
domainsReturns struct {
result1 []string
result2 error
}
Expand Down
4 changes: 2 additions & 2 deletions fake_receptor/fake_event_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
4 changes: 2 additions & 2 deletions fake_receptor/fake_raw_event_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down
12 changes: 6 additions & 6 deletions watcher/watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -20,22 +20,22 @@ 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
}

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,
}
Expand All @@ -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()

Expand Down
28 changes: 14 additions & 14 deletions watcher/watcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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() {
Expand Down Expand Up @@ -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))
})
})
Expand All @@ -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))
})
})
Expand Down Expand Up @@ -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))
})
})

Expand All @@ -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))
})
})
})
Expand Down

0 comments on commit c24d57b

Please sign in to comment.