diff --git a/test/integration/types_test.rb b/test/integration/types_test.rb index 86221341..d48f7aa2 100644 --- a/test/integration/types_test.rb +++ b/test/integration/types_test.rb @@ -1,7 +1,7 @@ require "test_helper" class TypesTest < GhostferryTestCase - JSON_OBJ = '{"data": {"float": 32.0, "quote": "\\\'", "value": [1]}}' + JSON_OBJ = '{"data": {"float": 32.0, "quote": "\\\'", "value": [1, 12.13]}}' EMPTY_JSON = '{}' JSON_ARRAY = '[\"test_data\", \"test_data_2\"]' JSON_NULL = 'null' @@ -9,6 +9,7 @@ class TypesTest < GhostferryTestCase JSON_FALSE = 'false' JSON_NUMBER = '42' JSON_FLOATING_POINT_WITH_ZERO_FRACTIONAL_PART = '52.0' + JSON_FLOATING_POINT_WITH_NON_ZERO_FRACTIONAL_PART = '52.13' def test_json_colum_not_null_with_no_default_is_invalid_this_is_fine # See: https://bugs.mysql.com/bug.php?id=98496 @@ -104,10 +105,10 @@ def test_json_data_insert # with a JSON column is broken on 5.7. # See: https://bugs.mysql.com/bug.php?id=87847 res = target_db.query("SELECT COUNT(*) AS cnt FROM #{DEFAULT_FULL_TABLE_NAME}") - assert_equal 18, res.first["cnt"] + assert_equal 20, res.first["cnt"] expected = [ - {"id"=>1, "data"=>"{\"data\": {\"float\": 32.0, \"quote\": \"'\", \"value\": [1]}}"}, + {"id"=>1, "data"=>"{\"data\": {\"float\": 32.0, \"quote\": \"'\", \"value\": [1, 12.13]}}"}, {"id"=>2, "data"=>"[\"test_data\", \"test_data_2\"]"}, {"id"=>3, "data"=>"{}"}, {"id"=>4, "data"=>nil}, @@ -116,15 +117,17 @@ def test_json_data_insert {"id"=>7, "data"=>"false"}, {"id"=>8, "data"=>"42"}, {"id"=>9, "data"=>"52.0"}, - {"id"=>10, "data"=>"{\"data\": {\"float\": 32.0, \"quote\": \"'\", \"value\": [1]}}"}, - {"id"=>11, "data"=>"[\"test_data\", \"test_data_2\"]"}, - {"id"=>12, "data"=>"{}"}, - {"id"=>13, "data"=>nil}, - {"id"=>14, "data"=>"null"}, - {"id"=>15, "data"=>"true"}, - {"id"=>16, "data"=>"false"}, - {"id"=>17, "data"=>"42"}, - {"id"=>18, "data"=>"52.0"}, + {"id"=>10, "data"=>"52.13"}, + {"id"=>11, "data"=>"{\"data\": {\"float\": 32.0, \"quote\": \"'\", \"value\": [1, 12.13]}}"}, + {"id"=>12, "data"=>"[\"test_data\", \"test_data_2\"]"}, + {"id"=>13, "data"=>"{}"}, + {"id"=>14, "data"=>nil}, + {"id"=>15, "data"=>"null"}, + {"id"=>16, "data"=>"true"}, + {"id"=>17, "data"=>"false"}, + {"id"=>18, "data"=>"42"}, + {"id"=>19, "data"=>"52.0"}, + {"id"=>20, "data"=>"52.13"}, ] res = target_db.query("SELECT * FROM #{DEFAULT_FULL_TABLE_NAME} ORDER BY id ASC") @@ -196,7 +199,7 @@ def test_json_data_update loop do sleep 0.1 res = target_db.query("SELECT COUNT(*) AS cnt FROM #{DEFAULT_FULL_TABLE_NAME}") - if res.first["cnt"] == 9 + if res.first["cnt"] == 10 source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = '#{EMPTY_JSON}' WHERE id = 1") source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = '#{JSON_ARRAY}' WHERE id = 2") source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = NULL WHERE id = 3") @@ -206,6 +209,7 @@ def test_json_data_update source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = '#{JSON_FLOATING_POINT_WITH_ZERO_FRACTIONAL_PART}' WHERE id = 7") source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = '#{JSON_NULL}' WHERE id = 8") source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = '#{JSON_NUMBER}' WHERE id = 9") + source_db.query("UPDATE #{DEFAULT_FULL_TABLE_NAME} SET data = '#{JSON_FLOATING_POINT_WITH_NON_ZERO_FRACTIONAL_PART}' WHERE id = 10") break end @@ -220,18 +224,19 @@ def test_json_data_update refute timedout, "failed due to time out while waiting for the 4 insert binlogs to be written to the target" res = target_db.query("SELECT COUNT(*) AS cnt FROM #{DEFAULT_FULL_TABLE_NAME}") - assert_equal 9, res.first["cnt"] + assert_equal 10, res.first["cnt"] expected = [ {"id"=>1, "data"=>"{}"}, {"id"=>2, "data"=>"[\"test_data\", \"test_data_2\"]"}, {"id"=>3, "data"=>nil}, - {"id"=>4, "data"=>"{\"data\": {\"float\": 32.0, \"quote\": \"'\", \"value\": [1]}}"}, + {"id"=>4, "data"=>"{\"data\": {\"float\": 32.0, \"quote\": \"'\", \"value\": [1, 12.13]}}"}, {"id"=>5, "data"=>"true"}, {"id"=>6, "data"=>"false"}, {"id"=>7, "data"=>"52.0"}, {"id"=>8, "data"=>"null"}, {"id"=>9, "data"=>"42"}, + {"id"=>10, "data"=>"52.13"}, ] res = target_db.query("SELECT * FROM #{DEFAULT_FULL_TABLE_NAME} ORDER BY id ASC") @@ -411,6 +416,7 @@ def insert_json_on_source source_db.query("INSERT INTO #{DEFAULT_FULL_TABLE_NAME} (data) VALUES ('#{JSON_FALSE}')") source_db.query("INSERT INTO #{DEFAULT_FULL_TABLE_NAME} (data) VALUES ('#{JSON_NUMBER}')") source_db.query("INSERT INTO #{DEFAULT_FULL_TABLE_NAME} (data) VALUES ('#{JSON_FLOATING_POINT_WITH_ZERO_FRACTIONAL_PART}')") + source_db.query("INSERT INTO #{DEFAULT_FULL_TABLE_NAME} (data) VALUES ('#{JSON_FLOATING_POINT_WITH_NON_ZERO_FRACTIONAL_PART}')") end def execute_copy_data_in_fixed_size_binary_column(column_size:, inserted_data:, expected_inserted_data:, updated_data:)