mingle_events 0.2.1 → 0.2.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: d698d7bfba52d210386fcfcc08932d91c83e1eee
4
- data.tar.gz: ecbc8067509a2d0c09d752f0f29e3b7c769b2a92
3
+ metadata.gz: 1653b5493ba56fce35515d2a49dc0a54e97667c4
4
+ data.tar.gz: 069cfd676643e547e4731385addff547abd468a9
5
5
  SHA512:
6
- metadata.gz: 6dd16e77733ee7dbd5703bc82ca8201c5b52d89d7fdc81d7e08959b4e137f72ac52d4b5c1761c7b7a792bf0bd6aea3f1ff45036864359ba65e2a7ab5c11c40af
7
- data.tar.gz: 64b001acbcd89fd8f45e11e43dfdb18069a22e41b4f4a14396e256ed57e65c3fb776be245e965b6fecb61289b92ebac50b8d7d08c42f9a3af25cc80e0e184a1c
6
+ metadata.gz: e13638f0c01b832cf57fb1f6d21fcd840e7a10243be789b3116cca122d03f395eb5d1c34adb685b901e4fb271fd9b599cf32840154ad0e4ae0874c118a3c061b
7
+ data.tar.gz: 5490fd62b2c4627754f0a11ac1ce2a0e3b1b8b5c9c1fafa5aa00be032b7d4d157feef0ca5f85c6dbff9b7c2cbb3c8c4bfb722156611ee49014e4ea9b4f48f148
@@ -53,6 +53,23 @@ module MingleEvents
53
53
  @entry_cache.update_current_state(next_entry, most_recent_new_entry)
54
54
  @entry_cache.entries(next_entry, most_recent_new_entry)
55
55
  end
56
+
57
+ def clear_cache_if_first_entry_mismatch!
58
+ unless first_entry_cached_match?
59
+ reset
60
+ end
61
+ end
62
+
63
+ def first_entry_cached_match?
64
+ if first_entry_cached = first_entry_fetched
65
+ page = page_with_first_entries
66
+ if first_entry = page.entries.last
67
+ first_entry_fetched.entry_id == first_entry.entry_id
68
+ end
69
+ else
70
+ true
71
+ end
72
+ end
56
73
 
57
74
  # returns all previously fetched entries; can be used to reprocess the events for, say,
58
75
  # various historical analyses
@@ -72,6 +89,10 @@ module MingleEvents
72
89
 
73
90
  def page_with_latest_entries
74
91
  Feed::Page.new("/api/v2/projects/#{@project_identifier}/feeds/events.xml", @mingle_access)
75
- end
92
+ end
93
+
94
+ def page_with_first_entries
95
+ Feed::Page.new("/api/v2/projects/#{@project_identifier}/feeds/events.xml?page=1", @mingle_access)
96
+ end
76
97
  end
77
98
  end
@@ -1,4 +1,6 @@
1
1
  module MingleEvents
2
+ class FileNotExist < StandardError; end
3
+
2
4
  class ZipDirectory
3
5
 
4
6
  def initialize(name)
@@ -24,7 +26,7 @@ module MingleEvents
24
26
 
25
27
  def file(path, &block)
26
28
  measure("read file") do
27
- raise "File at '#{path}' in archive '#{@root}' dose not exisits" unless exists?(path)
29
+ raise FileNotExist, "File at '#{path}' in archive '#{@root}' dose not exisits" unless exists?(path)
28
30
  entry_map[path].open { |entry_stream| yield(entry_stream) }
29
31
  end
30
32
  end
@@ -109,8 +109,8 @@ module MingleEvents
109
109
  state_dir = temp_dir
110
110
  mingle_access = stub_mingle_access
111
111
  fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
112
-
113
112
  fetcher.set_current_state_to_now_if_no_current_state
113
+
114
114
  assert fetcher.fetch_latest.to_a.empty?
115
115
 
116
116
  mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
@@ -196,6 +196,65 @@ module MingleEvents
196
196
  assert_equal([entry(104)], fetcher.fetch_latest.to_a)
197
197
  end
198
198
 
199
+ def test_should_clear_old_cache_if_the_first_event_does_not_match
200
+ state_dir = temp_dir
201
+ mingle_access = StubMingleAccess.new
202
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml', EMPTY_EVENTS_XML)
203
+ fetcher = ProjectEventFetcher.new('atlas', mingle_access, state_dir)
204
+ assert fetcher.first_entry_cached_match?
205
+
206
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=1',%{
207
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
208
+
209
+ <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=1" rel="current"/>
210
+ <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=1" rel="self"/>
211
+
212
+ <entry>
213
+ <id>https://mingle.example.com/projects/atlas/events/index/104</id>
214
+ <title>entry 104</title>
215
+ <updated>2011-02-03T08:14:42Z</updated>
216
+ <author><name>Bob</name></author>
217
+ </entry>
218
+ </feed>
219
+ })
220
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml',%{
221
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
222
+
223
+ <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml" rel="current"/>
224
+ <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml" rel="self"/>
225
+
226
+ <entry>
227
+ <id>https://mingle.example.com/projects/atlas/events/index/104</id>
228
+ <title>entry 104</title>
229
+ <updated>2011-02-03T08:14:42Z</updated>
230
+ <author><name>Bob</name></author>
231
+ </entry>
232
+ </feed>
233
+ })
234
+
235
+ fetcher.fetch_latest
236
+ assert_equal([entry(104)], fetcher.all_fetched_entries.to_a)
237
+ assert fetcher.first_entry_cached_match?
238
+
239
+ mingle_access.register_page_content('/api/v2/projects/atlas/feeds/events.xml?page=1',%{
240
+ <feed xmlns="http://www.w3.org/2005/Atom" xmlns:mingle="http://www.thoughtworks-studios.com/ns/mingle">
241
+
242
+ <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=1" rel="current"/>
243
+ <link href="https://mingle.example.com/api/v2/projects/atlas/feeds/events.xml?page=1" rel="self"/>
244
+
245
+ <entry>
246
+ <id>https://mingle.example.com/projects/atlas/events/index/105</id>
247
+ <title>entry 105</title>
248
+ <updated>2011-02-03T08:14:42Z</updated>
249
+ <author><name>Bob</name></author>
250
+ </entry>
251
+ </feed>
252
+ })
253
+ assert !fetcher.first_entry_cached_match?
254
+ fetcher.clear_cache_if_first_entry_mismatch!
255
+ assert_equal([], fetcher.all_fetched_entries.to_a)
256
+ end
257
+
199
258
  private
200
259
 
201
260
  def setup_current_state(first_entry_id, second_entry_id, last_entry_id, fetcher)
@@ -18,6 +18,12 @@ module MingleEvents
18
18
  assert_equal 's' * 1000, @dir.file('a', &:read)
19
19
  end
20
20
 
21
+ def test_file_not_exist_error
22
+ assert_raises MingleEvents::FileNotExist do
23
+ @dir.file('a')
24
+ end
25
+ end
26
+
21
27
  def test_read_write_files_with_sub_directory
22
28
  @dir.write_file('a/b/c') { |f| f.write( 's' * 1000) }
23
29
  @dir.reload
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mingle_events
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Rice
@@ -201,7 +201,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
201
  version: '1.2'
202
202
  requirements: []
203
203
  rubyforge_project: mingle_events
204
- rubygems_version: 2.2.0
204
+ rubygems_version: 2.4.5
205
205
  signing_key:
206
206
  specification_version: 3
207
207
  summary: A gem that lets you process Mingle events in a pipes and filters style.