estore 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bdd806cd7c12b665577e8f686f9a14225fd102ce
4
- data.tar.gz: 519601368cfc6e8d30912510fadbd2b866eff7e8
3
+ metadata.gz: 90ec9eb805fb44a8772c81a4f5ea5bfd4d224779
4
+ data.tar.gz: d29629f1fdb5f8819b0204becf1d1a97934f0ba7
5
5
  SHA512:
6
- metadata.gz: 5e554e45930e79aeb9c1eca4cdc5437bc8a26f3228c02b71d63c4c5e1c573cac7268e83d51bcd96bf619c7b430d1ca22eaaffbe224c44b139f6e4e031b1306dd
7
- data.tar.gz: 1ef5c432b902a710b61886b4e0ba5eee9448c021978add9d93b033b9b747dd5a693e019c960b855ea005cc350f781b9bdea73351f85905b958c7d5e0a348a29b
6
+ metadata.gz: 3896eeed05e045d57d635d467d9b002f5394b2b7f0a76f192d4bb0009e4c760d1b94fa60ce093ffbef483eab4a42c3d9bf52a2901e8a46d89eceba58c83e742b
7
+ data.tar.gz: 81a42f181c7541577a950b74d7a23824259c0cf31b20ac385ddbca91e58ed2d31cca791c127066024f2508a5173d39af6ae381f1bf0a2a30fc247b3c6489a6f3
data/.simplecov CHANGED
@@ -7,8 +7,18 @@ SimpleCov.start do
7
7
  add_filter '/config/'
8
8
 
9
9
  require 'coveralls'
10
+
11
+ formatters = [
12
+ SimpleCov::Formatter::HTMLFormatter,
13
+ Coveralls::SimpleCov::Formatter
14
+ ]
15
+
16
+ if RUBY_ENGINE == 'rbx'
17
+ require 'codeclimate-test-reporter'
18
+ formatters << CodeClimate::TestReporter::Formatter
19
+ end
20
+
10
21
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
11
- Coveralls::SimpleCov::Formatter,
12
- SimpleCov::Formatter::HTMLFormatter
22
+ *formatters
13
23
  ]
14
24
  end
@@ -10,7 +10,7 @@ install:
10
10
  - "wget -nc http://download.geteventstore.com/binaries/EventStore-OSS-Linux-v3.0.3.tar.gz"
11
11
  - "tar -xvzf EventStore-OSS-Linux-v3.0.3.tar.gz"
12
12
  - "mv EventStore-OSS-Linux-v3.0.3 .event_store"
13
- - "cd .event_store && ./run-node.sh --db ./ESData &"
13
+ - "cd .event_store && ./run-node.sh --mem-db &"
14
14
  - "bundle install"
15
15
  script: "bundle exec rake ci"
16
16
  rvm:
