summaryrefslogtreecommitdiff
path: root/test/test_journal.rb
diff options
context:
space:
mode:
authorMatthias Hecker <apoc@geekosphere.org>2015-06-14 19:31:55 +0200
committerMatthias Hecker <apoc@geekosphere.org>2015-06-14 19:31:55 +0200
commit075c7e031b3449ff026e51a2299f56df573ef688 (patch)
tree2631d2aa23352c9642cb11baf35100b367b1e378 /test/test_journal.rb
parent65de5ebca22a2d17729a63589240c734b5ca4de1 (diff)
journal: more postgres tests
Diffstat (limited to 'test/test_journal.rb')
-rw-r--r--test/test_journal.rb79
1 files changed, 53 insertions, 26 deletions
diff --git a/test/test_journal.rb b/test/test_journal.rb
index 2a522aa7..3f1ce766 100644
--- a/test/test_journal.rb
+++ b/test/test_journal.rb
@@ -224,41 +224,68 @@ class JournalStoragePostgresTest < Test::Unit::TestCase
assert_equal(['foo.%.bar'], @storage.query_to_sql(q)[1])
end
- def test_insert
- # the test message to persist
+ def test_operations
+ # insertion
m = JournalMessage.create('log.core', {foo: {bar: 'baz'}})
- # insert the test message:
@storage.insert(m)
- # find the test message by query:
- q = Query.define do
- topic 'log.core'
- end
- res = @storage.find(q)
- _m = res.first
- assert_equal(m, _m) # this only checks id
+ # query by id
+ res = @storage.find(Query.define { id m.id })
+ assert_equal(1, res.length)
+ assert_equal(m, res.first)
+
+ # check timestamp was returned correctly:
assert_equal(m.timestamp.strftime('%Y-%m-%d %H:%M:%S%z'),
- _m.timestamp.strftime('%Y-%m-%d %H:%M:%S%z'))
- assert_equal('log.core', _m.topic)
- assert_equal({'foo' => {'bar' => 'baz'}}, _m.payload)
- assert_equal(1, @storage.count(q))
+ res.first.timestamp.strftime('%Y-%m-%d %H:%M:%S%z'))
+
+ # check if payload was returned correctly:
+ assert_equal({'foo' => {'bar' => 'baz'}}, res.first.payload)
+
+ # query by topic
+ assert_equal(m, @storage.find(Query.define { topic('log.core') }).first)
+ assert_equal(m, @storage.find(Query.define { topic('log.*') }).first)
+ assert_equal(m, @storage.find(Query.define { topic('*.*') }).first)
+
+ # query by timestamp range
+ assert_equal(1, @storage.find(Query.define {
+ timestamp(from: Time.now-DAY, to: Time.now+DAY) }).length)
+ assert_equal(0, @storage.find(Query.define {
+ timestamp(from: Time.now-DAY*2, to: Time.now-DAY) }).length)
+
+ # query by payload
+ res = @storage.find(Query.define { payload('foo.bar' => 'baz') })
+ assert_equal(m, res.first)
+ res = @storage.find(Query.define { payload('foo.bar' => 'x') })
+ assert_true(res.empty?)
+
+ # without arguments: find and count
+ assert_equal(1, @storage.count)
+ assert_equal(m, @storage.find.first)
end
- def test_query_range
- timestamp = Time.now - DAY*7
- m = JournalMessage.create('log.core', {foo: {bar: 'baz'}},
- timestamp: timestamp)
- assert_equal(timestamp, m.timestamp)
+ def test_operations_multiple
+ # test operations on multiple messages
+ # insert a bunch:
+ @storage.insert(JournalMessage.create('test.topic', {name: 'one'}))
+ @storage.insert(JournalMessage.create('test.topic', {name: 'two'}))
+ @storage.insert(JournalMessage.create('test.topic', {name: 'three'}))
+ @storage.insert(JournalMessage.create('archived.topic', {name: 'four'},
+ timestamp: Time.now - DAY*100))
+ @storage.insert(JournalMessage.create('complex', {name: 'five', country: {
+ name: 'Italy'
+ }}))
+ @storage.insert(JournalMessage.create('complex', {name: 'six', country: {
+ name: 'Austria'
+ }}))
- @storage.insert(m)
- @storage.insert(JournalMessage.create('a.foo', {}))
- @storage.insert(JournalMessage.create('b.bar', {}))
- @storage.insert(JournalMessage.create('b.baz', {}))
- r = @storage.find(Query.define { timestamp(from: timestamp-DAY, to: timestamp+DAY) })
+ end
+
+ def test_journal
+ received = []
+ # this journal persists messages in the test storage:
+ journal = JournalBroker.new(storage: @storage)
- assert_equal(1, r.length)
- assert_equal(m, r.first)
end