require 'test/unit' #require 'yaml' require 'openwfe/flowexpressionid' require 'openwfe/expool/journalexpstorage' require 'openwfe/expressions/expressionmap' include OpenWFE class JournalPersistenceTest < Test::Unit::TestCase # # test journalling and appending to journal including: # - inserting :put and :del entries in the journal # - formatting for easy reading # - replay # def test_journalling_persistence fei = new_fei() feip = fei.parent_workflow_instance_id fes = JournalizedExpressionStorage.new("journal",nil) fes.clean(feip) fes[fei] = SequenceExpression.new(fei, nil, nil, nil, nil) fes.remove(fei, nil) assert fes.size(feip) == 2, "expected 2 entries in the journal" fes.to_human_s(feip) # prepare replay backup_journal = fes.backup(feip) fes.clean(fei) assert fes.size(feip) == 0, "storage is not empty" # replay replayer = JournalReplay.new(fes) replayer.replay(backup_journal) assert fes.size(feip) == 2, "2 entries have not been replayed" end def test_journal_truncate fes = JournalizedExpressionStorage.new("journal",nil) fei = new_fei() fei.workflow_instance_id = '789129' feip = fei.parent_workflow_instance_id fes.clean(feip) assert fes.size(feip) == 0 fe = SequenceExpression.new(fei, nil, nil, nil, nil) 24.times { |e| time = Time.gm(2007,01,17,e,00,00,00) entry = JournalEntry.new(:put, fei, fe, time) fes.write_to_journal(entry) } assert fes.size(feip) == 24 # truncate by number of lines assert fes.truncate!(feip, 10) == 10 assert fes.size(feip) == 10 # truncate by date date_limit = 5 assert fes.truncate!(feip, nil, Time.gm(2007,01,17,date_limit,00,00,00)) == 5 assert fes.size(feip) == 5 end # # no persistence, just test the journal entry class with a put def test_journal_entry_put fei = new_fei() fe = SequenceExpression.new(fei, nil, nil, nil, nil) journal_entry = JournalEntry.new(:put,fei,fe) journal_string = journal_entry.to_s journal_entry_read = JournalEntry.parse_from_string(journal_string) assert journal_entry_read.action == journal_entry.action assert journal_entry_read.action == :put assert journal_entry_read.fei.to_s == journal_entry.fei.to_s yamldump = YAML.dump(journal_entry_read.fe) assert journal_entry_read.fe != nil, "retrieved journal entry had a null expression" assert journal_entry_read.fe.to_s == journal_entry.fe.to_s, "string comparison failed for flow expression" assert yamldump.index("SequenceExpression") != nil end # # no persistence, just test the journal entry class with a del def test_journal_entry_del fei = new_fei() fe = SequenceExpression.new(fei, nil, nil, nil, nil) journal_entry = JournalEntry.new(:del,fei,fe) journal_string = journal_entry.to_s journal_entry_read = JournalEntry.parse_from_string(journal_string) assert journal_entry_read.action.to_s == journal_entry.action.to_s assert journal_entry_read.fei.to_s == journal_entry.fei.to_s assert journal_entry_read.fe == nil end # # this actually test the yaml output is expanded and readable, after the journal entry has been parsed def test_human_readable_journal_entry fei = new_fei() fe = SequenceExpression.new(fei, nil, nil, nil, nil) journal_entry = JournalEntry.new(:put,fei,fe) # test on a freshly made journal entry assert journal_entry_assert(journal_entry) # test on a re-parsed journal entry assert journal_entry_assert(JournalEntry.parse_from_string(journal_entry.to_s)) end protected def journal_entry_assert (journal_entry) human = journal_entry.to_human_s human.index("SequenceExpression") != nil end def new_fei () fei = OpenWFE::FlowExpressionId.new() fei.owfe_version = OPENWFE_VERSION fei.engine_id = 'this' fei.initial_engine_id = 'that' fei.workflow_definition_url = 'http://test/test.xml' fei.workflow_definition_name = 'test' fei.workflow_definition_revision = '1.0' fei.workflow_instance_id = '123456' fei.expression_name = 'do-test' fei.expression_id = '0.0' return fei end end