示例#1
0
func (db *serviceClient) getAcquiredValue(key string) ([]byte, error) {
	kvPair, _, err := db.consulClient.KV().Get(key, nil)
	if err != nil {
		return nil, err
	}

	if kvPair == nil || kvPair.Session == "" {
		return nil, consuladapter.NewKeyNotFoundError(key)
	}

	return kvPair.Value, nil
}
			})

			It("retrieves the lock data", func() {
				val, err := session.GetAcquiredValue(lockKey)
				Expect(err).NotTo(HaveOccurred())
				Expect(val).To(Equal(lockValue))
			})

			Context("when the session is destroyed", func() {
				BeforeEach(func() {
					session.Destroy()
				})

				It("eventually returns KeyNotFound", func() {
					otherAdapter := clusterRunner.NewSession("otherSession")
					keyNotFound := consuladapter.NewKeyNotFoundError(lockKey)
					Eventually(func() error {
						_, err := otherAdapter.GetAcquiredValue(lockKey)
						return err
					}).Should(Equal(keyNotFound))
				})
			})
		})

		Context("when presence is set", func() {
			BeforeEach(func() {
				_, err := session.SetPresence(presenceKey, presenceValue)
				Expect(err).NotTo(HaveOccurred())
			})

			It("retrieves the presence data", func() {