Class: TestRollback

Inherits:
Test::Unit::TestCase
  • Object
show all
Includes:
XamplAdHoc
Defined in:
lib/xamplr/test-support/test-rollback.rb,
lib/xamplr/test-support/test-deep-change.rb

Instance Method Summary collapse

Instance Method Details

#test_changeObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/xamplr/test-support/test-deep-change.rb', line 28

def test_change
  pname = "test_change"
  Xampl.transaction(pname, :in_memory){
    sack1 = Sack.new
    sack1.pid = "sack1"

    sack2 = sack1.new_sack("sack2"){ | sack |
      sack.new_bag{ | bag |
        bag.new_thing{ | thing |
          thing.info = "thing in sack2"
        }
      }
    }
  }

  #assert_equal(0, Xampl.count_changed)

  Xampl.transaction(pname){
    sack2 = Sack["sack2"]
    sack2.bag[0].thing[0].info = "changed value"
  }

  #assert_equal(0, Xampl.count_changed)
  Xampl.transaction(pname){
    Xampl.rollback
  }

  Xampl.transaction(pname){
    sack1 = Sack["sack1"]
    assert_equal("changed value", sack1.sack[0].bag[0].thing[0].info)
  }

end

#test_change_in_fsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/xamplr/test-support/test-deep-change.rb', line 62

def test_change_in_fs
  pname = "test_deep_change_in_fs" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.transaction(pname, :filesystem){
    sack1 = Sack.new
    sack1.pid = "sack1"

    sack2 = sack1.new_sack("sack2"){ | sack |
      sack.new_bag{ | bag |
        bag.new_thing{ | thing |
          thing.info = "thing in sack2"
        }
      }
    }
  }

  #assert_equal(0, Xampl.count_changed)

  Xampl.transaction(pname){
    sack2 = Sack["sack2"]
    sack2.bag[0].thing[0].info = "changed value"

    assert_equal(1, Xampl.count_changed)
    Xampl.persister.put_changed
  }

  #assert_equal(0, Xampl.count_changed)

  Xampl.transaction(pname){
    Xampl.rollback
  }

  Xampl.transaction(pname){
    sack1 = Sack["sack1"]
    assert_equal("changed value", sack1.sack[0].bag[0].thing[0].info)
  }

end

#test_change_out_of_persisterObject



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/xamplr/test-support/test-deep-change.rb', line 100

def test_change_out_of_persister
  pname = "test_change_out_of_persister"

  sack2 = nil

  Xampl.transaction(pname, :in_memory){
    sack1 = Sack.new
    sack1.pid = "sack1"

    sack2 = sack1.new_sack("sack2"){ | sack |
      sack.new_bag{ | bag |
        bag.new_thing{ | thing |
          thing.info = "thing in sack2"
        }
      }
    }
  }

  assert_raise(UnmanagedChange){
    sack2.bag[0].thing[0].info = "this is a very bad idea"
  }
  puts sack2.pp_xml

  Xampl.transaction(pname){
    Xampl.rollback
  }

  sack2a = nil
  Xampl.transaction(pname){
    sack2a = Sack["sack2"]
    sack2a.bag[0].new_thing.info = "change the sack"
  }
  puts sack2a.pp_xml
end

#test_rollbackObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/xamplr/test-support/test-rollback.rb', line 28

def test_rollback
  #sack1 = sack2 = nil

  Xampl.transaction("step7-persister", :in_memory){
    sack1 = Sack.new
    sack1.pid = "sack1"

    sack2 = sack1.new_sack("sack2"){ | sack |
      sack.new_bag{ | bag |
        bag.new_thing{ | thing |
          thing.info = "thing in sack2"
        }
      }
    }
  }

  #assert_equal(0, Xampl.count_changed)
  begin
    Xampl.transaction("step7-persister"){
      sack2 = Sack["sack2"]

      assert_equal(0, Xampl.count_changed)

      sack2.bag[0].thing[0].info = "this is a mistake"

      assert_equal(1, Xampl.count_changed)

      raise
    }
  rescue Exception
  end

  #assert_equal(0, Xampl.count_changed)

  Xampl.transaction("step7-persister"){
    sack1 = Sack["sack1"]
    assert_equal("thing in sack2", sack1.sack[0].bag[0].thing[0].info)
  }

end

#test_rollback_in_fsObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/xamplr/test-support/test-rollback.rb', line 69

def test_rollback_in_fs
  #sack1 = sack2 = nil

  pname = "test_rollback_in_fs" << Time.now.strftime("%Y%m%d-%H%M-%S") << rand.to_s
  Xampl.transaction(pname, :filesystem){
    sack1 = Sack.new
    sack1.pid = "sack1"

    sack2 = sack1.new_sack("sack2"){ | sack |
      sack.new_bag{ | bag |
        bag.new_thing{ | thing |
          thing.info = "thing in sack2"
        }
      }
    }
  }

  #assert_equal(0, Xampl.count_changed)
  begin
    Xampl.transaction(pname, :filesystem){
      sack2 = Sack["sack2"]

      sack2.bag[0].thing[0].info = "this is a mistake"

      raise
    }
  rescue Exception
  end

  #assert_equal(0, Xampl.count_changed)

  Xampl.transaction(pname, :filesystem){
    sack1 = Sack["sack1"]
    assert_equal("thing in sack2", sack1.sack[0].bag[0].thing[0].info)
  }

end