func NewEventFromBBS(bbsEvent models.Event) (receptor.Event, error) { switch bbsEvent := bbsEvent.(type) { case *models.ActualLRPCreatedEvent: actualLRP, evacuating := bbsEvent.ActualLrpGroup.Resolve() return receptor.NewActualLRPCreatedEvent(serialization.ActualLRPProtoToResponse(actualLRP, evacuating)), nil case *models.ActualLRPChangedEvent: before, evacuating := bbsEvent.Before.Resolve() after, evacuating := bbsEvent.After.Resolve() return receptor.NewActualLRPChangedEvent( serialization.ActualLRPProtoToResponse(before, evacuating), serialization.ActualLRPProtoToResponse(after, evacuating), ), nil case *models.ActualLRPRemovedEvent: actualLRP, evacuating := bbsEvent.ActualLrpGroup.Resolve() return receptor.NewActualLRPRemovedEvent(serialization.ActualLRPProtoToResponse(actualLRP, evacuating)), nil case *models.DesiredLRPCreatedEvent: return receptor.NewDesiredLRPCreatedEvent(serialization.DesiredLRPProtoToResponse(bbsEvent.DesiredLrp)), nil case *models.DesiredLRPChangedEvent: return receptor.NewDesiredLRPChangedEvent( serialization.DesiredLRPProtoToResponse(bbsEvent.Before), serialization.DesiredLRPProtoToResponse(bbsEvent.After), ), nil case *models.DesiredLRPRemovedEvent: return receptor.NewDesiredLRPRemovedEvent(serialization.DesiredLRPProtoToResponse(bbsEvent.DesiredLrp)), nil } return nil, fmt.Errorf("unknown event type: %#v", bbsEvent) }
func (w *watcher) watchActual(logger lager.Logger) (chan<- bool, <-chan error) { return w.bbs.WatchForActualLRPChanges(logger, func(created models.ActualLRP, evacuating bool) { logger.Debug("handling-actual-create") w.hub.Emit(receptor.NewActualLRPCreatedEvent(serialization.ActualLRPToResponse(created, evacuating))) }, func(changed models.ActualLRPChange, evacuating bool) { logger.Debug("handling-actual-change") w.hub.Emit(receptor.NewActualLRPChangedEvent( serialization.ActualLRPToResponse(changed.Before, evacuating), serialization.ActualLRPToResponse(changed.After, evacuating), )) }, func(deleted models.ActualLRP, evacuating bool) { logger.Debug("handling-actual-delete") w.hub.Emit(receptor.NewActualLRPRemovedEvent(serialization.ActualLRPToResponse(deleted, evacuating))) }) }
It("returns the event", func() { event, err := eventSource.Next() Expect(err).NotTo(HaveOccurred()) actualLRPChangedEvent, ok := event.(receptor.ActualLRPChangedEvent) Expect(ok).To(BeTrue()) Expect(actualLRPChangedEvent).To(Equal(expectedEvent)) }) }) Context("when receiving a ActualLRPRemovedEvent", func() { var expectedEvent receptor.ActualLRPRemovedEvent BeforeEach(func() { expectedEvent = receptor.NewActualLRPRemovedEvent(actualLRPResponse) payload, err := json.Marshal(expectedEvent) Expect(err).NotTo(HaveOccurred()) fakeRawEventSource.NextReturns( sse.Event{ ID: "sup", Name: string(expectedEvent.EventType()), Data: payload, }, nil, ) }) It("returns the event", func() { event, err := eventSource.Next()