File: tx_rollback_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 (167 lines) | stat: -rw-r--r-- 3,282 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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# encoding: utf-8
require 'spec_helper'


describe "AMQP transaction rollback" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec
  default_timeout 4.5

  amqp_before do
    @producer_channel    = AMQP::Channel.new
    @consumer_channel    = AMQP::Channel.new
  end

  # ...


  #
  # Examples
  #

  it "voids messages published since the last tx.select" do
    exchange = @producer_channel.fanout("amq.fanout")
    queue    = @consumer_channel.queue("", :exclusive => true)

    queue.bind(exchange).subscribe do |metadata, payload|
      fail "Consumer received a message before transaction committed"
    end

    @producer_channel.tx_select
    EventMachine.add_timer(0.5) do
      50.times { exchange.publish("before tx.commit") }
      @producer_channel.tx_rollback
    end

    done(3.5)
  end # it
end # describe




describe "AMQP connection closure that follows tx.select" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec
  default_timeout 4.5

  amqp_before do
    @producer_channel    = AMQP::Channel.new
    @consumer_channel    = AMQP::Channel.new
  end

  # ...


  #
  # Examples
  #

  it "voids messages published since the last tx.select" do
    exchange = @producer_channel.fanout("amq.fanout")
    queue    = @consumer_channel.queue("", :exclusive => true)

    queue.bind(exchange).subscribe do |metadata, payload|
      fail "Consumer received a message before transaction committed"
    end

    @producer_channel.tx_select
    EventMachine.add_timer(0.5) do
      3.times { exchange.publish("before tx.commit") }
      @producer_channel.connection.close
    end

    done(3.5)
  end # it
end # describe




describe "AMQP channel closure that follows tx.select" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec
  default_timeout 4.5

  amqp_before do
    @producer_channel    = AMQP::Channel.new
    @consumer_channel    = AMQP::Channel.new
  end

  # ...


  #
  # Examples
  #

  it "voids messages published since the last tx.select" do
    exchange = @producer_channel.fanout("amq.fanout")
    queue    = @consumer_channel.queue("", :exclusive => true)

    queue.bind(exchange).subscribe do |metadata, payload|
      fail "Consumer received a message before transaction committed"
    end

    @producer_channel.tx_select
    EventMachine.add_timer(0.5) do
      3.times { exchange.publish("before tx.commit") }
      @producer_channel.close
    end

    done(3.5)
  end # it
end # describe



describe "AMQP transaction rollback attempt on a non-transactional channel" do

  #
  # Environment
  #

  include EventedSpec::AMQPSpec
  default_timeout 4.5

  amqp_before do
    @producer_channel    = AMQP::Channel.new
    @consumer_channel    = AMQP::Channel.new
  end

  # ...


  #
  # Examples
  #

  it "causes channel-level exception" do
    exchange = @producer_channel.fanout("amq.fanout")
    queue    = @consumer_channel.queue("", :exclusive => true)

    queue.bind(exchange).subscribe do |metadata, payload|
      fail "Consumer received a message before transaction committed"
    end

    @producer_channel.on_error do |ch, channel_close|
      puts "#{channel_close.reply_text}"
      done
    end
    EventMachine.add_timer(0.5) { @producer_channel.tx_rollback }

    done(3.5)
  end # it
end # describe