コード例 #1
0
func (expectation transitionExpectation) driveFromState(allocationStore *allocationstore.AllocationStore, container executor.Container) {
	allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags)
	runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags)

	switch expectation.from {
	case "non-existent":

	case "reserved":
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		Expect(err).NotTo(HaveOccurred())

	case "initializing":
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		Expect(err).NotTo(HaveOccurred())

		err = allocationStore.Initialize(logger, &runReq)
		Expect(err).NotTo(HaveOccurred())

	case "failed":
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		Expect(err).NotTo(HaveOccurred())

		err = allocationStore.Initialize(logger, &runReq)
		Expect(err).NotTo(HaveOccurred())

		_, err = allocationStore.Fail(logger, container.Guid, "failure-reason")
		Expect(err).NotTo(HaveOccurred())

	default:
		Fail("unknown 'from' state: " + expectation.from)
	}
}
コード例 #2
0
func (expectation transitionExpectation) transitionToState(allocationStore *allocationstore.AllocationStore, container executor.Container) error {
	switch expectation.to {
	case "reserve":
		allocationRequest := executor.NewAllocationRequest(container.Guid, &container.Resource, container.Tags)
		_, err := allocationStore.Allocate(logger, &allocationRequest)
		return err

	case "initialize":
		runReq := executor.NewRunRequest(container.Guid, &container.RunInfo, container.Tags)
		return allocationStore.Initialize(logger, &runReq)

	case "fail":
		_, err := allocationStore.Fail(logger, container.Guid, "failure-reason")
		return err

	default:
		Fail("unknown 'to' state: " + expectation.to)
		return nil
	}
}
コード例 #3
0
	Describe("Initialize", func() {
		var req executor.AllocationRequest

		BeforeEach(func() {
			resource := executor.NewResource(512, 512, "")
			req = executor.NewAllocationRequest("banana", &resource, nil)

			_, err := allocationStore.Allocate(logger, &req)
			Expect(err).NotTo(HaveOccurred())
		})

		Context("when the guid is available", func() {
			It("it is marked as INITIALIZING", func() {
				runReq := executor.NewRunRequest(req.Guid, &executor.RunInfo{}, executor.Tags{})
				err := allocationStore.Initialize(logger, &runReq)
				Expect(err).NotTo(HaveOccurred())

				allocation, err := allocationStore.Lookup(req.Guid)
				Expect(err).NotTo(HaveOccurred())

				Expect(allocation.Guid).To(Equal(req.Guid))
				Expect(allocation.State).To(Equal(executor.StateInitializing))
			})
		})

		Context("when the guid is not available", func() {
			It("errors", func() {
				runReq := executor.NewRunRequest("doesnt-exist", &executor.RunInfo{}, executor.Tags{})
				err := allocationStore.Initialize(logger, &runReq)
				Expect(err).To(HaveOccurred())