test/test_io.rb in avro-1.3.3 vs test/test_io.rb in avro-1.5.4
- old
+ new
@@ -3,13 +3,13 @@
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
-#
+#
# http://www.apache.org/licenses/LICENSE-2.0
-#
+#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
@@ -143,19 +143,19 @@
def avro_hexlify(reader)
bytes = []
current_byte = reader.read(1)
bytes << hexlify(current_byte)
- while (current_byte[0] & 0x80) != 0
+ while (current_byte.unpack('C').first & 0x80) != 0
current_byte = reader.read(1)
bytes << hexlify(current_byte)
end
bytes.join ' '
end
def hexlify(msg)
- msg.split("").collect { |c| c[0].to_s(16).rjust(2, '0') }.join
+ msg.unpack("H*")
end
def test_binary_int_encoding
for value, hex_encoding in BINARY_INT_ENCODINGS
# write datum in binary to string buffer
@@ -230,10 +230,32 @@
assert_equal value_to_read, read_value
end
end
+ def test_skip_union
+ ["hello", -1, 32, nil].each do |value_to_skip|
+ value_to_read = 6253
+
+ schema = Avro::Schema.parse('["int", "string", "null"]')
+ writer = StringIO.new
+ encoder = Avro::IO::BinaryEncoder.new(writer)
+ datum_writer = Avro::IO::DatumWriter.new(schema)
+ datum_writer.write(value_to_skip, encoder)
+ datum_writer.write(value_to_read, encoder)
+
+ reader = StringIO.new(writer.string)
+ decoder = Avro::IO::BinaryDecoder.new(reader)
+ datum_reader = Avro::IO::DatumReader.new(schema)
+ datum_reader.skip_data(schema, decoder)
+ read_value = datum_reader.read(decoder)
+
+ assert_equal value_to_read, read_value
+ end
+ end
+
+
def test_schema_promotion
promotable_schemas = ['"int"', '"long"', '"float"', '"double"']
incorrect = 0
promotable_schemas.each_with_index do |ws, i|
writers_schema = Avro::Schema.parse(ws)
@@ -308,10 +330,10 @@
def check_datafile(schm)
seed = 0
count = 10
random_data = RandomData.new(schm, seed)
-
+
f = File.open(DATAFILE, 'wb')
dw = Avro::DataFile::Writer.new(f, datum_writer(schm), schm)
count.times{ dw << random_data.next }
dw.close