content_server 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (137) hide show
  1. data/bin/backup_server +8 -20
  2. data/bin/content_server +8 -20
  3. data/bin/testing_memory +60 -0
  4. data/bin/testing_server +57 -0
  5. data/ext/run_in_background/mkrf_conf.rb +34 -0
  6. data/lib/content_data/content_data.rb +613 -0
  7. data/lib/content_data/version.rb +3 -0
  8. data/lib/content_data.rb +6 -0
  9. data/lib/content_server/backup_server.rb +65 -86
  10. data/lib/content_server/content_server.rb +47 -77
  11. data/lib/content_server/file_streamer.rb +27 -33
  12. data/lib/content_server/queue_copy.rb +154 -49
  13. data/lib/content_server/queue_indexer.rb +19 -11
  14. data/lib/content_server/remote_content.rb +41 -23
  15. data/lib/content_server/server.rb +91 -0
  16. data/lib/content_server/version.rb +1 -1
  17. data/lib/content_server.rb +0 -15
  18. data/lib/email/email.rb +87 -0
  19. data/lib/email/version.rb +3 -0
  20. data/lib/email.rb +4 -0
  21. data/lib/file_copy/copy.rb +68 -0
  22. data/lib/file_copy/version.rb +4 -0
  23. data/lib/file_copy.rb +4 -0
  24. data/lib/file_indexing/index_agent.rb +170 -0
  25. data/lib/file_indexing/indexer_patterns.rb +72 -0
  26. data/lib/file_indexing/version.rb +3 -0
  27. data/lib/file_indexing.rb +9 -0
  28. data/lib/file_monitoring/file_monitoring.rb +105 -0
  29. data/lib/file_monitoring/monitor_path.rb +304 -0
  30. data/lib/file_monitoring/version.rb +3 -0
  31. data/lib/file_monitoring.rb +29 -0
  32. data/lib/file_utils/file_generator/README +97 -0
  33. data/lib/file_utils/file_generator/file_generator.rb +156 -0
  34. data/lib/file_utils/file_utils.rb +260 -0
  35. data/lib/file_utils/version.rb +3 -0
  36. data/lib/file_utils.rb +4 -0
  37. data/lib/log/version.rb +3 -0
  38. data/lib/log.rb +188 -0
  39. data/lib/networking/tcp.rb +213 -0
  40. data/lib/networking/version.rb +3 -0
  41. data/lib/networking.rb +4 -0
  42. data/lib/params/version.rb +3 -0
  43. data/lib/params.rb +419 -0
  44. data/lib/process_monitoring/monitoring.rb +85 -0
  45. data/lib/process_monitoring/monitoring_info.rb +79 -0
  46. data/lib/process_monitoring/send_email.rb +40 -0
  47. data/lib/process_monitoring/thread_safe_hash.rb +77 -0
  48. data/lib/process_monitoring/version.rb +3 -0
  49. data/lib/process_monitoring.rb +6 -0
  50. data/lib/run_in_background/version.rb +3 -0
  51. data/lib/run_in_background.rb +432 -0
  52. data/lib/testing_memory/testing_memory.rb +187 -0
  53. data/lib/testing_server/testing_server.rb +236 -0
  54. data/lib/testing_server/version.rb +3 -0
  55. data/lib/testing_server.rb +12 -0
  56. data/lib/validations/index_validations.rb +106 -0
  57. data/lib/validations/version.rb +3 -0
  58. data/lib/validations.rb +4 -0
  59. data/spec/content_data/validations_spec.rb +113 -0
  60. data/spec/file_copy/copy_spec.rb +54 -0
  61. data/spec/file_indexing/index_agent_spec.rb +53 -0
  62. data/spec/networking/tcp_spec.rb +95 -0
  63. data/spec/validations/index_validations_spec.rb +77 -0
  64. data/test/content_data/content_data_test.rb +290 -0
  65. data/test/file_generator/file_generator_spec.rb +84 -0
  66. data/test/file_indexing/index_agent_test/New.txt +0 -0
  67. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/bin/libexslt.dll +0 -0
  68. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/bin/libxslt.dll +0 -0
  69. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/bin/xsltproc.exe +0 -0
  70. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libexslt/exslt.h +102 -0
  71. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libexslt/exsltconfig.h +73 -0
  72. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libexslt/exsltexports.h +140 -0
  73. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libexslt/libexslt.h +29 -0
  74. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/attributes.h +38 -0
  75. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/documents.h +93 -0
  76. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/extensions.h +262 -0
  77. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/extra.h +80 -0
  78. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/functions.h +78 -0
  79. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/imports.h +75 -0
  80. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/keys.h +53 -0
  81. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/libxslt.h +30 -0
  82. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/namespaces.h +68 -0
  83. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/numbersInternals.h +69 -0
  84. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/pattern.h +81 -0
  85. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/preproc.h +43 -0
  86. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/security.h +104 -0
  87. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/templates.h +77 -0
  88. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/transform.h +207 -0
  89. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/trio.h +216 -0
  90. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/triodef.h +220 -0
  91. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/variables.h +91 -0
  92. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/win32config.h +101 -0
  93. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/xslt.h +103 -0
  94. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/xsltInternals.h +1967 -0
  95. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/xsltconfig.h +172 -0
  96. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/xsltexports.h +142 -0
  97. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/xsltlocale.h +57 -0
  98. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/xsltutils.h +309 -0
  99. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/include/libxslt/xsltwin32config.h +105 -0
  100. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/lib/libexslt.lib +0 -0
  101. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/lib/libexslt_a.lib +0 -0
  102. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/lib/libxslt.lib +0 -0
  103. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/lib/libxslt_a.lib +0 -0
  104. data/test/file_indexing/index_agent_test/libxslt-1.1.26.win32/readme.txt +22 -0
  105. data/test/file_indexing/index_agent_test/patterns.input +3 -0
  106. data/test/file_indexing/index_agent_test.rb +51 -0
  107. data/test/file_monitoring/file_monitoring_test/conf.yml +4 -0
  108. data/test/file_monitoring/file_monitoring_test/conf_win32.yml +5 -0
  109. data/test/file_monitoring/file_monitoring_test/log +56 -0
  110. data/test/file_monitoring/file_monitoring_test.rb +0 -0
  111. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000 +1000 -0
  112. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.0 +1000 -0
  113. data/test/file_monitoring/monitor_path_test/dir1000/test_file.1000.1 +1000 -0
  114. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500 +1500 -0
  115. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.0 +1500 -0
  116. data/test/file_monitoring/monitor_path_test/dir1500/test_file.1500.1 +1500 -0
  117. data/test/file_monitoring/monitor_path_test/test_file.500 +500 -0
  118. data/test/file_monitoring/monitor_path_test/test_file.500.0 +500 -0
  119. data/test/file_monitoring/monitor_path_test/test_file.500.1 +500 -0
  120. data/test/file_monitoring/monitor_path_test.rb +153 -0
  121. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500 +1500 -0
  122. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500.0 +1500 -0
  123. data/test/file_utils/fileutil_mksymlink_test/dir1000/dir1500/test_file.1500.1 +1500 -0
  124. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000 +1000 -0
  125. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000.0 +1000 -0
  126. data/test/file_utils/fileutil_mksymlink_test/dir1000/test_file.1000.1 +1000 -0
  127. data/test/file_utils/fileutil_mksymlink_test/test_file.500 +500 -0
  128. data/test/file_utils/fileutil_mksymlink_test/test_file.500.0 +500 -0
  129. data/test/file_utils/fileutil_mksymlink_test/test_file.500.1 +500 -0
  130. data/test/file_utils/fileutil_mksymlink_test.rb +125 -0
  131. data/test/file_utils/time_modification_test.rb +132 -0
  132. data/test/params/params_spec.rb +280 -0
  133. data/test/params/params_test.rb +43 -0
  134. data/test/run_in_background/run_in_background_test.rb +122 -0
  135. data/test/run_in_background/test_app +57 -0
  136. metadata +272 -132
  137. data/lib/content_server/globals.rb +0 -10