@@ -1,28 +1,35 @@
1
+ ## v0.1.3 - 2015-04-15
2
+ ### Added
3
+ * Workers to dispatch events in subscriptions
4
+ * Print error information while dispatching
5
+
6
+ [Compare v0.1.2...v0.1.3](https://github.com/eventstore-rb/estore/compare/v0.1.2...v0.1.3)
7
+
1
8
  ## v0.1.2 - 2015-04-05
2
9
  ### Added
3
10
  * Errors during commands reject promises too
4
11
  * Unit testing started
5
12
 
6
- [Compare v0.1.1...v0.1.2](https://github.com/rom-rb/rom-event_store/compare/v0.1.1...v0.1.2)
13
+ [Compare v0.1.1...v0.1.2](https://github.com/eventstore-rb/estore/compare/v0.1.1...v0.1.2)
7
14
 
8
15
  ## v0.1.1 - 2015-04-05
9
16
  ### Added
10
17
  * General errors during connection reject command promises
11
18
 
12
- [Compare v0.1.0...v0.1.1](https://github.com/rom-rb/rom-event_store/compare/v0.1.0...v0.1.1)
19
+ [Compare v0.1.0...v0.1.1](https://github.com/eventstore-rb/estore/compare/v0.1.0...v0.1.1)
13
20
 
14
21
  ## v0.1.0 - 2015-04-03
15
22
  ### Added
16
23
  * General refactoring using the concept of `Command`
17
24
 
18
- [Compare v0.0.2...v0.1.0](https://github.com/rom-rb/rom-event_store/compare/v0.0.2...v0.1.0)
25
+ [Compare v0.0.2...v0.1.0](https://github.com/eventstore-rb/estore/compare/v0.0.2...v0.1.0)
19
26
 
20
27
  ## v0.0.2 - 2015-04-01
21
28
  ### Added
22
29
  * Gem name changed to `estore`
23
30
  * Minor refactoring
24
31
 
25
- [Compare v0.0.1...v0.0.2](https://github.com/rom-rb/rom-event_store/compare/v0.0.1...v0.0.2)
32
+ [Compare v0.0.1...v0.0.2](https://github.com/eventstore-rb/estore/compare/v0.0.1...v0.0.2)
26
33
 
27
34
  ## v0.0.1 - 2015-03-31
28
35
  Forked from [eventstore-ruby](https://github.com/mathieuravaux/eventstore-ruby)
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
 
6
6
  group :test do
7
7
  gem 'coveralls', require: false
8
+ gem 'codeclimate-test-reporter', require: nil
8
9
  end
@@ -41,7 +41,7 @@ module Estore
41
41
 
42
42
  if error
43
43
  remove!
44
- promise.reject error
44
+ promise.reject ReadEventsError.new(error)
45
45
  else
46
46
  keep_reading(response)
47
47
  end
@@ -6,6 +6,8 @@ module Estore
6
6
  @has_finished = false
7
7
  @stream = stream
8
8
  @resolve_link_tos = options.fetch(:resolve_link_tos, true)
9
+ @worker_queue = Queue.new
10
+ @worker = Thread.new { loop { worker_loop } }
9
11
  end
10
12
 
11
13
  def call
@@ -33,9 +35,17 @@ module Estore
33
35
  @handler = block
34
36
  end
35
37
 
36
- def dispatch(event)
37
- @position = event.original_event_number
38
- @handler.call(event)
38
+ def enqueue(events)
39
+ events = Array(events)
40
+ @position = events.last.original_event_number
41
+ @worker_queue << events
42
+ end
43
+
44
+ def worker_loop
45
+ @worker_queue.pop.each { |event| @handler.call(event) }
46
+ rescue => e
47
+ puts e.message
48
+ puts e.backtrace
39
49
  end
40
50
  end
41
51
  end
@@ -12,9 +12,8 @@ module Estore
12
12
  @from = from
13
13
  @batch = options[:batch_size]
14
14
  @mutex = Mutex.new
15
- @queue = []
15
+ @while_catching_up = []
16
16
  @caught_up = false
17
- @last_worker = nil
18
17
  end
19
18
 
20
19
  def start
@@ -22,37 +21,32 @@ module Estore
22
21
 
23
22
  # TODO: Think about doing something more clever?
24
23
  read = ReadForward.new(@connection, @stream, @from, @batch) do |events|
25
- @last_worker = Thread.new(@last_worker) do |last_worker|
26
- last_worker.join if last_worker
27
- events.each { |event| dispatch(event) }
28
- end
24
+ enqueue events unless events.empty?
29
25
  end
30
26
 
31
27
  read.call.sync
32
- @last_worker.join if @last_worker
33
-
34
28
  switch_to_live
35
29
  end
36
30
 
37
31
  def switch_to_live
38
32
  @mutex.synchronize do
39
- queued_events.each { |event| dispatch(event) }
33
+ unprocessed_events.each { |event| enqueue event }
40
34
  @caught_up = true
41
35
  end
42
36
  end
43
37
 
44
- def queued_events
45
- @queue.find_all { |event| event.original_event_number > @position }
38
+ def unprocessed_events
39
+ @while_catching_up.find_all { |event| event.original_event_number > @position }
46
40
  end
47
41
 
48
42
  def event_appeared(response)
49
43
  unless @caught_up
50
44
  @mutex.synchronize do
51
- @queue << response.event unless @caught_up
45
+ @while_catching_up << response.event unless @caught_up
52
46
  end
53
47
  end
54
48
 
55
- dispatch(response.event) if @caught_up
49
+ enqueue response.event if @caught_up
56
50
  end
57
51
  end
58
52
  end
@@ -8,7 +8,7 @@ module Estore
8
8
  SubscriptionConfirmation => :ignore
9
9
 
10
10
  def event_appeared(response)
11
- dispatch(response.event)
11
+ enqueue response.event
12
12
  end
13
13
  end
14
14
  end
@@ -56,9 +56,7 @@ module Estore
56
56
  end
57
57
 
58
58
  def process_downstream
59
- loop do
60
- @buffer << socket.sysread(4096)
61
- end
59
+ loop { @buffer << socket.sysread(4096) }
62
60
  rescue IOError, EOFError
63
61
  @context.on_error(DisconnectionError.new) unless @terminating
64
62
  rescue => error
@@ -26,6 +26,9 @@ module Estore
26
26
  rescue => error
27
27
  command.reject! error
28
28
  remove(command)
29
+
30
+ puts "[DISPATCH] #{error.message}"
31
+ puts error.backtrace
29
32
  end
30
33
 
31
34
  def empty?
@@ -2,4 +2,5 @@ module Estore
2
2
  CannotConnectError = Class.new(StandardError)
3
3
  DisconnectionError = Class.new(StandardError)
4
4
  WriteEventsError = Class.new(StandardError)
5
+ ReadEventsError = Class.new(StandardError)
5
6
  end
@@ -1,3 +1,3 @@
1
1
  module Estore
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
@@ -108,4 +108,26 @@ describe Estore::Session do
108
108
 
109
109
  expect(received).to have(2130).events.starting_at(30).before(20.seconds)
110
110
  end
111
+
112
+ it 'allows to make a catchup subscription to a non-existing stream' do
113
+ stream = random_stream
114
+ received = []
115
+
116
+ sub = session.subscription(stream, from: 0)
117
+
118
+ sub.on_event do |event|
119
+ received << event
120
+ puts "Receiving... #{received.size}"
121
+ end
122
+
123
+ sub.start
124
+
125
+ Thread.new do
126
+ 30.times do
127
+ stream_with(2, stream)
128
+ end
129
+ end
130
+
131
+ expect(received).to have(60).events.starting_at(0).before(20.seconds)
132
+ end
111
133
  end
@@ -3,8 +3,8 @@ require 'spec_helper'
3
3
  describe Estore::ConnectionContext do
4
4
  subject(:context) { Estore::ConnectionContext.new }
5
5
 
6
- let(:bad_command) do
7
- BadCommand = Class.new do
6
+ let(:bad_command_class) do
7
+ Class.new do
8
8
  attr_reader :error
9
9
 
10
10
  def uuid
@@ -19,10 +19,10 @@ describe Estore::ConnectionContext do
19
19
  boom
20
20
  end
21
21
  end
22
-
23
- BadCommand.new
24
22
  end
25
23
 
24
+ let(:bad_command) { bad_command_class.new }
25
+
26
26
  before do
27
27
  context.register(bad_command)
28
28
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: estore
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathieu Ravaux
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-04-06 00:00:00.000000000 Z
12
+ date: 2015-04-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: beefcake