It("requests for the first set of data from the CC and stores the response", func() {
		var desired map[string]models.DesiredAppState
		var err error
		Eventually(func() interface{} {
			desired, err = store.GetDesiredState()
			return desired
		}, 1, 0.1).ShouldNot(BeEmpty())

		Ω(desired).Should(HaveKey(a1.AppGuid + "," + a1.AppVersion))
		Ω(desired).Should(HaveKey(a2.AppGuid + "," + a2.AppVersion))
		Ω(desired).Should(HaveKey(a3.AppGuid + "," + a3.AppVersion))
	})

	It("bumps the freshness", func() {
		Eventually(func() error {
			_, err := storeAdapter.Get("/hm/v1" + conf.DesiredFreshnessKey)
			return err
		}, 1, 0.1).ShouldNot(HaveOccurred())
	})

	It("reports success to the channel", func() {
		result := <-resultChan
		Ω(result.Success).Should(BeTrue())
		Ω(result.NumResults).Should(Equal(3))
		Ω(result.Message).Should(BeZero())
		Ω(result.Error).ShouldNot(HaveOccurred())
	})

	Context("when fetching again, and apps have been stopped and/or deleted", func() {
		BeforeEach(func() {
			<-resultChan
示例#2
0
			})
		})
	})

	Describe("RunForElection", func() {
		var candidate *elector.Elector

		BeforeEach(func() {
			candidate = elector.NewElector("name", fakeStore, time.Second, logger)
		})

		It("makes a bid to become leader", func() {
			err := candidate.RunForElection()
			Expect(err).NotTo(HaveOccurred())

			node, err := fakeStore.Get("syslog_drain_binder/leader")
			Expect(err).NotTo(HaveOccurred())
			Expect(node.Value).To(BeEquivalentTo("name"))
			Expect(node.TTL).To(Equal(uint64(1)))
		})

		It("sets the IsLeader flag to true", func() {
			candidate.RunForElection()
			Expect(candidate.IsLeader()).To(BeTrue())
		})

		It("re-attempts on an interval if key already exists", func() {
			err := fakeStore.Create(storeadapter.StoreNode{
				Key:   "syslog_drain_binder/leader",
				Value: []byte("some-other-instance"),
			})
示例#3
0
			{Key: "/hm/v2/pokemon/geodude", Value: []byte{}},
			{Key: "/hm/v2/deep-pokemon/abra/kadabra/alakazam", Value: []byte{}},
			{Key: "/hm/v2/pokemonCount", Value: []byte("151")},
			{Key: "/hm/v1/nuke/me/cause/im/an/old/version", Value: []byte("abc")},
			{Key: "/hm/v3/leave/me/alone/since/im/a/new/version", Value: []byte("abc")},
			{Key: "/hm/nuke/me/cause/im/not/versioned", Value: []byte("abc")},
			{Key: "/let/me/be", Value: []byte("abc")},
		})

		storeAdapter.Delete("/hm/v2/pokemon/geodude", "/hm/v2/deep-pokemon/abra/kadabra/alakazam")
		err := shredder.Shred()
		Ω(err).ShouldNot(HaveOccurred())
	})

	It("should delete empty directories", func() {
		_, err := storeAdapter.Get("/hm/v2/pokemon")
		Ω(err).Should(Equal(storeadapter.ErrorKeyNotFound))

		_, err = storeAdapter.Get("/hm/v2/deep-pokemon")
		Ω(err).Should(Equal(storeadapter.ErrorKeyNotFound))

		_, err = storeAdapter.Get("/hm/v2/pokemonCount")
		Ω(err).ShouldNot(HaveOccurred())
	})

	It("should delete everything underneath older versions", func() {
		_, err := storeAdapter.Get("/hm/v1/nuke/me/cause/im/an/old/version")
		Ω(err).Should(Equal(storeadapter.ErrorKeyNotFound))
	})

	It("should delete everything that is not versioned", func() {