@@ -0,0 +1,77 @@
1
+ require 'rspec'
2
+ require_relative '../../lib/validations.rb'
3
+
4
+ module Validations
5
+ module Spec
6
+ describe 'Index validation' do
7
+ context 'of index from other file system' do
8
+ before :all do
9
+ @size = 100
10
+ @path = '/dir1/dir2/file'
11
+ @path2 = '/dir3/dir4/file'
12
+ @path3 = '/dir5/dir6/file'
13
+ @path4 = '/dir7/dir8/file'
14
+ @mod_time = 123456
15
+ @checksum = 'abcde987654321'
16
+ @checksum2 = '987654321abcde'
17
+ @server = 'server_1'
18
+ end
19
+
20
+ before :each do
21
+ @index = ContentData::ContentData.new
22
+ @index.add_instance @checksum, @size, @server, @path, @mod_time
23
+ @index.add_instance @checksum2, @size, @server, @path2, @mod_time
24
+
25
+ @remote_index = ContentData::ContentData.new
26
+ @remote_index.add_instance @checksum, @size, @server, @path3, @mod_time
27
+ @remote_index.add_instance @checksum2, @size, @server, @path4, @mod_time
28
+
29
+ File.stub(:exists?).and_return(true)
30
+ File.stub(:size).and_return(@size)
31
+ File.stub(:mtime).and_return(@mod_time)
32
+ Params['instance_check_level'] = 'shallow'
33
+ end
34
+
35
+ it 'succeeds when all remote contents has valid local instance' do
36
+ IndexValidations.validate_remote_index(@remote_index, @index).should be_true
37
+ end
38
+
39
+ it 'fails when remote content is absent' do
40
+ absent_checksum = '123'
41
+ absent_path = '/dir9/dir10/absent_file'
42
+ @remote_index.add_instance absent_checksum, @size, @server, absent_path, @mod_time
43
+ IndexValidations.validate_remote_index(@remote_index, @index).should be_false
44
+ end
45
+
46
+ it 'fails when local instance of remote content is invalid' do
47
+ modified_mtime = @mod_time + 10
48
+ File.stub(:mtime).with(@path).and_return(modified_mtime)
49
+ IndexValidations.validate_remote_index(@remote_index, @index).should be_false
50
+ end
51
+
52
+ it ':failed param returns index of absent contents or contents without valid instances' do
53
+ # one instance that absent,
54
+ absent_checksum = '123'
55
+ absent_path = '/dir9/dir10/absent_file'
56
+ @remote_index.add_instance absent_checksum, @size, @server, absent_path, @mod_time
57
+
58
+ # invalid instance has @path2 path on local and @path4 on remote
59
+ modified_mtime = @mod_time + 10
60
+ File.stub(:mtime).with(@path2).and_return(modified_mtime)
61
+
62
+ failed = ContentData::ContentData.new
63
+ IndexValidations.validate_remote_index(@remote_index, @index, :failed => failed)
64
+ # should be two failed contents, with one instance per content
65
+ failed.contents_size.should eq(2)
66
+ failed.content_exists(absent_checksum).should be_true
67
+ failed.content_exists(@checksum2).should be_true
68
+ failed.checksum_instances_size(absent_checksum).should eq(1)
69
+ failed.checksum_instances_size(@checksum2).should eq(1)
70
+ failed.instance_exists(absent_path, @server, absent_checksum).should be_true
71
+ failed.instance_exists(@path4, @server, @checksum2).should be_true
72
+ end
73
+ end
74
+ end
75
+ end
76
+ end
77
+
@@ -0,0 +1,290 @@
1
+ require 'time.rb'
2
+ require 'test/unit'
3
+ require 'content_server/server'
4
+ require_relative '../../lib/content_data/content_data.rb'
5
+
6
+ class TestContentData < Test::Unit::TestCase
7
+
8
+
9
+ Params.boolean('enable_monitoring', false, 'Whether to enable process monitoring or not.')
10
+ ContentServer.init_globals
11
+
12
+ def test_cloning_db_1
13
+ content_data = ContentData::ContentData.new
14
+ content_data.add_instance("A1", 1242, "server_1",
15
+ "/home/file_1", 2222222222)
16
+
17
+ content_data_cloned = ContentData::ContentData.new(content_data)
18
+ #check that DBs are equal
19
+ assert_equal(content_data, content_data_cloned)
20
+
21
+ content_data_cloned.add_instance("A1", 1242, "server_1",
22
+ "/home/file_2", 3333333333)
23
+ #change orig DB - size
24
+ assert_not_equal(content_data, content_data_cloned)
25
+ end
26
+
27
+ def test_cloning_db_2
28
+ content_data = ContentData::ContentData.new
29
+ content_data.add_instance("A1", 1242, "server_1",
30
+ "/home/file_1", 2222222222)
31
+
32
+ content_data_cloned = ContentData::ContentData.new(content_data)
33
+ #check that DBs are equal
34
+ assert_equal(content_data, content_data_cloned)
35
+
36
+ content_data_cloned.add_instance("A2", 1243, "server_1",
37
+ "/home/file_2", 3333333333)
38
+ #change orig DB - size
39
+ assert_not_equal(content_data, content_data_cloned)
40
+ end
41
+
42
+
43
+ def test_add_instance
44
+ #create first content with instance
45
+ content_data = ContentData::ContentData.new
46
+ content_data.add_instance("A1", 50, "server_1",
47
+ "/home/file_1", 2222222222)
48
+
49
+ #Add new instance - different size
50
+ # size would be overriden should not be added
51
+ content_data.add_instance("A1", 60, "server_1",
52
+ "/home/file_2", 2222222222)
53
+ assert_equal("1\nA1,60,2222222222\n2\nA1,60,server_1,/home/file_1,2222222222\nA1,60,server_1,/home/file_2,2222222222\n", content_data.to_s)
54
+
55
+ #Add new instance - new content
56
+ #both new content and new instances are created in DB
57
+ content_data.add_instance("A2", 60, "server_1",
58
+ "/home/file_2", 3333333333)
59
+ assert_equal("2\nA1,60,2222222222\nA2,60,3333333333\n3\n" +
60
+ "A1,60,server_1,/home/file_1,2222222222\n" +
61
+ "A1,60,server_1,/home/file_2,2222222222\n" +
62
+ "A2,60,server_1,/home/file_2,3333333333\n", content_data.to_s)
63
+
64
+ #Add new instance - same content
65
+ content_data.add_instance("A2", 60, "server_1",
66
+ "/home/file_3", 4444444444)
67
+ assert_equal("2\nA1,60,2222222222\nA2,60,3333333333\n4\n" +
68
+ "A1,60,server_1,/home/file_1,2222222222\n" +
69
+ "A1,60,server_1,/home/file_2,2222222222\n" +
70
+ "A2,60,server_1,/home/file_2,3333333333\n" +
71
+ "A2,60,server_1,/home/file_3,4444444444\n", content_data.to_s)
72
+ end
73
+
74
+ def test_instance_exists
75
+ content_data = ContentData::ContentData.new
76
+ content_data.add_instance("A129", 50, "server_1",
77
+ "/home/file_1", 2222222222)
78
+ assert_equal(true, content_data.instance_exists('/home/file_1', 'server_1'))
79
+ assert_equal(false, content_data.instance_exists('/home/file_1', 'stum'))
80
+ end
81
+
82
+ def test_remove_instance
83
+ #remove instance also removes content
84
+ content_data = ContentData::ContentData.new
85
+ content_data.add_instance("A1", 50, "server_1",
86
+ "/home/file_1", 2222222222)
87
+ assert_equal(true, content_data.content_exists('A1'))
88
+ assert_equal(true, content_data.instance_exists('/home/file_1', 'server_1'))
89
+ content_data.remove_instance('server_1', '/home/file_1')
90
+ assert_equal(false, content_data.instance_exists('/home/file_1', 'server_1'))
91
+ assert_equal(false, content_data.content_exists('A1'))
92
+
93
+ #remove instance does not remove content
94
+ content_data.add_instance("A1", 50, "server_1",
95
+ "/home/file_1", 2222222222)
96
+ content_data.add_instance("A1", 50, "server_1",
97
+ "/home/file_2", 3333333333)
98
+ assert_equal(true, content_data.content_exists('A1'))
99
+ assert_equal(true, content_data.instance_exists('/home/file_1', 'server_1'))
100
+ content_data.remove_instance('server_1', '/home/file_1')
101
+ assert_equal(false, content_data.instance_exists('/home/file_1', 'server_1'))
102
+ assert_equal(true, content_data.content_exists('A1'))
103
+
104
+ #remove also removes content
105
+ content_data.remove_instance('server_1', '/home/file_2')
106
+ assert_equal(false, content_data.instance_exists('/home/file_1', 'server_1'))
107
+ assert_equal(false, content_data.content_exists('A1'))
108
+ end
109
+
110
+ def test_to_file_from_file
111
+ content_data = ContentData::ContentData.new
112
+ content_data.add_instance("A1", 50, "server_1",
113
+ "/home/file_1", 22222222222)
114
+ content_data.add_instance("B1", 60, "server_1",
115
+ "/home/file_2", 44444444444)
116
+ content_data.add_instance("B1", 60, "server_1",
117
+ "/home/file_3", 55555555555)
118
+ file_moc_object = StringIO.new
119
+ file_moc_object.write(content_data.to_s)
120
+ test_file = __FILE__ + 'test'
121
+ content_data.to_file(test_file)
122
+ content_data_2 = ContentData::ContentData.new
123
+ content_data_2.from_file(test_file)
124
+ assert_equal(true, content_data == content_data_2)
125
+ end
126
+
127
+ def test_merge
128
+ content_data_a = ContentData::ContentData.new
129
+ content_data_a.add_instance("A1", 50, "server_1",
130
+ "/home/file_1", 22222222222)
131
+
132
+ content_data_b = ContentData::ContentData.new
133
+ content_data_b.add_instance("B1", 60, "server_1",
134
+ "/home/file_2", 44444444444)
135
+ content_data_b.add_instance("B1", 60, "server_1",
136
+ "/home/file_3", 55555555555)
137
+ content_data_merged = ContentData.merge(content_data_a, content_data_b)
138
+ assert_equal(content_data_merged.to_s, "2\nB1,60,44444444444\nA1,50,22222222222\n3\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\nA1,50,server_1,/home/file_1,22222222222\n")
139
+ content_data_a.remove_instance('server_1', '/home/file_1')
140
+ assert_equal(content_data_merged.to_s, "2\nB1,60,44444444444\nA1,50,22222222222\n3\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\nA1,50,server_1,/home/file_1,22222222222\n")
141
+ content_data_b.remove_instance('server_1', '/home/file_2')
142
+ assert_equal(content_data_merged.to_s, "2\nB1,60,44444444444\nA1,50,22222222222\n3\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\nA1,50,server_1,/home/file_1,22222222222\n")
143
+
144
+ end
145
+
146
+ def test_merge_override_b
147
+ content_data_a = ContentData::ContentData.new
148
+ content_data_a.add_instance("A1", 50, "server_1",
149
+ "/home/file_1", 22222222222)
150
+
151
+ content_data_b = ContentData::ContentData.new
152
+ content_data_b.add_instance("A1", 50, "server_1",
153
+ "/home/file_1", 22222222222)
154
+ content_data_b.add_instance("B1", 60, "server_1",
155
+ "/home/file_2", 44444444444)
156
+ content_data_b.add_instance("B1", 60, "server_1",
157
+ "/home/file_3", 55555555555)
158
+ content_data_merged = ContentData.merge_override_b(content_data_a, content_data_b)
159
+ assert_equal("2\nA1,50,22222222222\nB1,60,44444444444\n3\nA1,50,server_1,/home/file_1,22222222222\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n",
160
+ content_data_merged.to_s)
161
+
162
+ content_data_a.remove_instance('server_1', '/home/file_1')
163
+ assert_equal("2\nA1,50,22222222222\nB1,60,44444444444\n3\nA1,50,server_1,/home/file_1,22222222222\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n",
164
+ content_data_merged.to_s)
165
+ content_data_b.remove_instance('server_1', '/home/file_2')
166
+ assert_equal("2\nA1,50,22222222222\nB1,60,44444444444\n2\nA1,50,server_1,/home/file_1,22222222222\nB1,60,server_1,/home/file_3,55555555555\n",
167
+ content_data_b.to_s)
168
+
169
+ assert_equal(true, content_data_merged == content_data_b)
170
+ end
171
+
172
+ def test_remove
173
+ content_data_a = ContentData::ContentData.new
174
+ content_data_a.add_instance("A1", 50, "server_1",
175
+ "/home/file_1", 22222222222)
176
+
177
+ content_data_b = ContentData::ContentData.new
178
+ content_data_b.add_instance("A1", 50, "server_1",
179
+ "/home/file_1", 22222222222)
180
+ content_data_b.add_instance("A1", 50, "server_1",
181
+ "extra_inst", 66666666666)
182
+ content_data_b.add_instance("B1", 60, "server_1",
183
+ "/home/file_2", 44444444444)
184
+ content_data_b.add_instance("B1", 60, "server_1",
185
+ "/home/file_3", 55555555555)
186
+ content_data_removed = ContentData.remove(content_data_a, content_data_b)
187
+ assert_equal(content_data_removed.to_s, "1\nB1,60,44444444444\n2\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n")
188
+ content_data_a.remove_instance('server_1', '/home/file_1')
189
+ assert_equal(content_data_removed.to_s, "1\nB1,60,44444444444\n2\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n")
190
+ content_data_b.remove_instance('server_1', '/home/file_2')
191
+ assert_equal(content_data_removed.to_s, "1\nB1,60,44444444444\n2\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n")
192
+
193
+ #check nil
194
+ content_data_removed = ContentData.remove(nil, content_data_b)
195
+ assert_equal(content_data_removed.to_s, content_data_b.to_s)
196
+ content_data_removed = ContentData.remove(content_data_b, nil)
197
+ assert_equal(content_data_removed, nil)
198
+ end
199
+
200
+ def test_remove_instances
201
+ content_data_a = ContentData::ContentData.new
202
+ content_data_a.add_instance("A1", 50, "server_1",
203
+ "/home/file_1", 22222222222)
204
+
205
+ content_data_b = ContentData::ContentData.new
206
+ content_data_b.add_instance("A1", 50, "server_1",
207
+ "/home/file_1", 22222222222)
208
+ content_data_b.add_instance("A1", 50, "server_1",
209
+ "extra_inst", 66666666666)
210
+ content_data_b.add_instance("B1", 60, "server_1",
211
+ "/home/file_2", 44444444444)
212
+ content_data_b.add_instance("B1", 60, "server_1",
213
+ "/home/file_3", 55555555555)
214
+ content_data_removed = ContentData.remove_instances(content_data_a, content_data_b)
215
+ assert_equal(content_data_removed.to_s,"2\nA1,50,22222222222\nB1,60,44444444444\n3\nA1,50,server_1,extra_inst,66666666666\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n")
216
+ content_data_a.remove_instance('server_1', '/home/file_1')
217
+ assert_equal(content_data_removed.to_s,"2\nA1,50,22222222222\nB1,60,44444444444\n3\nA1,50,server_1,extra_inst,66666666666\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n")
218
+ content_data_b.remove_instance('server_1', '/home/file_2')
219
+ assert_equal(content_data_removed.to_s,"2\nA1,50,22222222222\nB1,60,44444444444\n3\nA1,50,server_1,extra_inst,66666666666\nB1,60,server_1,/home/file_2,44444444444\nB1,60,server_1,/home/file_3,55555555555\n")
220
+
221
+ #assert_equal(content_data_b, nil)
222
+
223
+ #check nil
224
+ content_data_removed = ContentData.remove_instances(nil, content_data_b)
225
+ assert_equal(content_data_removed.to_s, content_data_b.to_s)
226
+ content_data_removed = ContentData.remove_instances(content_data_b, nil)
227
+ assert_equal(content_data_removed, nil)
228
+ end
229
+
230
+ def test_remove_directory
231
+
232
+ content_data_b = ContentData::ContentData.new
233
+ content_data_b.add_instance("A1", 50, "server_1",
234
+ "/home/file_1", 22222222222)
235
+ content_data_b.add_instance("A1", 50, "server_1",
236
+ "extra_inst", 66666666666)
237
+ content_data_b.add_instance("B1", 60, "server_1",
238
+ "/home/file_2", 44444444444)
239
+ content_data_b.add_instance("B1", 60, "server_1",
240
+ "/home/file_3", 55555555555)
241
+ content_data_removed = ContentData.remove_directory(content_data_b, 'home', "server_1")
242
+ assert_equal("1\nA1,50,22222222222\n1\nA1,50,server_1,extra_inst,66666666666\n",
243
+ content_data_removed.to_s)
244
+
245
+ content_data_b.remove_instance('server_1', '/home/file_2')
246
+ assert_equal("1\nA1,50,22222222222\n1\nA1,50,server_1,extra_inst,66666666666\n",
247
+ content_data_removed.to_s)
248
+
249
+ assert_equal("2\nA1,50,22222222222\nB1,60,44444444444\n3\nA1,50,server_1,/home/file_1,22222222222\nA1,50,server_1,extra_inst,66666666666\nB1,60,server_1,/home/file_3,55555555555\n",
250
+ content_data_b.to_s)
251
+
252
+ content_data_b = ContentData::ContentData.new
253
+ content_data_removed = ContentData.remove_directory(content_data_b, 'home', "server_1")
254
+ assert_equal(0, content_data_removed.contents_size)
255
+ content_data_removed = ContentData.remove_directory(nil, 'home', "server_1")
256
+ assert_equal(content_data_removed, nil)
257
+ end
258
+
259
+ def test_intersect
260
+ content_data_a = ContentData::ContentData.new
261
+ content_data_a.add_instance("A1", 50, "server_1",
262
+ "/home/file_1", 22222222222)
263
+ content_data_a.add_instance("C1", 70, "server_1",
264
+ "/home/file_4", 77777777777)
265
+ content_data_b = ContentData::ContentData.new
266
+ content_data_b.add_instance("A1", 50, "server_1",
267
+ "/home/file_1", 22222222222)
268
+ content_data_b.add_instance("A1", 50, "server_1",
269
+ "/home/file_5", 55555555555)
270
+ content_data_b.add_instance("B1", 60, "server_1",
271
+ "/home/file_2", 44444444444)
272
+
273
+ content_data_intersect = ContentData.intersect(content_data_a, content_data_b)
274
+ assert_equal(content_data_intersect.to_s, "1\nA1,50,22222222222\n2\nA1,50,server_1,/home/file_1,22222222222\nA1,50,server_1,/home/file_5,55555555555\n")
275
+ end
276
+
277
+ def test_unify_time
278
+ content_data_a = ContentData::ContentData.new
279
+ content_data_a.add_instance("A1", 50, "server_1",
280
+ "/home/file_1", 22222222222)
281
+ content_data_a.add_instance("C1", 70, "server_1",
282
+ "/home/file_4", 77777777777)
283
+ content_data_a.add_instance("C1", 70, "server_1",
284
+ "/home/file_5", 33333333333)
285
+ content_data_a.unify_time
286
+ assert_equal(content_data_a.to_s, "2\nA1,50,22222222222\nC1,70,33333333333\n3\nA1,50,server_1,/home/file_1,22222222222\nC1,70,server_1,/home/file_4,33333333333\nC1,70,server_1,/home/file_5,33333333333\n")
287
+ end
288
+ end
289
+
290
+
@@ -0,0 +1,84 @@
1
+ # Author: Slava Pasechnik (slavapas13@gmail.com)
2
+ # Run from bbfs> ruby -Ilib test/file_generator/file_generator_spec.rb
3
+
4
+ require 'file_utils/file_generator/file_generator'
5
+ require 'rspec'
6
+
7
+ module FileGenerator
8
+ module Spec
9
+ describe 'FileGenerator::run' do
10
+ before(:each) do
11
+ Params['total_created_directories'] = 1
12
+ Params['total_files_in_dir'] = 1
13
+ Params['is_tot_files_in_dir_random'] = false
14
+ Params['is_use_random_size'] = false
15
+ Params['sleep_time_in_seconds'] = 0
16
+ Params['dir_name_prefix'] = "td4bs"
17
+ Params['file_name_prefix'] = "agf4bs_"
18
+ end
19
+
20
+ it 'should reach File.open 1 files' do
21
+ file = mock('file')
22
+ file_utils_mkdir_p = double('FileUtils.mkdir_p')
23
+ file_open = double('File.open')
24
+
25
+ FileUtils.stub(:mkdir_p).and_return(file_utils_mkdir_p)
26
+ File.stub(:open).and_return(file_open)
27
+ File.should_receive(:open).exactly(1).times
28
+
29
+ fg = FileGenerator.new()
30
+ fg.run()
31
+ end
32
+
33
+ it 'should reach File.open 3 files' do
34
+ file = mock('file')
35
+ file_utils_mkdir_p = double('FileUtils.mkdir_p')
36
+ file_open = double('File.open')
37
+
38
+ FileUtils.stub(:mkdir_p).and_return(file_utils_mkdir_p)
39
+ File.stub(:open).and_return(file_open)
40
+ File.should_receive(:open).exactly(3).times
41
+
42
+ Params['total_files_in_dir'] = 3
43
+ fg = FileGenerator.new()
44
+ fg.run()
45
+ end
46
+
47
+ it 'should reach File.open with prefixed dir and file names' do
48
+ file = mock('file')
49
+ file_utils_mkdir_p = double('FileUtils.mkdir_p')
50
+ file_open = double('File.open')
51
+
52
+ FileUtils.stub(:mkdir_p).and_return(file_utils_mkdir_p)
53
+ File.stub(:open).and_return(file_open)
54
+ File.should_receive(:open).with(/td4bs.*agf4bs_/, "w")
55
+
56
+ fg = FileGenerator.new()
57
+ fg.run()
58
+ end
59
+
60
+ it 'should reach File.open 3 files' do
61
+ file = mock('file')
62
+ file_utils_mkdir_p = double('FileUtils.mkdir_p')
63
+ file_open = double('File.open')
64
+
65
+ FileUtils.stub(:mkdir_p).and_return(file_utils_mkdir_p)
66
+ File.stub(:open).and_return(file_open)
67
+ File.should_receive(:open).exactly(3).times
68
+
69
+ Params['total_files_in_dir'] = 3
70
+ fg = FileGenerator.new()
71
+ fg.run()
72
+ end
73
+
74
+ it 'should create filename and put text in it' do
75
+ file = mock('file')
76
+ File.should_receive(:open).with(any_args(), "w").exactly(2).times.and_yield(file)
77
+ file.should_receive(:write).exactly(2).times
78
+ Params['total_files_in_dir'] = 2
79
+ fg = FileGenerator.new()
80
+ fg.run()
81
+ end
82
+ end
83
+ end
84
+ end
File without changes
@@ -0,0 +1,102 @@
1
+
2
+ #ifndef __EXSLT_H__
3
+ #define __EXSLT_H__
4
+
5
+ #include <libxml/tree.h>
6
+ #include <libxml/xpath.h>
7
+ #include "exsltexports.h"
8
+ #include <libexslt/exsltconfig.h>
9
+
10
+ #ifdef __cplusplus
11
+ extern "C" {
12
+ #endif
13
+
14
+ EXSLTPUBVAR const char *exsltLibraryVersion;
15
+ EXSLTPUBVAR const int exsltLibexsltVersion;
16
+ EXSLTPUBVAR const int exsltLibxsltVersion;
17
+ EXSLTPUBVAR const int exsltLibxmlVersion;
18
+
19
+ /**
20
+ * EXSLT_COMMON_NAMESPACE:
21
+ *
22
+ * Namespace for EXSLT common functions
23
+ */
24
+ #define EXSLT_COMMON_NAMESPACE ((const xmlChar *) "http://exslt.org/common")
25
+ /**
26
+ * EXSLT_CRYPTO_NAMESPACE:
27
+ *
28
+ * Namespace for EXSLT crypto functions
29
+ */
30
+ #define EXSLT_CRYPTO_NAMESPACE ((const xmlChar *) "http://exslt.org/crypto")
31
+ /**
32
+ * EXSLT_MATH_NAMESPACE:
33
+ *
34
+ * Namespace for EXSLT math functions
35
+ */
36
+ #define EXSLT_MATH_NAMESPACE ((const xmlChar *) "http://exslt.org/math")
37
+ /**
38
+ * EXSLT_SETS_NAMESPACE:
39
+ *
40
+ * Namespace for EXSLT set functions
41
+ */
42
+ #define EXSLT_SETS_NAMESPACE ((const xmlChar *) "http://exslt.org/sets")
43
+ /**
44
+ * EXSLT_FUNCTIONS_NAMESPACE:
45
+ *
46
+ * Namespace for EXSLT functions extension functions
47
+ */
48
+ #define EXSLT_FUNCTIONS_NAMESPACE ((const xmlChar *) "http://exslt.org/functions")
49
+ /**
50
+ * EXSLT_STRINGS_NAMESPACE:
51
+ *
52
+ * Namespace for EXSLT strings functions
53
+ */
54
+ #define EXSLT_STRINGS_NAMESPACE ((const xmlChar *) "http://exslt.org/strings")
55
+ /**
56
+ * EXSLT_DATE_NAMESPACE:
57
+ *
58
+ * Namespace for EXSLT date functions
59
+ */
60
+ #define EXSLT_DATE_NAMESPACE ((const xmlChar *) "http://exslt.org/dates-and-times")
61
+ /**
62
+ * EXSLT_DYNAMIC_NAMESPACE:
63
+ *
64
+ * Namespace for EXSLT dynamic functions
65
+ */
66
+ #define EXSLT_DYNAMIC_NAMESPACE ((const xmlChar *) "http://exslt.org/dynamic")
67
+
68
+ /**
69
+ * SAXON_NAMESPACE:
70
+ *
71
+ * Namespace for SAXON extensions functions
72
+ */
73
+ #define SAXON_NAMESPACE ((const xmlChar *) "http://icl.com/saxon")
74
+
75
+ EXSLTPUBFUN void EXSLTCALL exsltCommonRegister (void);
76
+ #ifdef EXSLT_CRYPTO_ENABLED
77
+ EXSLTPUBFUN void EXSLTCALL exsltCryptoRegister (void);
78
+ #endif
79
+ EXSLTPUBFUN void EXSLTCALL exsltMathRegister (void);
80
+ EXSLTPUBFUN void EXSLTCALL exsltSetsRegister (void);
81
+ EXSLTPUBFUN void EXSLTCALL exsltFuncRegister (void);
82
+ EXSLTPUBFUN void EXSLTCALL exsltStrRegister (void);
83
+ EXSLTPUBFUN void EXSLTCALL exsltDateRegister (void);
84
+ EXSLTPUBFUN void EXSLTCALL exsltSaxonRegister (void);
85
+ EXSLTPUBFUN void EXSLTCALL exsltDynRegister(void);
86
+
87
+ EXSLTPUBFUN void EXSLTCALL exsltRegisterAll (void);
88
+
89
+ EXSLTPUBFUN int EXSLTCALL exsltDateXpathCtxtRegister (xmlXPathContextPtr ctxt,
90
+ const xmlChar *prefix);
91
+ EXSLTPUBFUN int EXSLTCALL exsltMathXpathCtxtRegister (xmlXPathContextPtr ctxt,
92
+ const xmlChar *prefix);
93
+ EXSLTPUBFUN int EXSLTCALL exsltSetsXpathCtxtRegister (xmlXPathContextPtr ctxt,
94
+ const xmlChar *prefix);
95
+ EXSLTPUBFUN int EXSLTCALL exsltStrXpathCtxtRegister (xmlXPathContextPtr ctxt,
96
+ const xmlChar *prefix);
97
+
98
+ #ifdef __cplusplus
99
+ }
100
+ #endif
101
+ #endif /* __EXSLT_H__ */
102
+
@@ -0,0 +1,73 @@
1
+ /*
2
+ * exsltconfig.h: compile-time version informations for the EXSLT library
3
+ *
4
+ * See Copyright for the status of this software.
5
+ *
6
+ * daniel@veillard.com
7
+ */
8
+
9
+ #ifndef __XML_EXSLTCONFIG_H__
10
+ #define __XML_EXSLTCONFIG_H__
11
+
12
+ #ifdef __cplusplus
13
+ extern "C" {
14
+ #endif
15
+
16
+ /**
17
+ * LIBEXSLT_DOTTED_VERSION:
18
+ *
19
+ * the version string like "1.2.3"
20
+ */
21
+ #define LIBEXSLT_DOTTED_VERSION "0.8.15"
22
+
23
+ /**
24
+ * LIBEXSLT_VERSION:
25
+ *
26
+ * the version number: 1.2.3 value is 10203
27
+ */
28
+ #define LIBEXSLT_VERSION 815
29
+
30
+ /**
31
+ * LIBEXSLT_VERSION_STRING:
32
+ *
33
+ * the version number string, 1.2.3 value is "10203"
34
+ */
35
+ #define LIBEXSLT_VERSION_STRING "815"
36
+
37
+ /**
38
+ * LIBEXSLT_VERSION_EXTRA:
39
+ *
40
+ * extra version information, used to show a CVS compilation
41
+ */
42
+ #define LIBEXSLT_VERSION_EXTRA ""
43
+
44
+ /**
45
+ * WITH_CRYPTO:
46
+ *
47
+ * Whether crypto support is configured into exslt
48
+ */
49
+ #if 1
50
+ #define EXSLT_CRYPTO_ENABLED
51
+ #endif
52
+
53
+ /**
54
+ * ATTRIBUTE_UNUSED:
55
+ *
56
+ * This macro is used to flag unused function parameters to GCC
57
+ */
58
+ #ifdef __GNUC__
59
+ #ifdef HAVE_ANSIDECL_H
60
+ #include <ansidecl.h>
61
+ #endif
62
+ #ifndef ATTRIBUTE_UNUSED
63
+ #define ATTRIBUTE_UNUSED __attribute__((unused))
64
+ #endif
65
+ #else
66
+ #define ATTRIBUTE_UNUSED
67
+ #endif
68
+
69
+ #ifdef __cplusplus
70
+ }
71
+ #endif
72
+
73
+ #endif /* __XML_EXSLTCONFIG_H__ */