conflict 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/lib/conflict/core.rb +41 -17
- data/lib/conflict/domain.rb +13 -8
- data/lib/conflict/parsers.rb +58 -14
- data/test/common.rb +132 -132
- data/test/negative_test.rb +10 -9
- data/test/parser_test.rb +14 -14
- data/test/round_trip/expiration_test.rb +56 -56
- data/test/round_trip/happy_path_test.rb +105 -105
- data/test/round_trip/multi_diff_test.rb +67 -67
- data/test/round_trip/multiple_actions_test.rb +82 -82
- data/test/round_trip/negative_test.rb +109 -79
- data/test/round_trip/relative_path_test.rb +63 -63
- metadata +20 -19
@@ -1,82 +1,82 @@
|
|
1
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
-
# or more contributor license agreements. See the NOTICE file
|
3
|
-
# distributed with this work for additional information
|
4
|
-
# regarding copyright ownership. The ASF licenses this file
|
5
|
-
# to you under the Apache License, Version 2.0 (the
|
6
|
-
# "License"); you may not use this file except in compliance
|
7
|
-
# with the License. You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing,
|
12
|
-
# software distributed under the License is distributed on an
|
13
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
-
# KIND, either express or implied. See the License for the
|
15
|
-
# specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
|
18
|
-
require 'test/unit'
|
19
|
-
require 'conflict'
|
20
|
-
include Conflict
|
21
|
-
|
22
|
-
class RoundTripMultipleActionsTest < Test::Unit::TestCase
|
23
|
-
include ConflictConstants
|
24
|
-
RESOURCE = CONFLICT_URL + '/test_data.txt'
|
25
|
-
DATA_DIR = './test/data/three/'
|
26
|
-
|
27
|
-
def setup
|
28
|
-
|
29
|
-
@added = File::new(DATA_DIR + "added.diff.txt").to_s
|
30
|
-
@deleted = File::new(DATA_DIR + "deleted.diff.txt").to_s
|
31
|
-
@changed = File::new(DATA_DIR + "changed.diff.txt").to_s
|
32
|
-
@info = File::new(DATA_DIR + "conflict.info.txt").to_s
|
33
|
-
|
34
|
-
@first = Event::new(CLIENT_ONE, "added", RESOURCE)
|
35
|
-
@second = Event::new(CLIENT_TWO, "deleted", RESOURCE)
|
36
|
-
@third = Event::new(CLIENT_THREE, "changed", RESOURCE)
|
37
|
-
|
38
|
-
@conf = {:port=>83}
|
39
|
-
|
40
|
-
@thread = Thread.new do
|
41
|
-
Server::new(@conf).start
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
def teardown
|
47
|
-
@thread.kill
|
48
|
-
@thread.join(5)
|
49
|
-
end
|
50
|
-
|
51
|
-
def test_workflow_using_add_delete_and_change
|
52
|
-
|
53
|
-
client_one = Client::new({:id=>CLIENT_ONE}.merge(@conf)) # dev start conflict clients
|
54
|
-
client_two = Client::new({:id=>CLIENT_TWO}.merge(@conf))
|
55
|
-
client_three = Client::new({:id=>CLIENT_THREE}.merge(@conf))
|
56
|
-
|
57
|
-
response = client_one.diff(@added, @info)
|
58
|
-
assert_equal [], response
|
59
|
-
|
60
|
-
response = client_two.diff(@deleted, @info)
|
61
|
-
assert [Conflict::Conflict.new(@second, @first)].eql?(response)
|
62
|
-
|
63
|
-
response = client_three.diff(@changed, @info)
|
64
|
-
assert [Conflict::Conflict.new(@third, @first),Conflict::Conflict.new(@third, @second)].eql?(response)
|
65
|
-
|
66
|
-
response = client_two.revert @info
|
67
|
-
assert_equal [], response
|
68
|
-
|
69
|
-
response = client_one.diff(@added, @info)
|
70
|
-
assert [Conflict::Conflict.new(@first, @third)].eql?(response)
|
71
|
-
|
72
|
-
response = client_three.diff(@changed, @info)
|
73
|
-
assert [Conflict::Conflict.new(@third, @first)].eql?(response)
|
74
|
-
|
75
|
-
response = client_one.revert @info
|
76
|
-
assert_equal [], response
|
77
|
-
|
78
|
-
response = client_three.revert @info
|
79
|
-
assert_equal [], response
|
80
|
-
end
|
81
|
-
|
82
|
-
end
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class RoundTripMultipleActionsTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
RESOURCE = CONFLICT_URL + '/test_data.txt'
|
25
|
+
DATA_DIR = './test/data/three/'
|
26
|
+
|
27
|
+
def setup
|
28
|
+
|
29
|
+
@added = File::new(DATA_DIR + "added.diff.txt").to_s
|
30
|
+
@deleted = File::new(DATA_DIR + "deleted.diff.txt").to_s
|
31
|
+
@changed = File::new(DATA_DIR + "changed.diff.txt").to_s
|
32
|
+
@info = File::new(DATA_DIR + "conflict.info.txt").to_s
|
33
|
+
|
34
|
+
@first = Event::new(CLIENT_ONE, "added", RESOURCE)
|
35
|
+
@second = Event::new(CLIENT_TWO, "deleted", RESOURCE)
|
36
|
+
@third = Event::new(CLIENT_THREE, "changed", RESOURCE)
|
37
|
+
|
38
|
+
@conf = {:port=>83}
|
39
|
+
|
40
|
+
@thread = Thread.new do
|
41
|
+
Server::new(@conf).start
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
def teardown
|
47
|
+
@thread.kill
|
48
|
+
@thread.join(5)
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_workflow_using_add_delete_and_change
|
52
|
+
|
53
|
+
client_one = Client::new({:id=>CLIENT_ONE}.merge(@conf)) # dev start conflict clients
|
54
|
+
client_two = Client::new({:id=>CLIENT_TWO}.merge(@conf))
|
55
|
+
client_three = Client::new({:id=>CLIENT_THREE}.merge(@conf))
|
56
|
+
|
57
|
+
response = client_one.diff(@added, @info)
|
58
|
+
assert_equal [], response
|
59
|
+
|
60
|
+
response = client_two.diff(@deleted, @info)
|
61
|
+
assert [Conflict::Conflict.new(@second, @first)].eql?(response)
|
62
|
+
|
63
|
+
response = client_three.diff(@changed, @info)
|
64
|
+
assert [Conflict::Conflict.new(@third, @first),Conflict::Conflict.new(@third, @second)].eql?(response)
|
65
|
+
|
66
|
+
response = client_two.revert @info
|
67
|
+
assert_equal [], response
|
68
|
+
|
69
|
+
response = client_one.diff(@added, @info)
|
70
|
+
assert [Conflict::Conflict.new(@first, @third)].eql?(response)
|
71
|
+
|
72
|
+
response = client_three.diff(@changed, @info)
|
73
|
+
assert [Conflict::Conflict.new(@third, @first)].eql?(response)
|
74
|
+
|
75
|
+
response = client_one.revert @info
|
76
|
+
assert_equal [], response
|
77
|
+
|
78
|
+
response = client_three.revert @info
|
79
|
+
assert_equal [], response
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
@@ -1,79 +1,109 @@
|
|
1
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
-
# or more contributor license agreements. See the NOTICE file
|
3
|
-
# distributed with this work for additional information
|
4
|
-
# regarding copyright ownership. The ASF licenses this file
|
5
|
-
# to you under the Apache License, Version 2.0 (the
|
6
|
-
# "License"); you may not use this file except in compliance
|
7
|
-
# with the License. You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing,
|
12
|
-
# software distributed under the License is distributed on an
|
13
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
-
# KIND, either express or implied. See the License for the
|
15
|
-
# specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
|
18
|
-
require 'test/unit'
|
19
|
-
require 'conflict'
|
20
|
-
include Conflict
|
21
|
-
|
22
|
-
class NegativeServerTest < Test::Unit::TestCase
|
23
|
-
include ConflictConstants
|
24
|
-
DATA_DIR = './test/data/three/'
|
25
|
-
|
26
|
-
def
|
27
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
end
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class NegativeServerTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
DATA_DIR = './test/data/three/'
|
25
|
+
|
26
|
+
def setup
|
27
|
+
|
28
|
+
@added = File::new(DATA_DIR + "added.diff.txt").to_s
|
29
|
+
@deleted = File::new(DATA_DIR + "deleted.diff.txt").to_s
|
30
|
+
@info = File::new(DATA_DIR + "conflict.info.txt").to_s
|
31
|
+
@clients = [{}, {"client"=>""}, {"client"=>" "}, {"client"=>"foo"}]
|
32
|
+
@diffs = [{}, {"diff"=>""}, {"diff"=>" "}, {"diff"=>@added} ]
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_combinations
|
37
|
+
|
38
|
+
@cfg = {:port=>84}
|
39
|
+
@thread = Thread.new do
|
40
|
+
Server::new(@cfg).start
|
41
|
+
end
|
42
|
+
|
43
|
+
infos = [{}, {"info"=>""}, {"info"=>" "}, {"info"=>@info} ]
|
44
|
+
|
45
|
+
# leaving these out until I can figure out how to make multi-params happen w/ ruby 1.8.4
|
46
|
+
# {"diff"=>[@added,@deleted]}
|
47
|
+
# {"info"=>[@info,@info]}
|
48
|
+
# [3, 4, 4]
|
49
|
+
|
50
|
+
# single diff with no changes, single diff w/ no changes,
|
51
|
+
# single diff w/ changes, multi-diff with changes
|
52
|
+
good = [ [3, 1, 3], [3, 2, 3], [3, 3, 3] ]
|
53
|
+
|
54
|
+
# tests all mathematical possibilities
|
55
|
+
@clients.each_index do | i |
|
56
|
+
@diffs.each_index do | j |
|
57
|
+
infos.each_index do | k |
|
58
|
+
|
59
|
+
body = @clients[i].merge(@diffs[j]).merge(infos[k])
|
60
|
+
code = send body, Conflict::DIFF_URL
|
61
|
+
point = [i, j, k]
|
62
|
+
expected_code = good.index(point) ? 200 : 500
|
63
|
+
assert_equal(expected_code.to_s, code, point.to_s + " -> " + body.to_s)
|
64
|
+
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
@thread.kill
|
70
|
+
@thread.join(5)
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_combinations_cvs
|
75
|
+
|
76
|
+
@cfg = {:port=>88}
|
77
|
+
@thread = Thread.new do
|
78
|
+
Server::new(@cfg).start
|
79
|
+
end
|
80
|
+
|
81
|
+
good = [ [3, 1], [3, 2], [3, 3] ]
|
82
|
+
|
83
|
+
@clients.each_index do | i |
|
84
|
+
@diffs.each_index do | j |
|
85
|
+
|
86
|
+
body = @clients[i].merge(@diffs[j])
|
87
|
+
code = send body, Conflict::DIFF_CVS_URL
|
88
|
+
point = [i, j]
|
89
|
+
expected_code = good.index(point) ? 200 : 500
|
90
|
+
assert_equal(expected_code.to_s, code, point.to_s + " -> " + body.to_s)
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
@thread.kill
|
96
|
+
@thread.join(5)
|
97
|
+
|
98
|
+
end
|
99
|
+
|
100
|
+
def send body, url
|
101
|
+
|
102
|
+
req = Net::HTTP::Post.new(url)
|
103
|
+
req.set_form_data(body)
|
104
|
+
http = Net::HTTP.new("127.0.0.1", @cfg[:port])
|
105
|
+
res = http.request(req).code
|
106
|
+
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
@@ -1,63 +1,63 @@
|
|
1
|
-
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
-
# or more contributor license agreements. See the NOTICE file
|
3
|
-
# distributed with this work for additional information
|
4
|
-
# regarding copyright ownership. The ASF licenses this file
|
5
|
-
# to you under the Apache License, Version 2.0 (the
|
6
|
-
# "License"); you may not use this file except in compliance
|
7
|
-
# with the License. You may obtain a copy of the License at
|
8
|
-
#
|
9
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
-
#
|
11
|
-
# Unless required by applicable law or agreed to in writing,
|
12
|
-
# software distributed under the License is distributed on an
|
13
|
-
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
-
# KIND, either express or implied. See the License for the
|
15
|
-
# specific language governing permissions and limitations
|
16
|
-
# under the License.
|
17
|
-
|
18
|
-
require 'test/unit'
|
19
|
-
require 'conflict'
|
20
|
-
include Conflict
|
21
|
-
|
22
|
-
class RoundTripRelativePathTest < Test::Unit::TestCase
|
23
|
-
include ConflictConstants
|
24
|
-
|
25
|
-
def test_relative_path
|
26
|
-
|
27
|
-
cfg = {:port=>82}
|
28
|
-
@thread = Thread.new do
|
29
|
-
Server::new(cfg).start
|
30
|
-
end
|
31
|
-
|
32
|
-
info_one = File.new(STOMP_1_INFO_PATH).to_s
|
33
|
-
info_two = File.new(STOMP_2_INFO_PATH).to_s
|
34
|
-
diff_one = File::new(STOMP_1_DIFF_PATH).to_s
|
35
|
-
diff_two = File::new(STOMP_2_DIFF_PATH).to_s
|
36
|
-
|
37
|
-
first_event = Event::new(CLIENT_ONE, "changed", STOMP_RESOURCE)
|
38
|
-
second_event = Event::new(CLIENT_TWO, "changed", STOMP_RESOURCE)
|
39
|
-
|
40
|
-
client_one = Client::new({:id=>CLIENT_ONE}.merge(cfg))
|
41
|
-
client_two = Client::new({:id=>CLIENT_TWO}.merge(cfg))
|
42
|
-
|
43
|
-
response = client_one.diff diff_one, info_one
|
44
|
-
assert_equal [], response
|
45
|
-
|
46
|
-
response = client_two.diff diff_two, info_two
|
47
|
-
assert [Conflict::Conflict::new(second_event, first_event)].eql?(response)
|
48
|
-
|
49
|
-
response = client_one.resend
|
50
|
-
assert [Conflict::Conflict::new(first_event, second_event)].eql?(response)
|
51
|
-
|
52
|
-
response = client_two.revert info_two
|
53
|
-
assert_equal [], response
|
54
|
-
|
55
|
-
response = client_one.revert info_one
|
56
|
-
assert_equal [], response
|
57
|
-
|
58
|
-
@thread.kill
|
59
|
-
@thread.join(5)
|
60
|
-
|
61
|
-
end
|
62
|
-
|
63
|
-
end
|
1
|
+
# Licensed to the Apache Software Foundation (ASF) under one
|
2
|
+
# or more contributor license agreements. See the NOTICE file
|
3
|
+
# distributed with this work for additional information
|
4
|
+
# regarding copyright ownership. The ASF licenses this file
|
5
|
+
# to you under the Apache License, Version 2.0 (the
|
6
|
+
# "License"); you may not use this file except in compliance
|
7
|
+
# with the License. You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing,
|
12
|
+
# software distributed under the License is distributed on an
|
13
|
+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
14
|
+
# KIND, either express or implied. See the License for the
|
15
|
+
# specific language governing permissions and limitations
|
16
|
+
# under the License.
|
17
|
+
|
18
|
+
require 'test/unit'
|
19
|
+
require 'conflict'
|
20
|
+
include Conflict
|
21
|
+
|
22
|
+
class RoundTripRelativePathTest < Test::Unit::TestCase
|
23
|
+
include ConflictConstants
|
24
|
+
|
25
|
+
def test_relative_path
|
26
|
+
|
27
|
+
cfg = {:port=>82}
|
28
|
+
@thread = Thread.new do
|
29
|
+
Server::new(cfg).start
|
30
|
+
end
|
31
|
+
|
32
|
+
info_one = File.new(STOMP_1_INFO_PATH).to_s
|
33
|
+
info_two = File.new(STOMP_2_INFO_PATH).to_s
|
34
|
+
diff_one = File::new(STOMP_1_DIFF_PATH).to_s
|
35
|
+
diff_two = File::new(STOMP_2_DIFF_PATH).to_s
|
36
|
+
|
37
|
+
first_event = Event::new(CLIENT_ONE, "changed", STOMP_RESOURCE)
|
38
|
+
second_event = Event::new(CLIENT_TWO, "changed", STOMP_RESOURCE)
|
39
|
+
|
40
|
+
client_one = Client::new({:id=>CLIENT_ONE}.merge(cfg))
|
41
|
+
client_two = Client::new({:id=>CLIENT_TWO}.merge(cfg))
|
42
|
+
|
43
|
+
response = client_one.diff diff_one, info_one
|
44
|
+
assert_equal [], response
|
45
|
+
|
46
|
+
response = client_two.diff diff_two, info_two
|
47
|
+
assert [Conflict::Conflict::new(second_event, first_event)].eql?(response)
|
48
|
+
|
49
|
+
response = client_one.resend
|
50
|
+
assert [Conflict::Conflict::new(first_event, second_event)].eql?(response)
|
51
|
+
|
52
|
+
response = client_two.revert info_two
|
53
|
+
assert_equal [], response
|
54
|
+
|
55
|
+
response = client_one.revert info_one
|
56
|
+
assert_equal [], response
|
57
|
+
|
58
|
+
@thread.kill
|
59
|
+
@thread.join(5)
|
60
|
+
|
61
|
+
end
|
62
|
+
|
63
|
+
end
|