Example #1
0
func TestExchange_UsesMatcherForMessagesDirectionToBindings(t *testing.T) {
	ex := amq.NewExchange(matcher.Direct)

	c1 := new(countingConsumer)
	c2 := new(countingConsumer)

	b1 := &amq.Binding{Key: "key1", Consumer: c1}
	b2 := &amq.Binding{Key: "key2", Consumer: c2}

	ex.BindTo(b1)
	ex.BindTo(b2)

	for i := 0; i < 100; i++ {
		ex.Consume(testMsg{
			routingKey: "key1",
		})
	}

	if c1.callsCount != 100 {
		t.Errorf("Unexpected calls count: %d, expected: %d", c1.callsCount, 100)
	}

	if c2.callsCount != 0 {
		t.Errorf("Unexpected calls count: %d, expected: %d", c1.callsCount, 0)
	}
}
Example #2
0
func TestExchange_SilentlyDropsMessagesWhenNoBindings(t *testing.T) {
	ex := amq.NewExchange(matcher.Direct)

	for i := 0; i < 100; i++ {
		ex.Consume(testMsg{})
	}
}
Example #3
0
func TestExchange_BindToErrorsOnDoubleBind(t *testing.T) {
	ex := amq.NewExchange(matcher.Direct)

	b := &amq.Binding{Key: "key", Consumer: new(countingConsumer)}

	err := ex.BindTo(b)
	if err != nil {
		t.Error("Unexpected error:", err)
	}

	err = ex.BindTo(b)
	if err != amq.ErrAlreadyBound {
		t.Error("Unexpected error:", err)
	}
}
Example #4
0
func TestExchange_UnbindFromErrorsOnDoubleUnind(t *testing.T) {
	ex := amq.NewExchange(matcher.Direct)

	b := &amq.Binding{Key: "key", Consumer: new(countingConsumer)}

	err := ex.BindTo(b)
	if err != nil {
		t.Error("Unexpected error:", err)
	}

	err = ex.UnbindFrom(b)
	if err != nil {
		t.Error("Unexpected error:", err)
	}

	err = ex.UnbindFrom(b)
	if err != amq.ErrBindingNotFound {
		t.Error("Unexpected error:", err)
	}
}
Example #5
0
func TestExchange_OnlyOneDeliveryToSingleConsumer(t *testing.T) {
	ex := amq.NewExchange(matcher.Direct)

	c := new(countingConsumer)

	b1 := &amq.Binding{Key: "key", Consumer: c}
	b2 := &amq.Binding{Key: "key", Consumer: c}

	ex.BindTo(b1)
	ex.BindTo(b2)

	for i := 0; i < 100; i++ {
		ex.Consume(testMsg{
			routingKey: "key",
		})
	}

	if c.callsCount != 100 {
		t.Errorf("Unexpected calls count: %d, expected: %d", c.callsCount, 100)
	}
}