2014-11-29

draw msgflow in reactive app





cpp_idioms.org



usually we got log like following:
[sys1] ---->   [sys2] 00001  MSG_0  0x00010002 0x00030004
[sys2] ---->   [sys3] 00002  MSG_1  0x00010002 0x00030004
[sys3] ---->   [sys1] 00003  MSG_2  0x00010002 0x00030004

but a diagram like following is more readable:
sys1   sys2   sys3   
  |----->|      |     MSG_0   [0x00010002 0x00030004]
  |      |----->|     MSG_1   [0x00010002 0x00030004]
  |<------------|     MSG_2   [0x00010002 0x00030004]

I implemented a simple app to draw this diagram: https://github.com/whunmr/msgflow

more complicated diagram generated from log:
ss3   kk3   zz1   qq1   qq2   kk1   bb1   aa1   ss1   
 |     |     |     |     |     |     |     |     *     MSG_0   [1] [0x00010002 0x00030004]
 |     |     |     |     |     |     |     |<----|     MSG_1   [2] [0x00010002 0x00030004]
 |     |     |     |     |     |     |     |---->|     MSG_2   [3] [0x00010002 0x00030004]
 |     |     |     |     |     |<----|     |     |     MSG_3   [4] [0x00010002 0x00030004]
 |     |     |     |     |     |---------------->|     MSG_4   [5] [0x00010002 0x00030004]
 |     |     |     |     |     |<----------------|     MSG_5   [6] [0x00010002 0x00030004]
 |     |     |     |     |     |     |     |<----|     MSG_6   [7] [0x00010002 0x00030004]
 |     |     |     |     |<----------------------|     MSG_7   [8] [0x00010002 0x00030004]
 |     |     |<----|     |     |     |     |     |     MSG_8   [9] [0x00010002 0x00030004]
 |     |     |---------------------------->|     |     MSG_9   [10] [0x00010002 0x00030004]
 |     |     |     |     |     |     |     |---->|     MSG_2   [11] [0x00010002 0x00030004]
 |     |<----------------------------|     |     |     MSG_3   [12] [0x00010002 0x00030004]
 |     |     |     |     |     |---------------->|     MSG_4   [13] [0x00010002 0x00030004]
 |     |<----------------------------------------|     MSG_5   [14] [0x00010002 0x00030004]
 |---------------------------------------->|     |     MSG_6   [15] [0x00010002 0x00030004]
 |---------------->|     |     |     |     |     |     MSG_7   [16] [0x00010002 0x00030004]
 |     |     |<----------------------------------|     MSG_8   [17] [0x00010002 0x00030004]
 |     |     |---------------------------------->|     MSG_9   [18] [0x00010002 0x00030004]

 


DSL for reactive application implementation in C++





cpp_idioms.org



def_mi(Basic_mi_x) {
                                         step(sync_call_1);
                                         step(sync_call_2);
        sysd<----------------------------async_step(async_call_1) {
                sysd-------------------->ack(msg_ack_1, on_msg_ack_1);
                sysd-------------------->ack(msg_ack_2, on_msg_ack_2);
                
                sysd-------------------->ack_ex(msg_ack_4)
                {
                                         step(sync_call_nested_1);
                        sysx<------------async_step(nested_async_call_1)
                        {
                                sysx---->ack(nested_msg_ack_1, on_nested_msg_ack_1);
                                sysx---->ack(nested_msg_ack_2, on_nested_msg_ack_2);
                                sysx---->ack(msg_ack_1, on_nested_msg_ack_3);            
                        } async_step_end;
                } on_msg_ack_ex_end;
        }async_step_end;
} def_mi_end;


https://github.com/whunmr/reactive_cpp



2014-05-09

Generate dynamic examples for cucumber Scenario outline






In following scenario outline, examples will be generated by `generate_example_data_func`:



Feature: test feature
  Scenario Outline: testing
    * test_tool __________________* "<foo>"
    * test_tool *__________________ "<bar>"
  Examples: 
    | foo                             | bar |
    | `generate_example_data_func`    |     |


implementation of `generate_example_data_func`, and steps:



Given(/^test_tool __________________\* "(.*?)"$/) do |arg1|
end

Given(/^test_tool \*__________________ "(.*?)"$/) do |arg1|
end

def generate_example_data_func table
  table <<  ["xxx", "yyy"]
  table <<  ["aaa", "bbb"]

  table
end

running result:
$ cucumber –expand



Feature: test feature

  Scenario Outline: testing                 # features/reading_report/test.feature:2
    * test_tool __________________* "<foo>" # features/step_definitions/new_step.rb:1
    * test_tool *__________________ "<bar>" # features/step_definitions/new_step.rb:4

    Examples: 

      Scenario: | xxx | yyy |                 # features/reading_report/test.feature:-1
        * test_tool __________________* "xxx"   # features/step_definitions/new_step.rb:1
        * test_tool *__________________ "yyy"   # features/step_definitions/new_step.rb:4

      Scenario: | aaa | bbb |                 # features/reading_report/test.feature:-1
        * test_tool __________________* "aaa"   # features/step_definitions/new_step.rb:1
        * test_tool *__________________ "bbb"   # features/step_definitions/new_step.rb:4

2 scenarios (2 passed)
4 steps (4 passed)
0m0.028s


To support dynamic generate example data, we need change the scenario_outline.rb`:



def create_examples_table(example_section_and_gherkin_examples)
  example_section = example_section_and_gherkin_examples[0]
  gherkin_examples = example_section_and_gherkin_examples[1]

  examples_location    = example_section[0]
  examples_comment     = example_section[1]
  examples_keyword     = example_section[2]
  examples_title       = example_section[3]
  examples_description = example_section[4]
  examples_matrix      = example_section[5]

  #CHANGE BEGIN#####################################################
  #~/.rvm/gems/ruby-1.9.3-p392/gems/cucumber-1.3.14/lib/cucumber/ast/scenario_outline.rb
  if examples_matrix.length > 1 && examples_matrix[1].length > 1
      using_function_to_generate_examples = !(examples_matrix[1][0] =~ /^`.*`$/).nil?

      

      if using_function_to_generate_examples
        function_str = examples_matrix[1][0].gsub!(/`(.*)`/, '\1') + "([" + examples_matrix[0].to_s  + "])"
        examples_matrix = eval(function_str)
      end
  end
  #CHANGE END#####################################################

  examples_table = OutlineTable.new(examples_matrix, self)
  ex = Examples.new(examples_location, examples_comment, examples_keyword, examples_title, examples_description, examples_table)
  ex.gherkin_statement(gherkin_examples)
  ex
end