func (this *SerialListenerFixture) TestListenCallInOrder() {
	items := []Listener{
		&FakeForSerialListener{listened: clock.UTCNow().Add(time.Second)},
		&FakeForSerialListener{listened: clock.UTCNow()},
		&FakeForSerialListener{listened: clock.UTCNow().Add(-time.Second)},
	}

	NewSerialListener(items...).Listen()

	times := []time.Time{}
	for _, item := range items {
		fake := item.(*FakeForSerialListener)
		times = append(times, fake.listened)

		this.So(fake.calls, should.Equal, 1)
	}

	this.So(times, should.BeChronological)

}
func (this *TransactionWriter) Write(message messaging.Dispatch) error {
	if !this.ensureChannel() {
		return messaging.WriterClosedError
	}

	// FUTURE: if error on publish, don't publish anything else
	// until we reset the channel during commit
	// opening a new channel is what marks it as able to continue
	dispatch := toAMQPDispatch(message, clock.UTCNow())
	return this.channel.PublishMessage(message.Destination, dispatch)
}
func (this *FakeLockerRouter) Handle(item interface{}) []interface{} {
	this.handled = append(this.handled, item)
	this.handles = append(this.handles, clock.UTCNow())

	if len(this.results) == 0 {
		return nil
	}

	if this.err == nil {
		return this.results[len(this.handled)-1]
	}

	return append(this.results[len(this.handled)-1], this.err)
}
func (this *CompositeWaitListenerFixture) TestAllListenersAreCalledAndWaitedFor() {
	this.listener.Listen()

	this.completed = clock.UTCNow()

	for _, item := range this.items {
		if item == nil {
			continue
		}

		this.So(item.(*FakeListener).calls, should.Equal, 1)
		this.So(this.completed.After(item.(*FakeListener).instant), should.BeTrue)
	}
}
func (this *ChannelWriter) Write(message messaging.Dispatch) error {
	if !this.ensureChannel() {
		return messaging.WriterClosedError
	}

	dispatch := toAMQPDispatch(message, clock.UTCNow())
	err := this.channel.PublishMessage(message.Destination, dispatch)
	if err == nil {
		return nil
	}

	this.channel.Close()
	this.channel = nil
	return err
}
Beispiel #6
0
func (this *HandlerFixture) Setup() {
	this.now = clock.UTCNow()
	this.input = make(chan messaging.Delivery, 2)
	this.output = make(chan projector.DocumentMessage, 2)
	this.transformer = NewFakeTransformer()
	this.handler = NewHandler(this.input, this.output, this.transformer)
	this.handler.clock = clock.Freeze(this.now)

	this.firstInput = messaging.Delivery{
		Message: 1,
		Receipt: &FakeAcknowledgement{},
	}
	this.secondInput = messaging.Delivery{
		Message: 2,
		Receipt: &FakeAcknowledgement{},
	}
}
func (this *FakeLockerRouter) Unlock() {
	this.locked--
	this.unlocks = append(this.unlocks, clock.UTCNow())
}
func (this *FakeLockerRouter) Lock() {
	this.locked++
	this.locks = append(this.locks, clock.UTCNow())
}
func (this *FakeForSerialListener) Listen() {
	this.calls++
	this.listened = clock.UTCNow()
	time.Sleep(time.Microsecond)
}
func (this *CompositeListenerFixture) TestCompositeListenerCallsInnerListenersConcurrently() {
	started := clock.UTCNow()
	this.composite.Listen()
	this.So(time.Since(started), should.BeLessThan, nap*5)
}
func (this *FakeListener) Listen() {
	this.instant = clock.UTCNow()
	time.Sleep(time.Millisecond)
	this.calls++
}
Beispiel #12
0
func (this *Handler) persist(document projector.Document) {
	started := clock.UTCNow()
	this.writer.Write(document)
	metrics.Measure(DocumentWriteLatency, milliseconds(time.Since(started)))
	this.waiter.Done()
}
func (this *MessageTransformerFixture) Setup() {
	this.documents = []projector.Document{&FakeDocument{}}
	this.cloner = &FakeCloner{}
	this.transformer = NewMessageTransformer(this.documents, this.cloner)
	this.now = clock.UTCNow()
}
func (this *RabbitAdapterFixture) Setup() {
	this.now = clock.UTCNow()
}
func (this *FakeSubscriptionChannel) DeclareTransientQueue() (string, error) {
	return strconv.FormatInt(clock.UTCNow().UnixNano(), 10), nil
}