コード例 #1
0
ファイル: evacuator_test.go プロジェクト: cgrotz/hm9000
	BeforeEach(func() {
		storeAdapter = fakestoreadapter.New()
		messageBus = fakeyagnats.Connect()
		store = storepackage.NewStore(conf, storeAdapter, fakelogger.NewFakeLogger())
		timeProvider = &faketimeprovider.FakeTimeProvider{
			TimeToProvide: time.Unix(100, 0),
		}

		app = appfixture.NewAppFixture()

		evacuator = New(messageBus, store, timeProvider, conf, fakelogger.NewFakeLogger())
		evacuator.Listen()
	})

	It("should be listening on the message bus for droplet.exited", func() {
		Ω(messageBus.SubjectCallbacks("droplet.exited")).ShouldNot(BeNil())
	})

	Context("when droplet.exited is received", func() {
		Context("when the message is malformed", func() {
			It("does nothing", func() {
				messageBus.SubjectCallbacks("droplet.exited")[0](&nats.Msg{
					Data: []byte("ß"),
				})

				pendingStarts, err := store.GetPendingStartMessages()
				Ω(err).ShouldNot(HaveOccurred())
				Ω(pendingStarts).Should(BeEmpty())
			})
		})
コード例 #2
0
		messageBus = fakeyagnats.Connect()
		logger = fakelogger.NewFakeLogger()

		usageTracker = &fakemetricsaccountant.FakeUsageTracker{}
		usageTracker.MeasureUsageReturns(0.7, 0)
		metricsAccountant = &fakemetricsaccountant.FakeMetricsAccountant{}
	})

	JustBeforeEach(func() {
		listener = New(conf, messageBus, store, usageTracker, metricsAccountant, clock, logger)
		listener.Start()
	})

	beat := func() {
		messageBus.SubjectCallbacks("dea.heartbeat")[0](&nats.Msg{
			Data: app.Heartbeat(1).ToJSON(),
		})
	}

	It("To subscribe to the dea.heartbeat subject", func() {
		Expect(messageBus.Subscriptions("dea.heartbeat")).To(HaveLen(1))
	})

	It("To subscribe to the dea.advertise subject", func() {
		Expect(messageBus.Subscriptions("dea.advertise")).NotTo(BeNil())
		Expect(messageBus.Subscriptions("dea.advertise")).To(HaveLen(1))
	})

	It("To start tracking store usage", func() {
		Expect(usageTracker.StartTrackingUsageCallCount()).To(Equal(1))
		Expect(usageTracker.MeasureUsageCallCount()).To(Equal(1))