File: queue_exclusivity_spec.rb

package info (click to toggle)
ruby-amqp 1.8.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 2,508 kB
  • sloc: ruby: 8,272; sh: 11; makefile: 10
file content (98 lines) | stat: -rw-r--r-- 2,322 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# encoding: utf-8

require 'spec_helper'

describe "Non-exclusive queue" do

  #
  # Environment
  #

  include EventedSpec::EMSpec

  default_timeout 5

  em_after { @connection1.close; @connection2.close }
  #
  # Examples
  #

  it "can be used across multiple connections" do
    @connection1 = AMQP.connect do
      @connection2 = AMQP.connect do
        @connection1.should_not == @connection2

        channel1 = AMQP::Channel.new(@connection1)
        channel2 = AMQP::Channel.new(@connection2)

        instance1 = AMQP::Queue.new(channel1, "amqpgem.integration.queues.non-exclusive", :exclusive => false, :auto_delete => true)
        instance2 = AMQP::Queue.new(channel2, "amqpgem.integration.queues.non-exclusive", :exclusive => false, :auto_delete => true)

        exchange1 = channel1.fanout("amqpgem.integration.exchanges.fanout1", :auto_delete => true)
        exchange2 = channel2.fanout("amqpgem.integration.exchanges.fanout2", :auto_delete => true)


        instance1.bind(exchange1).subscribe do |payload|
        end

        instance2.bind(exchange2).subscribe do |payload|
        end

        done(0.2) {
          channel1.should be_open
          channel1.close

          channel2.should be_open
          channel2.close
        }
      end
    end
  end
end



describe "Exclusive queue" do

  #
  # Environment
  #

  include EventedSpec::EMSpec

  default_timeout 2

  em_after { @connection1.close; @connection2.close }


  #
  # Examples
  #

  it "can ONLY be used by ONE connection" do
    @connection1 = AMQP.connect do
      @connection2 = AMQP.connect do
        @connection1.should_not == @connection2

        queue_name = "amqpgem.integration.queues.exclusive"
        callback_fired = false
        @channel1 = AMQP::Channel.new(@connection1) do
          AMQP::Queue.new(@channel1, queue_name, :exclusive => true) do
            @channel2 = AMQP::Channel.new(@connection2) do
              AMQP::Queue.new(@channel2, queue_name, :exclusive => true) do
                callback_fired = true
              end
            end
          end
        end

        done(1) {
          callback_fired.should be_false
          @channel1.should_not be_closed
          # because it is a channel-level exception
          @channel2.should be_closed
        }
      end
    end
  end
end