test/random_data.rb in avro-salsify-fork-1.9.0.0 vs test/random_data.rb in avro-salsify-fork-1.9.0.1

- old
+ new

@@ -25,19 +25,21 @@ def next nextdata(@schm) end def nextdata(schm, d=0) + return logical_nextdata(schm, d=0) unless schm.type_adapter.eql?(Avro::LogicalTypes::Identity) + case schm.type_sym when :boolean rand > 0.5 when :string randstr() when :int - rand(Avro::Schema::INT_MAX_VALUE - Avro::Schema::INT_MIN_VALUE) + Avro::Schema::INT_MIN_VALUE + rand_int when :long - rand(Avro::Schema::LONG_MAX_VALUE - Avro::Schema::LONG_MIN_VALUE) + Avro::Schema::LONG_MIN_VALUE + rand_long when :float (-1024 + 2048 * rand).round.to_f when :double Avro::Schema::LONG_MIN_VALUE + (Avro::Schema::LONG_MAX_VALUE - Avro::Schema::LONG_MIN_VALUE) * rand when :bytes @@ -77,14 +79,31 @@ schm.size.times { f << BYTEPOOL[rand(BYTEPOOL.size), 1] } f end end + def logical_nextdata(schm, _d=0) + case schm.logical_type + when 'date' + Avro::LogicalTypes::IntDate.decode(rand_int) + when 'timestamp-millis', 'timestamp-micros' + Avro::LogicalTypes::TimestampMicros.decode(rand_long) + end + end + CHARPOOL = 'abcdefghjkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789' BYTEPOOL = '12345abcd' def randstr(chars=CHARPOOL, length=20) str = '' rand(length+1).times { str << chars[rand(chars.size)] } str + end + + def rand_int + rand(Avro::Schema::INT_MAX_VALUE - Avro::Schema::INT_MIN_VALUE) + Avro::Schema::INT_MIN_VALUE + end + + def rand_long + rand(Avro::Schema::LONG_MAX_VALUE - Avro::Schema::LONG_MIN_VALUE) + Avro::Schema::LONG_MIN_VALUE end end