コード例 #1
0
ファイル: service_client.go プロジェクト: timani/bbs
func (db *serviceClient) NewBBSLockRunner(logger lager.Logger, bbsPresence *models.BBSPresence, retryInterval, lockTTL time.Duration) (ifrit.Runner, error) {
	bbsPresenceJSON, err := models.ToJSON(bbsPresence)
	if err != nil {
		return nil, err
	}
	return locket.NewLock(logger, db.consulClient, locket.LockSchemaPath("bbs_lock"), bbsPresenceJSON, db.clock, retryInterval, lockTTL), nil
}
コード例 #2
0
func (c serviceClient) NewAuctioneerLockRunner(logger lager.Logger, presence Presence, retryInterval time.Duration) (ifrit.Runner, error) {
	if err := presence.Validate(); err != nil {
		return nil, err
	}

	payload, err := json.Marshal(presence)
	if err != nil {
		return nil, err
	}
	return locket.NewLock(c.session, LockSchemaPath(), payload, c.clock, retryInterval, logger), nil
}
コード例 #3
0
ファイル: main_test.go プロジェクト: cfibmers/nsync
		AfterEach(func() {
			ginkgomon.Interrupt(process, interruptTimeout)
		})

		It("exits with an error", func() {
			Eventually(process.Wait(), 5*domainTTL).Should(Receive(HaveOccurred()))
		})
	})

	Context("when the bulker initially does not have the lock", func() {
		var nsyncLockClaimerProcess ifrit.Process

		BeforeEach(func() {
			heartbeatInterval = 1 * time.Second

			nsyncLockClaimer := locket.NewLock(logger, consulRunner.NewClient(), locket.LockSchemaPath(bulkerLockName), []byte("something-else"), clock.NewClock(), locket.RetryInterval, locket.LockTTL)
			nsyncLockClaimerProcess = ifrit.Invoke(nsyncLockClaimer)
		})

		JustBeforeEach(func() {
			process = startBulker(false)
		})

		AfterEach(func() {
			ginkgomon.Interrupt(process, interruptTimeout)
			ginkgomon.Kill(nsyncLockClaimerProcess)
		})

		It("does not make any requests", func() {
			Consistently(func() int {
				return len(fakeBBS.ReceivedRequests())
コード例 #4
0
ファイル: service_client.go プロジェクト: emc-xchallenge/tps
func (c serviceClient) NewTPSWatcherLockRunner(logger lager.Logger, emitterID string, retryInterval time.Duration) ifrit.Runner {
	return locket.NewLock(c.session, TPSWatcherLockSchemaPath(), []byte(emitterID), c.clock, retryInterval, logger)
}
コード例 #5
0
ファイル: master_lock_test.go プロジェクト: timani/bbs
import (
	"github.com/cloudfoundry-incubator/bbs/cmd/bbs/testrunner"
	"github.com/cloudfoundry-incubator/locket"
	"github.com/pivotal-golang/clock"
	"github.com/tedsuo/ifrit"
	"github.com/tedsuo/ifrit/ginkgomon"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("MasterLock", func() {
	Context("when the bbs cannot obtain the bbs lock", func() {
		var competingBBSLockProcess ifrit.Process
		BeforeEach(func() {
			competingBBSLock := locket.NewLock(logger, consulClient, locket.LockSchemaPath("bbs_lock"), []byte{}, clock.NewClock(), locket.RetryInterval, locket.LockTTL)
			competingBBSLockProcess = ifrit.Invoke(competingBBSLock)

			bbsRunner = testrunner.New(bbsBinPath, bbsArgs)
			bbsRunner.StartCheck = "bbs.lock.acquiring-lock"

			bbsProcess = ginkgomon.Invoke(bbsRunner)
		})

		AfterEach(func() {
			ginkgomon.Kill(competingBBSLockProcess)
		})

		It("is not reachable", func() {
			_, err := client.Domains(logger)
			Expect(err).To(HaveOccurred())
コード例 #6
0
ファイル: main_test.go プロジェクト: cfibmers/auctioneer
	Context("when the auctioneer cannot acquire the lock on startup", func() {
		var task *rep.Task
		var competingAuctioneerProcess ifrit.Process

		BeforeEach(func() {
			task = &rep.Task{
				TaskGuid: "task-guid",
				Domain:   "test",
				Resource: rep.Resource{
					MemoryMB: 124,
					DiskMB:   456,
					RootFs:   "some-rootfs",
				},
			}

			competingAuctioneerLock := locket.NewLock(logger, consulClient, locket.LockSchemaPath("auctioneer_lock"), []byte{}, clock.NewClock(), 500*time.Millisecond, 10*time.Second)
			competingAuctioneerProcess = ifrit.Invoke(competingAuctioneerLock)

			runner.StartCheck = "auctioneer.lock-bbs.lock.acquiring-lock"

			auctioneerProcess = ifrit.Background(runner)
		})

		AfterEach(func() {
			ginkgomon.Kill(competingAuctioneerProcess)
		})

		It("should not advertise its presence, and should not be reachable", func() {
			Eventually(func() error {
				return auctioneerClient.RequestTaskAuctions([]*auctioneer.TaskStartRequest{
					&auctioneer.TaskStartRequest{*task},
コード例 #7
0
ファイル: service_client.go プロジェクト: cf-routing/nsync
func (c serviceClient) NewNsyncBulkerLockRunner(logger lager.Logger, bulkerID string, retryInterval, lockTTL time.Duration) ifrit.Runner {
	return locket.NewLock(logger, c.consulClient, NysncBulkerLockSchemaPath(), []byte(bulkerID), c.clock, retryInterval, lockTTL)
}