Example #1
0
			createsCh := make(chan *models.ActualLRPGroup)
			creates = createsCh

			changesCh := make(chan *models.ActualLRPChange)
			changes = changesCh

			deletesCh := make(chan *models.ActualLRPGroup)
			deletes = deletesCh

			stop, errors = etcdDB.WatchForActualLRPChanges(logger,
				func(created *models.ActualLRPGroup) { createsCh <- created },
				func(changed *models.ActualLRPChange) { changesCh <- changed },
				func(deleted *models.ActualLRPGroup) { deletesCh <- deleted },
			)

			actualLRP := models.NewUnclaimedActualLRP(models.NewActualLRPKey(lrpProcessGuid, lrpIndex, lrpDomain), clock.Now().UnixNano())
			actualLRPGroup = models.NewRunningActualLRPGroup(actualLRP)
		})

		AfterEach(func() {
			close(stop)
			Consistently(errors).ShouldNot(Receive())
			Eventually(errors).Should(BeClosed())
		})

		It("sends an event down the pipe for create", func() {
			etcdHelper.SetRawActualLRP(actualLRPGroup.Instance)
			Eventually(creates).Should(Receive(Equal(actualLRPGroup)))
		})

		It("sends an event down the pipe for updates", func() {
Example #2
0
					event, err := eventSource.Next()
					Expect(err).NotTo(HaveOccurred())

					desiredLRPRemovedEvent, ok := event.(*models.DesiredLRPRemovedEvent)
					Expect(ok).To(BeTrue())
					Expect(desiredLRPRemovedEvent).To(Equal(expectedEvent))
				})
			})
		})

		Describe("Actual LRP Events", func() {
			var actualLRPGroup *models.ActualLRPGroup
			var actualLRP *models.ActualLRP

			BeforeEach(func() {
				actualLRP = models.NewUnclaimedActualLRP(models.NewActualLRPKey("some-guid", 0, "some-domain"), 1)
				actualLRPGroup = models.NewRunningActualLRPGroup(actualLRP)
			})

			Context("when receiving a ActualLRPCreatedEvent", func() {
				var expectedEvent *models.ActualLRPCreatedEvent

				BeforeEach(func() {
					expectedEvent = models.NewActualLRPCreatedEvent(actualLRPGroup)
					payload, err := proto.Marshal(expectedEvent)
					Expect(err).NotTo(HaveOccurred())
					payload = []byte(base64.StdEncoding.EncodeToString(payload))

					fakeRawEventSource.NextReturns(
						sse.Event{
							ID:   "sup",
						Path: "true",
						User: "user",
					}),
				}
				eventChannel <- models.NewDesiredLRPCreatedEvent(desiredLRP)

				data, err := json.Marshal(receptor.NewDesiredLRPCreatedEvent(serialization.DesiredLRPProtoToResponse(desiredLRP)))
				Expect(err).NotTo(HaveOccurred())

				event, err := reader.Next()
				Expect(err).NotTo(HaveOccurred())
				Expect(event.ID).To(Equal("0"))
				Expect(event.Name).To(Equal(string(receptor.EventTypeDesiredLRPCreated)))
				Expect(event.Data).To(MatchJSON(data))

				actualLRP := models.NewUnclaimedActualLRP(models.NewActualLRPKey("some-guid", 3, "some-domain"), 0)
				actualLRPGroup := &models.ActualLRPGroup{Instance: actualLRP}
				eventChannel <- models.NewActualLRPCreatedEvent(actualLRPGroup)

				data, err = json.Marshal(receptor.NewActualLRPCreatedEvent(serialization.ActualLRPProtoToResponse(actualLRP, false)))
				Expect(err).NotTo(HaveOccurred())

				event, err = reader.Next()
				Expect(err).NotTo(HaveOccurred())
				Expect(event.ID).To(Equal("1"))
				Expect(event.Name).To(Equal(string(receptor.EventTypeActualLRPCreated)))
				Expect(event.Data).To(MatchJSON(data))
				eventChannel <- eventfakes.FakeEvent{"B"}

				close(done)
			})