PageRenderTime 27ms CodeModel.GetById 1ms RepoModel.GetById 0ms app.codeStats 0ms

/hbase-shell/src/test/ruby/hbase/replication_admin_test.rb

http://github.com/apache/hbase
Ruby | 810 lines | 673 code | 79 blank | 58 comment | 0 complexity | 341dd2e2ac6f8db001733a5b427cdf53 MD5 | raw file
Possible License(s): Apache-2.0, MIT
  1. #
  2. #
  3. # Licensed to the Apache Software Foundation (ASF) under one
  4. # or more contributor license agreements. See the NOTICE file
  5. # distributed with this work for additional information
  6. # regarding copyright ownership. The ASF licenses this file
  7. # to you under the Apache License, Version 2.0 (the
  8. # "License"); you may not use this file except in compliance
  9. # with the License. You may obtain a copy of the License at
  10. #
  11. # http://www.apache.org/licenses/LICENSE-2.0
  12. #
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #
  19. require 'hbase_shell'
  20. require 'hbase_constants'
  21. require 'hbase/hbase'
  22. require 'hbase/table'
  23. include Java
  24. java_import org.apache.hadoop.hbase.replication.SyncReplicationState
  25. module Hbase
  26. class ReplicationAdminTest < Test::Unit::TestCase
  27. include TestHelpers
  28. include HBaseConstants
  29. def setup
  30. @peer_id = '1'
  31. @dummy_endpoint = 'org.apache.hadoop.hbase.replication.DummyReplicationEndpoint'
  32. setup_hbase
  33. assert_equal(0, command(:list_peers).length)
  34. end
  35. def teardown
  36. assert_equal(0, command(:list_peers).length)
  37. shutdown
  38. end
  39. define_test "add_peer: should fail when args isn't specified" do
  40. assert_raise(ArgumentError) do
  41. command(:add_peer, @peer_id, nil)
  42. end
  43. end
  44. define_test "add_peer: fail when neither CLUSTER_KEY nor ENDPOINT_CLASSNAME are specified" do
  45. assert_raise(ArgumentError) do
  46. args = {}
  47. command(:add_peer, @peer_id, args)
  48. end
  49. end
  50. define_test "add_peer: args must be a hash" do
  51. assert_raise(ArgumentError) do
  52. command(:add_peer, @peer_id, 1)
  53. end
  54. assert_raise(ArgumentError) do
  55. command(:add_peer, @peer_id, ['test'])
  56. end
  57. assert_raise(ArgumentError) do
  58. command(:add_peer, @peer_id, 'test')
  59. end
  60. end
  61. define_test "add_peer: single zk cluster key" do
  62. cluster_key = "server1.cie.com:2181:/hbase"
  63. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  64. command(:add_peer, @peer_id, args)
  65. assert_equal(1, command(:list_peers).length)
  66. peer = command(:list_peers).get(0)
  67. assert_equal(@peer_id, peer.getPeerId)
  68. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  69. assert_equal(true, peer.getPeerConfig.replicateAllUserTables)
  70. # cleanup for future tests
  71. command(:remove_peer, @peer_id)
  72. end
  73. define_test "add_peer: multiple zk cluster key" do
  74. cluster_key = "zk1,zk2,zk3:2182:/hbase-prod"
  75. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  76. command(:add_peer, @peer_id, args)
  77. assert_equal(1, command(:list_peers).length)
  78. peer = command(:list_peers).get(0)
  79. assert_equal(@peer_id, peer.getPeerId)
  80. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  81. assert_equal(true, peer.getPeerConfig.replicateAllUserTables)
  82. # cleanup for future tests
  83. command(:remove_peer, @peer_id)
  84. end
  85. define_test "add_peer: serial" do
  86. cluster_key = "server1.cie.com:2181:/hbase"
  87. remote_wal_dir = "hdfs://srv1:9999/hbase"
  88. table_cfs = { "ns3:table1" => [], "ns3:table2" => [],
  89. "ns3:table3" => [] }
  90. # add a new replication peer which serial flag is true
  91. args = {CLUSTER_KEY => cluster_key, SERIAL => true,
  92. TABLE_CFS => table_cfs, ENDPOINT_CLASSNAME => @dummy_endpoint}
  93. command(:add_peer, @peer_id, args)
  94. assert_equal(1, command(:list_peers).length)
  95. peer = command(:list_peers).get(0)
  96. assert_equal(@peer_id, peer.getPeerId)
  97. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  98. assert_equal(true, peer.getPeerConfig.isSerial)
  99. assert_tablecfs_equal(table_cfs, peer.getPeerConfig.getTableCFsMap())
  100. # cleanup for future tests
  101. command(:remove_peer, @peer_id)
  102. end
  103. define_test "add_peer: remote wal dir" do
  104. cluster_key = "server1.cie.com:2181:/hbase"
  105. remote_wal_dir = "hdfs://srv1:9999/hbase"
  106. table_cfs = { "ns3:table1" => [], "ns3:table2" => [],
  107. "ns3:table3" => [] }
  108. args = {CLUSTER_KEY => cluster_key, REMOTE_WAL_DIR => remote_wal_dir,
  109. TABLE_CFS => table_cfs, ENDPOINT_CLASSNAME => @dummy_endpoint}
  110. command(:add_peer, @peer_id, args)
  111. assert_equal(1, command(:list_peers).length)
  112. peer = command(:list_peers).get(0)
  113. assert_equal(@peer_id, peer.getPeerId)
  114. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  115. assert_equal(remote_wal_dir, peer.getPeerConfig.getRemoteWALDir)
  116. assert_tablecfs_equal(table_cfs, peer.getPeerConfig.getTableCFsMap())
  117. # cleanup for future tests
  118. command(:remove_peer, @peer_id)
  119. end
  120. define_test "add_peer: single zk cluster key with enabled/disabled state" do
  121. cluster_key = "server1.cie.com:2181:/hbase"
  122. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  123. command(:add_peer, @peer_id, args)
  124. assert_equal(1, command(:list_peers).length)
  125. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  126. assert_equal(true, command(:list_peers).get(0).isEnabled)
  127. command(:remove_peer, @peer_id)
  128. enable_args = {CLUSTER_KEY => cluster_key, STATE => 'ENABLED',
  129. ENDPOINT_CLASSNAME => @dummy_endpoint}
  130. command(:add_peer, @peer_id, enable_args)
  131. assert_equal(1, command(:list_peers).length)
  132. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  133. assert_equal(true, command(:list_peers).get(0).isEnabled)
  134. command(:remove_peer, @peer_id)
  135. disable_args = {CLUSTER_KEY => cluster_key, STATE => 'DISABLED',
  136. ENDPOINT_CLASSNAME => @dummy_endpoint}
  137. command(:add_peer, @peer_id, disable_args)
  138. assert_equal(1, command(:list_peers).length)
  139. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  140. assert_equal(false, command(:list_peers).get(0).isEnabled)
  141. command(:remove_peer, @peer_id)
  142. end
  143. define_test "add_peer: multiple zk cluster key - peer config" do
  144. cluster_key = "zk1,zk2,zk3:2182:/hbase-prod"
  145. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  146. command(:add_peer, @peer_id, args)
  147. assert_equal(1, command(:list_peers).length)
  148. peer = command(:list_peers).get(0)
  149. assert_equal(@peer_id, peer.getPeerId)
  150. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  151. assert_equal(true, peer.getPeerConfig.replicateAllUserTables)
  152. # cleanup for future tests
  153. command(:remove_peer, @peer_id)
  154. end
  155. define_test "add_peer: multiple zk cluster key and namespaces" do
  156. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  157. namespaces = ["ns1", "ns2", "ns3"]
  158. namespaces_str = "ns1;ns2;ns3"
  159. args = {CLUSTER_KEY => cluster_key, NAMESPACES => namespaces,
  160. ENDPOINT_CLASSNAME => @dummy_endpoint}
  161. command(:add_peer, @peer_id, args)
  162. assert_equal(1, command(:list_peers).length)
  163. peer = command(:list_peers).get(0)
  164. assert_equal(@peer_id, peer.getPeerId)
  165. peer_config = peer.getPeerConfig
  166. assert_equal(false, peer_config.replicateAllUserTables)
  167. assert_equal(cluster_key, peer_config.get_cluster_key)
  168. assert_equal(namespaces_str,
  169. replication_admin.show_peer_namespaces(peer_config))
  170. # cleanup for future tests
  171. command(:remove_peer, @peer_id)
  172. end
  173. define_test "add_peer: multiple zk cluster key and namespaces, table_cfs" do
  174. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  175. namespaces = ["ns1", "ns2"]
  176. table_cfs = { "ns3:table1" => [], "ns3:table2" => ["cf1"],
  177. "ns3:table3" => ["cf1", "cf2"] }
  178. namespaces_str = "ns1;ns2"
  179. args = {CLUSTER_KEY => cluster_key, NAMESPACES => namespaces,
  180. TABLE_CFS => table_cfs, ENDPOINT_CLASSNAME => @dummy_endpoint}
  181. command(:add_peer, @peer_id, args)
  182. assert_equal(1, command(:list_peers).length)
  183. peer = command(:list_peers).get(0)
  184. assert_equal(@peer_id, peer.getPeerId)
  185. peer_config = peer.getPeerConfig
  186. assert_equal(false, peer_config.replicateAllUserTables)
  187. assert_equal(cluster_key, peer_config.get_cluster_key)
  188. assert_equal(namespaces_str,
  189. replication_admin.show_peer_namespaces(peer_config))
  190. assert_tablecfs_equal(table_cfs, peer_config.getTableCFsMap())
  191. # cleanup for future tests
  192. command(:remove_peer, @peer_id)
  193. end
  194. def assert_tablecfs_equal(table_cfs, table_cfs_map)
  195. assert_equal(table_cfs.length, table_cfs_map.length)
  196. table_cfs_map.each{|key, value|
  197. assert(table_cfs.has_key?(key.getNameAsString))
  198. if table_cfs.fetch(key.getNameAsString).length == 0
  199. assert_equal(nil, value)
  200. else
  201. assert_equal(table_cfs.fetch(key.getNameAsString).length, value.length)
  202. value.each{|v|
  203. assert(table_cfs.fetch(key.getNameAsString).include?(v))
  204. }
  205. end
  206. }
  207. end
  208. define_test "add_peer: multiple zk cluster key and table_cfs - peer config" do
  209. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  210. table_cfs = { "table1" => [], "table2" => ["cf1"], "table3" => ["cf1", "cf2"] }
  211. args = {CLUSTER_KEY => cluster_key, TABLE_CFS => table_cfs,
  212. ENDPOINT_CLASSNAME => @dummy_endpoint}
  213. command(:add_peer, @peer_id, args)
  214. assert_equal(1, command(:list_peers).length)
  215. peer = command(:list_peers).get(0)
  216. assert_equal(@peer_id, peer.getPeerId)
  217. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  218. assert_tablecfs_equal(table_cfs, peer.getPeerConfig.getTableCFsMap)
  219. assert_equal(false, peer.getPeerConfig.replicateAllUserTables)
  220. # cleanup for future tests
  221. command(:remove_peer, @peer_id)
  222. end
  223. define_test "add_peer: should fail when args is a hash and peer_tableCFs provided" do
  224. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  225. table_cfs_str = "table1;table2:cf1;table3:cf1,cf2"
  226. assert_raise(ArgumentError) do
  227. args = { CLUSTER_KEY => cluster_key }
  228. command(:add_peer, @peer_id, args, table_cfs_str)
  229. end
  230. end
  231. define_test "set_peer_tableCFs: works with table-cfs map" do
  232. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  233. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  234. command(:add_peer, @peer_id, args)
  235. command(:set_peer_replicate_all, @peer_id, false)
  236. assert_equal(1, command(:list_peers).length)
  237. peer = command(:list_peers).get(0)
  238. assert_equal(@peer_id, peer.getPeerId)
  239. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  240. table_cfs = { "table1" => [], "table2" => ["cf1"], "ns3:table3" => ["cf1", "cf2"] }
  241. command(:set_peer_tableCFs, @peer_id, table_cfs)
  242. assert_tablecfs_equal(table_cfs, command(:get_peer_config, @peer_id).getTableCFsMap())
  243. # cleanup for future tests
  244. command(:remove_peer, @peer_id)
  245. end
  246. define_test "append_peer_tableCFs: works with table-cfs map" do
  247. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  248. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  249. command(:add_peer, @peer_id, args)
  250. command(:set_peer_replicate_all, @peer_id, false)
  251. assert_equal(1, command(:list_peers).length)
  252. peer = command(:list_peers).get(0)
  253. assert_equal(@peer_id, peer.getPeerId)
  254. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  255. table_cfs = { "table1" => [], "ns2:table2" => ["cf1"] }
  256. command(:append_peer_tableCFs, @peer_id, table_cfs)
  257. assert_tablecfs_equal(table_cfs, command(:get_peer_config, @peer_id).getTableCFsMap())
  258. table_cfs = { "table1" => [], "ns2:table2" => ["cf1"], "ns3:table3" => ["cf1", "cf2"] }
  259. command(:append_peer_tableCFs, @peer_id, { "ns3:table3" => ["cf1", "cf2"] })
  260. assert_tablecfs_equal(table_cfs, command(:get_peer_config, @peer_id).getTableCFsMap())
  261. # cleanup for future tests
  262. command(:remove_peer, @peer_id)
  263. end
  264. define_test "remove_peer_tableCFs: works with table-cfs map" do
  265. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  266. table_cfs = { "table1" => [], "ns2:table2" => ["cf1"], "ns3:table3" => ["cf1", "cf2"] }
  267. args = {CLUSTER_KEY => cluster_key, TABLE_CFS => table_cfs,
  268. ENDPOINT_CLASSNAME => @dummy_endpoint}
  269. command(:add_peer, @peer_id, args)
  270. assert_equal(1, command(:list_peers).length)
  271. peer = command(:list_peers).get(0)
  272. assert_equal(@peer_id, peer.getPeerId)
  273. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  274. table_cfs = { "table1" => [], "ns2:table2" => ["cf1"] }
  275. command(:remove_peer_tableCFs, @peer_id, { "ns3:table3" => ["cf1", "cf2"] })
  276. assert_tablecfs_equal(table_cfs, command(:get_peer_config, @peer_id).getTableCFsMap())
  277. # cleanup for future tests
  278. command(:remove_peer, @peer_id)
  279. end
  280. define_test 'set_peer_exclude_tableCFs: works with table-cfs map' do
  281. cluster_key = 'zk4,zk5,zk6:11000:/hbase-test'
  282. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  283. command(:add_peer, @peer_id, args)
  284. assert_equal(1, command(:list_peers).length)
  285. peer = command(:list_peers).get(0)
  286. assert_equal(@peer_id, peer.getPeerId)
  287. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  288. table_cfs = { 'table1' => [], 'table2' => ['cf1'],
  289. 'ns3:table3' => ['cf1', 'cf2'] }
  290. command(:set_peer_exclude_tableCFs, @peer_id, table_cfs)
  291. assert_equal(1, command(:list_peers).length)
  292. peer = command(:list_peers).get(0)
  293. peer_config = peer.getPeerConfig
  294. assert_equal(true, peer_config.replicateAllUserTables)
  295. assert_tablecfs_equal(table_cfs, peer_config.getExcludeTableCFsMap)
  296. # cleanup for future tests
  297. replication_admin.remove_peer(@peer_id)
  298. end
  299. define_test "append_peer_exclude_tableCFs: works with exclude table-cfs map" do
  300. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  301. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  302. command(:add_peer, @peer_id, args)
  303. assert_equal(1, command(:list_peers).length)
  304. peer = command(:list_peers).get(0)
  305. assert_equal(@peer_id, peer.getPeerId)
  306. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  307. # set exclude-table-cfs
  308. exclude_table_cfs = {"table1" => [], "ns2:table2" => ["cf1", "cf2"]}
  309. command(:set_peer_exclude_tableCFs, @peer_id, exclude_table_cfs)
  310. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  311. # append empty exclude-table-cfs
  312. append_table_cfs = {}
  313. command(:append_peer_exclude_tableCFs, @peer_id, append_table_cfs)
  314. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  315. # append exclude-table-cfs which don't exist in peer' exclude-table-cfs
  316. append_table_cfs = {"table3" => ["cf3"]}
  317. exclude_table_cfs = {"table1" => [], "ns2:table2" => ["cf1", "cf2"], "table3" => ["cf3"]}
  318. command(:append_peer_exclude_tableCFs, @peer_id, append_table_cfs)
  319. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  320. # append exclude-table-cfs which exist in peer' exclude-table-cfs
  321. append_table_cfs = {"table1" => ["cf1"], "ns2:table2" => ["cf1", "cf3"], "table3" => []}
  322. exclude_table_cfs = {"table1" => [], "ns2:table2" => ["cf1", "cf2", "cf3"], "table3" => []}
  323. command(:append_peer_exclude_tableCFs, @peer_id, append_table_cfs)
  324. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  325. # cleanup for future tests
  326. command(:remove_peer, @peer_id)
  327. end
  328. define_test 'remove_peer_exclude_tableCFs: works with exclude table-cfs map' do
  329. cluster_key = 'zk4,zk5,zk6:11000:/hbase-test'
  330. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  331. command(:add_peer, @peer_id, args)
  332. assert_equal(1, command(:list_peers).length)
  333. peer = command(:list_peers).get(0)
  334. assert_equal(@peer_id, peer.getPeerId)
  335. assert_equal(cluster_key, peer.getPeerConfig.getClusterKey)
  336. # set exclude-table-cfs
  337. exclude_table_cfs = {'table1' => [], 'table2' => ['cf1'], 'ns3:table3' => ['cf1', 'cf2']}
  338. command(:set_peer_exclude_tableCFs, @peer_id, exclude_table_cfs)
  339. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  340. # remove empty exclude-table-cfs
  341. remove_table_cfs = {}
  342. command(:remove_peer_exclude_tableCFs, @peer_id, remove_table_cfs)
  343. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  344. # remove exclude-table-cfs which exist in pees' exclude table cfs
  345. remove_table_cfs = {'table1' => [], 'table2' => ['cf1']}
  346. exclude_table_cfs = {'ns3:table3' => ['cf1', 'cf2']}
  347. command(:remove_peer_exclude_tableCFs, @peer_id, remove_table_cfs)
  348. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  349. # remove exclude-table-cfs which exist in pees' exclude-table-cfs
  350. remove_table_cfs = {'ns3:table3' => ['cf2', 'cf3']}
  351. exclude_table_cfs = {'ns3:table3' => ['cf1']}
  352. command(:remove_peer_exclude_tableCFs, @peer_id, remove_table_cfs)
  353. assert_tablecfs_equal(exclude_table_cfs, command(:get_peer_config, @peer_id).getExcludeTableCFsMap())
  354. # cleanup for future tests
  355. replication_admin.remove_peer(@peer_id)
  356. end
  357. define_test "set_peer_namespaces: works with namespaces array" do
  358. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  359. namespaces = ["ns1", "ns2"]
  360. namespaces_str = "ns1;ns2"
  361. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  362. command(:add_peer, @peer_id, args)
  363. command(:set_peer_replicate_all, @peer_id, false)
  364. command(:set_peer_namespaces, @peer_id, namespaces)
  365. assert_equal(1, command(:list_peers).length)
  366. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  367. peer_config = command(:list_peers).get(0).getPeerConfig
  368. assert_equal(namespaces_str,
  369. replication_admin.show_peer_namespaces(peer_config))
  370. # cleanup for future tests
  371. command(:remove_peer, @peer_id)
  372. end
  373. define_test "append_peer_namespaces: works with namespaces array" do
  374. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  375. namespaces = ["ns1", "ns2"]
  376. namespaces_str = "ns1;ns2"
  377. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  378. command(:add_peer, @peer_id, args)
  379. command(:set_peer_replicate_all, @peer_id, false)
  380. command(:append_peer_namespaces, @peer_id, namespaces)
  381. assert_equal(1, command(:list_peers).length)
  382. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  383. peer_config = command(:list_peers).get(0).getPeerConfig
  384. assert_equal(namespaces_str,
  385. replication_admin.show_peer_namespaces(peer_config))
  386. namespaces = ["ns3"]
  387. namespaces_str = "ns1;ns2;ns3"
  388. command(:append_peer_namespaces, @peer_id, namespaces)
  389. assert_equal(1, command(:list_peers).length)
  390. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  391. peer_config = command(:list_peers).get(0).getPeerConfig
  392. assert_equal(namespaces_str,
  393. replication_admin.show_peer_namespaces(peer_config))
  394. # append a namespace which is already in the peer config
  395. command(:append_peer_namespaces, @peer_id, namespaces)
  396. assert_equal(1, command(:list_peers).length)
  397. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  398. peer_config = command(:list_peers).get(0).getPeerConfig
  399. assert_equal(namespaces_str,
  400. replication_admin.show_peer_namespaces(peer_config))
  401. # cleanup for future tests
  402. command(:remove_peer, @peer_id)
  403. end
  404. define_test "remove_peer_namespaces: works with namespaces array" do
  405. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  406. namespaces = ["ns1", "ns2", "ns3"]
  407. args = {CLUSTER_KEY => cluster_key, NAMESPACES => namespaces,
  408. ENDPOINT_CLASSNAME => @dummy_endpoint}
  409. command(:add_peer, @peer_id, args)
  410. namespaces = ["ns1", "ns2"]
  411. namespaces_str = "ns3"
  412. command(:remove_peer_namespaces, @peer_id, namespaces)
  413. assert_equal(1, command(:list_peers).length)
  414. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  415. peer_config = command(:list_peers).get(0).getPeerConfig
  416. assert_equal(namespaces_str,
  417. replication_admin.show_peer_namespaces(peer_config))
  418. namespaces = ["ns3"]
  419. namespaces_str = nil
  420. command(:remove_peer_namespaces, @peer_id, namespaces)
  421. assert_equal(1, command(:list_peers).length)
  422. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  423. peer_config = command(:list_peers).get(0).getPeerConfig
  424. assert_equal(namespaces_str,
  425. replication_admin.show_peer_namespaces(peer_config))
  426. # remove a namespace which is not in peer config
  427. command(:remove_peer_namespaces, @peer_id, namespaces)
  428. assert_equal(1, command(:list_peers).length)
  429. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  430. peer_config = command(:list_peers).get(0).getPeerConfig
  431. assert_equal(namespaces_str,
  432. replication_admin.show_peer_namespaces(peer_config))
  433. # cleanup for future tests
  434. command(:remove_peer, @peer_id)
  435. end
  436. define_test 'set_peer_exclude_namespaces: works with namespaces array' do
  437. cluster_key = 'zk4,zk5,zk6:11000:/hbase-test'
  438. namespaces = ['ns1', 'ns2']
  439. namespaces_str = '!ns1;ns2'
  440. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  441. command(:add_peer, @peer_id, args)
  442. command(:set_peer_exclude_namespaces, @peer_id, namespaces)
  443. assert_equal(1, command(:list_peers).length)
  444. peer_config = command(:list_peers).get(0).getPeerConfig
  445. assert_equal(true, peer_config.replicateAllUserTables)
  446. assert_equal(namespaces_str,
  447. replication_admin.show_peer_exclude_namespaces(peer_config))
  448. # cleanup for future tests
  449. command(:remove_peer, @peer_id)
  450. end
  451. define_test 'set_peer_replicate_all' do
  452. cluster_key = 'zk4,zk5,zk6:11000:/hbase-test'
  453. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  454. command(:add_peer, @peer_id, args)
  455. assert_equal(1, command(:list_peers).length)
  456. peer_config = command(:list_peers).get(0).getPeerConfig
  457. assert_equal(true, peer_config.replicateAllUserTables)
  458. command(:set_peer_replicate_all, @peer_id, false)
  459. peer_config = command(:list_peers).get(0).getPeerConfig
  460. assert_equal(false, peer_config.replicateAllUserTables)
  461. command(:set_peer_replicate_all, @peer_id, true)
  462. peer_config = command(:list_peers).get(0).getPeerConfig
  463. assert_equal(true, peer_config.replicateAllUserTables)
  464. # cleanup for future tests
  465. replication_admin.remove_peer(@peer_id)
  466. end
  467. define_test 'set_peer_serial' do
  468. cluster_key = 'zk4,zk5,zk6:11000:/hbase-test'
  469. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  470. command(:add_peer, @peer_id, args)
  471. assert_equal(1, command(:list_peers).length)
  472. peer_config = command(:list_peers).get(0).getPeerConfig
  473. # the default serial flag is false
  474. assert_equal(false, peer_config.isSerial)
  475. command(:set_peer_serial, @peer_id, true)
  476. peer_config = command(:list_peers).get(0).getPeerConfig
  477. assert_equal(true, peer_config.isSerial)
  478. command(:set_peer_serial, @peer_id, false)
  479. peer_config = command(:list_peers).get(0).getPeerConfig
  480. assert_equal(false, peer_config.isSerial)
  481. # cleanup for future tests
  482. replication_admin.remove_peer(@peer_id)
  483. assert_equal(0, command(:list_peers).length)
  484. end
  485. define_test "set_peer_bandwidth: works with peer bandwidth upper limit" do
  486. cluster_key = org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster::HOST + ":2181:/hbase-test"
  487. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  488. command(:add_peer, @peer_id, args)
  489. peer_config = command(:get_peer_config, @peer_id)
  490. assert_equal(0, peer_config.get_bandwidth)
  491. command(:set_peer_bandwidth, @peer_id, 2097152)
  492. peer_config = command(:get_peer_config, @peer_id)
  493. assert_equal(2097152, peer_config.get_bandwidth)
  494. #cleanup
  495. command(:remove_peer, @peer_id)
  496. end
  497. define_test "transit_peer_sync_replication_state: test" do
  498. cluster_key = "server1.cie.com:2181:/hbase"
  499. remote_wal_dir = "hdfs://srv1:9999/hbase"
  500. table_cfs = { "ns3:table1" => [], "ns3:table2" => [],
  501. "ns3:table3" => [] }
  502. args = {CLUSTER_KEY => cluster_key, REMOTE_WAL_DIR => remote_wal_dir,
  503. TABLE_CFS => table_cfs, ENDPOINT_CLASSNAME => @dummy_endpoint}
  504. command(:add_peer, @peer_id, args)
  505. assert_equal(1, command(:list_peers).length)
  506. peer = command(:list_peers).get(0)
  507. assert_equal(@peer_id, peer.getPeerId)
  508. assert_equal(SyncReplicationState::DOWNGRADE_ACTIVE, peer.getSyncReplicationState)
  509. command(:transit_peer_sync_replication_state, @peer_id, 'STANDBY')
  510. assert_equal(1, command(:list_peers).length)
  511. peer = command(:list_peers).get(0)
  512. assert_equal(@peer_id, peer.getPeerId)
  513. assert_equal(SyncReplicationState::STANDBY, peer.getSyncReplicationState)
  514. # need to transit back otherwise we can not remove the peer
  515. command(:transit_peer_sync_replication_state, @peer_id, 'DOWNGRADE_ACTIVE')
  516. assert_equal(1, command(:list_peers).length)
  517. peer = command(:list_peers).get(0)
  518. assert_equal(@peer_id, peer.getPeerId)
  519. assert_equal(SyncReplicationState::DOWNGRADE_ACTIVE, peer.getSyncReplicationState)
  520. # cleanup for future tests
  521. command(:remove_peer, @peer_id)
  522. end
  523. define_test "get_peer_config: works with simple clusterKey peer" do
  524. cluster_key = org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster::HOST + ":2181:/hbase-test"
  525. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  526. command(:add_peer, @peer_id, args)
  527. peer_config = command(:get_peer_config, @peer_id)
  528. assert_equal(cluster_key, peer_config.get_cluster_key)
  529. #cleanup
  530. command(:remove_peer, @peer_id)
  531. end
  532. define_test "get_peer_config: works with replicationendpointimpl peer and config params" do
  533. cluster_key = org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster::HOST + ":2181:/hbase-test"
  534. config_params = { "config1" => "value1", "config2" => "value2" }
  535. args = { CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint,
  536. CONFIG => config_params }
  537. command(:add_peer, @peer_id, args)
  538. peer_config = command(:get_peer_config, @peer_id)
  539. assert_equal(cluster_key, peer_config.get_cluster_key)
  540. assert_equal(@dummy_endpoint, peer_config.get_replication_endpoint_impl)
  541. assert_equal(2, peer_config.get_configuration.size)
  542. assert_equal("value1", peer_config.get_configuration.get("config1"))
  543. #cleanup
  544. command(:remove_peer, @peer_id)
  545. end
  546. define_test "list_peer_configs: returns all peers' ReplicationPeerConfig objects" do
  547. cluster_key = org.apache.hadoop.hbase.zookeeper.MiniZooKeeperCluster::HOST + ":2181:/hbase-test"
  548. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  549. peer_id_second = '2'
  550. command(:add_peer, @peer_id, args)
  551. config_params = { "config1" => "value1", "config2" => "value2" }
  552. args2 = {ENDPOINT_CLASSNAME => @dummy_endpoint, CONFIG => config_params}
  553. command(:add_peer, peer_id_second, args2)
  554. peer_configs = command(:list_peer_configs)
  555. assert_equal(2, peer_configs.size)
  556. assert_equal(cluster_key, peer_configs.get(@peer_id).get_cluster_key)
  557. assert_equal(@dummy_endpoint, peer_configs.get(peer_id_second).get_replication_endpoint_impl)
  558. #cleanup
  559. command(:remove_peer, @peer_id)
  560. command(:remove_peer, peer_id_second)
  561. end
  562. define_test "update_peer_config: can update peer config and data" do
  563. config_params = { "config1" => "value1", "config2" => "value2" }
  564. data_params = {"data1" => "value1", "data2" => "value2"}
  565. args = {ENDPOINT_CLASSNAME => @dummy_endpoint, CONFIG => config_params, DATA => data_params}
  566. command(:add_peer, @peer_id, args)
  567. new_config_params = { "config1" => "new_value1" }
  568. new_data_params = {"data1" => "new_value1"}
  569. new_args = {CONFIG => new_config_params, DATA => new_data_params}
  570. command(:update_peer_config, @peer_id, new_args)
  571. #Make sure the updated key/value pairs in config and data were successfully updated, and that those we didn't
  572. #update are still there and unchanged
  573. peer_config = command(:get_peer_config, @peer_id)
  574. command(:remove_peer, @peer_id)
  575. assert_equal("new_value1", peer_config.get_configuration.get("config1"))
  576. assert_equal("value2", peer_config.get_configuration.get("config2"))
  577. assert_equal("new_value1", Bytes.to_string(peer_config.get_peer_data.get(Bytes.toBytes("data1"))))
  578. assert_equal("value2", Bytes.to_string(peer_config.get_peer_data.get(Bytes.toBytes("data2"))))
  579. end
  580. define_test "append_peer_exclude_namespaces: works with namespaces array" do
  581. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  582. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  583. command(:add_peer, @peer_id, args)
  584. command(:set_peer_replicate_all, @peer_id, true)
  585. namespaces = ["ns1", "ns2"]
  586. namespaces_str = "!ns1;ns2"
  587. command(:append_peer_exclude_namespaces, @peer_id, namespaces)
  588. assert_equal(1, command(:list_peers).length)
  589. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  590. peer_config = command(:list_peers).get(0).getPeerConfig
  591. assert_equal(namespaces_str,
  592. replication_admin.show_peer_exclude_namespaces(peer_config))
  593. namespaces = ["ns3"]
  594. namespaces_str = "!ns1;ns2;ns3"
  595. command(:append_peer_exclude_namespaces, @peer_id, namespaces)
  596. assert_equal(1, command(:list_peers).length)
  597. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  598. peer_config = command(:list_peers).get(0).getPeerConfig
  599. assert_equal(namespaces_str,
  600. replication_admin.show_peer_exclude_namespaces(peer_config))
  601. # append a namespace which is already excluded in the peer config
  602. command(:append_peer_exclude_namespaces, @peer_id, namespaces)
  603. assert_equal(1, command(:list_peers).length)
  604. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  605. peer_config = command(:list_peers).get(0).getPeerConfig
  606. assert_equal(namespaces_str,
  607. replication_admin.show_peer_exclude_namespaces(peer_config))
  608. # cleanup for future tests
  609. command(:remove_peer, @peer_id)
  610. end
  611. define_test "remove_peer_exclude_namespaces: works with namespaces array" do
  612. cluster_key = "zk4,zk5,zk6:11000:/hbase-test"
  613. args = {CLUSTER_KEY => cluster_key, ENDPOINT_CLASSNAME => @dummy_endpoint}
  614. command(:add_peer, @peer_id, args)
  615. namespaces = ["ns1", "ns2", "ns3"]
  616. command(:set_peer_exclude_namespaces, @peer_id, namespaces)
  617. namespaces = ["ns1", "ns2"]
  618. namespaces_str = "!ns3"
  619. command(:remove_peer_exclude_namespaces, @peer_id, namespaces)
  620. assert_equal(1, command(:list_peers).length)
  621. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  622. peer_config = command(:list_peers).get(0).getPeerConfig
  623. assert_equal(namespaces_str,
  624. replication_admin.show_peer_exclude_namespaces(peer_config))
  625. namespaces = ["ns3"]
  626. namespaces_str = nil
  627. command(:remove_peer_exclude_namespaces, @peer_id, namespaces)
  628. assert_equal(1, command(:list_peers).length)
  629. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  630. peer_config = command(:list_peers).get(0).getPeerConfig
  631. assert_equal(namespaces_str,
  632. replication_admin.show_peer_exclude_namespaces(peer_config))
  633. # remove a namespace which is not in peer config
  634. command(:remove_peer_namespaces, @peer_id, namespaces)
  635. assert_equal(1, command(:list_peers).length)
  636. assert_equal(@peer_id, command(:list_peers).get(0).getPeerId)
  637. peer_config = command(:list_peers).get(0).getPeerConfig
  638. assert_equal(namespaces_str,
  639. replication_admin.show_peer_exclude_namespaces(peer_config))
  640. # cleanup for future tests
  641. command(:remove_peer, @peer_id)
  642. end
  643. # assert_raise fails on native exceptions - https://jira.codehaus.org/browse/JRUBY-5279
  644. # Can't catch native Java exception with assert_raise in JRuby 1.6.8 as in the test below.
  645. # define_test "add_peer: adding a second peer with same id should error" do
  646. # command(:add_peer, @peer_id, '')
  647. # assert_equal(1, command(:list_peers).length)
  648. #
  649. # assert_raise(java.lang.IllegalArgumentException) do
  650. # command(:add_peer, @peer_id, '')
  651. # end
  652. #
  653. # assert_equal(1, command(:list_peers).length, 1)
  654. #
  655. # # cleanup for future tests
  656. # command(:remove_peer, @peer_id)
  657. # end
  658. end
  659. end