예제 #1
0
파일: sqldb.go 프로젝트: cloudfoundry/bbs
func (db *SQLDB) convertPostgresError(err *pq.Error) *models.Error {
	switch err.Code {
	case "22001":
		return models.ErrBadRequest
	case "23505":
		return models.ErrResourceExists
	case "42P01":
		return models.NewUnrecoverableError(err)
	default:
		return models.ErrUnknownError
	}
}
예제 #2
0
파일: sqldb.go 프로젝트: cloudfoundry/bbs
func (db *SQLDB) convertMySQLError(err *mysql.MySQLError) *models.Error {
	switch err.Number {
	case 1062:
		return models.ErrResourceExists
	case 1213:
		return models.ErrDeadlock
	case 1406:
		return models.ErrBadRequest
	case 1146:
		return models.NewUnrecoverableError(err)
	default:
		return models.ErrUnknownError
	}

	return nil
}
		changeEvents := []*models.ActualLRPChangedEvent{}
		for i := 0; i < actualHub.EmitCallCount(); i++ {
			event := actualHub.EmitArgsForCall(i)
			if changeEvent, ok := event.(*models.ActualLRPChangedEvent); ok {
				changeEvents = append(changeEvents, changeEvent)
			}
		}
		group1 := &models.ActualLRPGroup{Instance: unclaimingActualLRP1}
		group2 := &models.ActualLRPGroup{Instance: unclaimingActualLRP2}
		Expect(changeEvents).To(ContainElement(models.NewActualLRPChangedEvent(group1, group1)))
		Expect(changeEvents).To(ContainElement(models.NewActualLRPChangedEvent(group2, group2)))
	})

	Context("when the DB returns an unrecoverable error", func() {
		BeforeEach(func() {
			fakeLRPDB.UnclaimActualLRPReturns(nil, nil, models.NewUnrecoverableError(nil))
		})

		It("logs the error", func() {
			Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
		})

		It("returns the error", func() {
			Expect(err).To(HaveOccurred())
			Expect(err).Should(Equal(models.NewUnrecoverableError(nil)))
		})
	})

	Context("when unclaiming the actual lrp fails", func() {
		BeforeEach(func() {
			fakeLRPDB.UnclaimActualLRPReturns(nil, nil, errors.New("terrrible"))
예제 #4
0
			})

			It("returns an empty list", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
				response := models.DesiredLRPsResponse{}
				err := response.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).To(BeNil())
				Expect(response.DesiredLrps).To(BeEmpty())
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				fakeDesiredLRPDB.DesiredLRPsReturns([]*models.DesiredLRP{}, models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when the DB errors out", func() {
			BeforeEach(func() {
				fakeDesiredLRPDB.DesiredLRPsReturns([]*models.DesiredLRP{}, models.ErrUnknownError)
			})

			It("provides relevant error information", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
예제 #5
0
			It("returns an empty list", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))

				response := &models.CellsResponse{}
				err := response.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).To(BeNil())
				Expect(response.Cells).To(BeNil())
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				fakeServiceClient.CellsReturns(nil, models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when the serviceClient errors out", func() {
			BeforeEach(func() {
				fakeServiceClient.CellsReturns(nil, models.ErrUnknownError)
			})

			It("provides relevant error information", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
예제 #6
0
			It("responds with an error", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))

				var upsertDomainResponse models.UpsertDomainResponse
				err := upsertDomainResponse.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(upsertDomainResponse.Error).NotTo(BeNil())
				Expect(upsertDomainResponse.Error).To(Equal(models.ErrBadRequest))
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				fakeDomainDB.UpsertDomainReturns(models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when the DB errors out", func() {
			BeforeEach(func() {
				fakeDomainDB.UpsertDomainReturns(models.ErrUnknownError)
			})

			It("provides relevant error information", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
					fakeActualLRPDB.ClaimActualLRPReturns(
						&models.ActualLRPGroup{Instance: &afterActualLRP},
						&models.ActualLRPGroup{Instance: &afterActualLRP},
						nil,
					)
				})

				It("does not emit a change event to the hub", func() {
					Eventually(actualHub.EmitCallCount).Should(Equal(0))
				})
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				fakeActualLRPDB.ClaimActualLRPReturns(nil, nil, models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when claiming the actual lrp fails", func() {
			BeforeEach(func() {
				fakeActualLRPDB.ClaimActualLRPReturns(nil, nil, models.ErrUnknownError)
			})

			It("responds with an error", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
예제 #8
0
				BeforeEach(func() {
					cellId = "cell-id"
				})

				It("calls the controller with a cell filter", func() {
					Expect(controller.TasksCallCount()).To(Equal(1))
					_, actualDomain, actualCellId := controller.TasksArgsForCall(0)
					Expect(actualDomain).To(Equal(domain))
					Expect(actualCellId).To(Equal(cellId))
				})
			})
		})

		Context("when the controller returns an unrecoverable error", func() {
			BeforeEach(func() {
				controller.TasksReturns(nil, models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when the controller errors out", func() {
			BeforeEach(func() {
				controller.TasksReturns(nil, models.ErrUnknownError)
			})

			It("provides relevant error information", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
			})

			It("returns an empty list", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
				response := models.DesiredLRPsResponse{}
				err := response.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).To(BeNil())
				Expect(response.DesiredLrps).To(BeEmpty())
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				fakeDesiredLRPDB.DesiredLRPsReturns([]*models.DesiredLRP{}, models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when the DB errors out", func() {
			BeforeEach(func() {
				fakeDesiredLRPDB.DesiredLRPsReturns([]*models.DesiredLRP{}, models.ErrUnknownError)
			})

			It("provides relevant error information", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
					Expect(responseRecorder.Code).To(Equal(http.StatusOK))
					response := models.TasksResponse{}
					err := response.Unmarshal(responseRecorder.Body.Bytes())
					Expect(err).NotTo(HaveOccurred())

					Expect(response.Error).To(BeNil())
					Expect(response.Tasks).To(HaveLen(2))
					Expect(response.Tasks[0]).To(Equal(task1.VersionDownTo(format.V0)))
					Expect(response.Tasks[1]).To(Equal(task2.VersionDownTo(format.V0)))
				})
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				controller.TasksReturns(nil, models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when the DB errors out", func() {
			BeforeEach(func() {
				controller.TasksReturns(nil, models.ErrUnknownError)
			})

			It("provides relevant error information", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
예제 #11
0
			})

			It("returns an empty list", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
				response := &models.ActualLRPGroupsResponse{}
				err := response.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).To(BeNil())
				Expect(response.ActualLrpGroups).To(BeNil())
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				fakeActualLRPDB.ActualLRPGroupsReturns([]*models.ActualLRPGroup{}, models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when the DB errors out", func() {
			BeforeEach(func() {
				fakeActualLRPDB.ActualLRPGroupsReturns([]*models.ActualLRPGroup{}, models.ErrUnknownError)
			})

			It("provides relevant error information", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))
예제 #12
0
			It("responds with an error", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))

				var response models.RemoveEvacuatingActualLRPResponse
				err := response.Unmarshal(responseRecorder.Body.Bytes())
				Expect(err).NotTo(HaveOccurred())

				Expect(response.Error).NotTo(BeNil())
				Expect(response.Error).To(Equal(models.ErrBadRequest))
			})
		})

		Context("when the DB returns an unrecoverable error", func() {
			BeforeEach(func() {
				fakeEvacuationDB.RemoveEvacuatingActualLRPReturns(models.NewUnrecoverableError(nil))
			})

			It("logs and writes to the exit channel", func() {
				Eventually(logger).Should(gbytes.Say("unrecoverable-error"))
				Eventually(exitCh).Should(Receive())
			})
		})

		Context("when DB errors out", func() {
			BeforeEach(func() {
				fakeEvacuationDB.RemoveEvacuatingActualLRPReturns(models.ErrUnknownError)
			})

			It("responds with an error", func() {
				Expect(responseRecorder.Code).To(Equal(http.StatusOK))