Exemple #1
0
func insertTask(db *sql.DB, serializer format.Serializer, task *models.Task, malformedTaskDefinition bool) {
	taskDefData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, task.TaskDefinition)
	Expect(err).NotTo(HaveOccurred())

	if malformedTaskDefinition {
		taskDefData = []byte("{{{{{{{{{{")
	}

	queryStr := `INSERT INTO tasks
						  (guid, domain, created_at, updated_at, first_completed_at, state,
							cell_id, result, failed, failure_reason, task_definition)
					    VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`
	if test_helpers.UsePostgres() {
		queryStr = test_helpers.ReplaceQuestionMarks(queryStr)
	}
	result, err := db.Exec(
		queryStr,
		task.TaskGuid,
		task.Domain,
		task.CreatedAt,
		task.UpdatedAt,
		task.FirstCompletedAt,
		task.State,
		task.CellId,
		task.Result,
		task.Failed,
		task.FailureReason,
		taskDefData,
	)
	Expect(err).NotTo(HaveOccurred())
	Expect(result.RowsAffected()).NotTo(Equal(1))
}
Exemple #2
0
			}, nil
		}
		cryptor.DecryptStub = func(ciphered encryption.Encrypted) ([]byte, error) {
			return ciphered.CipherText, nil
		}
		encoder = format.NewEncoder(cryptor)
		serializer = format.NewSerializer(cryptor)
	})

	Describe("Marshal", func() {
		Describe("LEGACY_FORMATTING", func() {
			It("marshals the data as-is without an envelope", func() {
				jsonEncodedTask, err := json.Marshal(task)
				Expect(err).NotTo(HaveOccurred())

				encoded, err := serializer.Marshal(logger, format.LEGACY_FORMATTING, task)
				Expect(err).NotTo(HaveOccurred())
				Expect(encoded).To(MatchJSON(jsonEncodedTask))
			})
		})

		Describe("FORMATTED_JSON", func() {
			It("marshals the data as json with an UNENCODED envelope", func() {
				jsonEncodedTask, err := json.Marshal(task)
				Expect(err).NotTo(HaveOccurred())

				encoded, err := serializer.Marshal(logger, format.FORMATTED_JSON, task)
				Expect(err).NotTo(HaveOccurred())

				unencoded, err := encoder.Decode(encoded)
				Expect(err).NotTo(HaveOccurred())
	Describe("Up", func() {
		var (
			task         *models.Task
			migrationErr error
		)

		Describe("Task Migration", func() {
			BeforeEach(func() {
				task = model_helpers.NewValidTask("task-guid-1")
				task.Action = models.WrapAction(&models.TimeoutAction{Action: model_helpers.NewValidAction(),
					DeprecatedTimeoutNs: 5 * int64(time.Second),
				})
			})

			JustBeforeEach(func() {
				taskData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, task)
				Expect(err).NotTo(HaveOccurred())
				_, err = storeClient.Set(etcddb.TaskSchemaPath(task), taskData, 0)
				Expect(err).NotTo(HaveOccurred())

				migration.SetStoreClient(storeClient)
				migration.SetCryptor(cryptor)
				migration.SetClock(fakeClock)
				migrationErr = migration.Up(logger)
			})

			It("changes task timeoutAction timeout to milliseconds", func() {
				Expect(migrationErr).NotTo(HaveOccurred())
				newTask, err := db.TaskByGuid(logger, task.TaskGuid)
				Expect(err).NotTo(HaveOccurred())
				Expect(newTask.Action.GetTimeoutAction().GetTimeoutMs()).To(Equal(int64(5000)))
				desiredLRPsToCreate = 3
				for i := 0; i < desiredLRPsToCreate; i++ {
					processGuid := fmt.Sprintf("process-guid-%d", i)
					var desiredLRP *models.DesiredLRP
					desiredLRP = model_helpers.NewValidDesiredLRP(processGuid)

					schedulingInfo, runInfo := desiredLRP.CreateComponents(fakeClock.Now())

					var (
						encryptedVolumePlacement []byte
						err                      error
					)
					if i == 0 { // test for nil and full VolumePlacements
						schedulingInfo.VolumePlacement = nil
						encryptedVolumePlacement, err = serializer.Marshal(logger, format.ENCRYPTED_PROTO, &models.VolumePlacement{})
					} else {
						encryptedVolumePlacement, err = serializer.Marshal(logger, format.ENCRYPTED_PROTO, schedulingInfo.VolumePlacement)
					}
					Expect(err).NotTo(HaveOccurred())

					volumePlacementData, err := encoder.Decode(encryptedVolumePlacement)
					Expect(err).NotTo(HaveOccurred())

					routesData, err := json.Marshal(desiredLRP.Routes)
					Expect(err).NotTo(HaveOccurred())

					schedInfoData, err := serializer.Marshal(logger, format.ENCRYPTED_PROTO, &schedulingInfo)
					Expect(err).NotTo(HaveOccurred())
					_, err = storeClient.Set(etcddb.DesiredLRPSchedulingInfoSchemaPath(processGuid), schedInfoData, 0)
					Expect(err).NotTo(HaveOccurred())