Skip to content

Commit

Permalink
Added test case for 100MB block and modified Changelog.md
Browse files Browse the repository at this point in the history
  • Loading branch information
katmsft authored and vinjiang committed Sep 14, 2017
1 parent de8922e commit 854f349
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 65 deletions.
2 changes: 1 addition & 1 deletion BreakingChanges.md
Expand Up @@ -4,7 +4,7 @@ TABLE
* The return type `Azure::Service::EnumerationResult` of `query_tables` has a changed structure. Now the `'updated'` will not be contained, and is flattened to a structure in the form of `{ {"TableName" => "tableone"}, {"TableName" => "tabletwo"}, {"TableName" => "tablethree"}}`.
* The `Azure::Storage::Table::Entity` does not contain `:table` and `updated` anymore. The updated time can be found in `:properties`.
* The return type of `get_table` is changed to a Hash that contains full metadata returned from the server when query the table.
* The method `Azure::Storage::Table::EdmType::unserialize_query_value` is renamed to `unserialize_value`.
* The method `Azure::Storage::Table::EdmType::unserialize_query_value` is renamed to `deserialize_value`.

Tracking Breaking Changes in 0.11.0-preview

Expand Down
15 changes: 15 additions & 0 deletions ChangeLog.md
@@ -1,3 +1,18 @@
2017.09 - version 0.13.0-preview

ALL
* Removed Nokogiri from Gemfile because it causes bundler fail to install azure-storage. Added it back to runtime dependency and explicitly require user to install the correct version of Nokogiri in README.md.
* Service version is upgraded to 2016-05-31.

BLOB
* Block size can now be up to 100MB.

TABLE
* The return type `Azure::Service::EnumerationResult` of `query_tables` has a changed structure. Now the `'updated'` will not be contained, and is flattened to a structure in the form of `{ {"TableName" => "tableone"}, {"TableName" => "tabletwo"}, {"TableName" => "tablethree"}}`.
* The `Azure::Storage::Table::Entity` does not contain `:table` and `updated` anymore. The updated time can be found in `:properties`.
* The return type of `get_table` is changed to a Hash that contains full metadata returned from the server when query the table.
* The method `Azure::Storage::Table::EdmType::unserialize_query_value` is renamed to `deserialize_value`.

2017.08 - version 0.12.3-preview

ALL
Expand Down
18 changes: 8 additions & 10 deletions lib/azure/storage/default.rb
Expand Up @@ -47,13 +47,13 @@ module Default
# Default HTTP port.
DEFAULT_HTTP_PORT = 80
# Default HTTPS port.
DEFAULT_HTTPS_PORT= 443
DEFAULT_HTTPS_PORT = 443

# Marker for atom metadata.
XML_METADATA_MARKER = '$'
# Marker for atom value.
XML_VALUE_MARKER = '_'

def os
host_os = RbConfig::CONFIG['host_os']
case host_os
Expand All @@ -69,17 +69,17 @@ def os
"Unknown #{host_os}"
end
end

module_function :os

# Default User Agent header string
USER_AGENT = "Azure-Storage/#{Azure::Storage::Version.to_uas} (Ruby #{RUBY_VERSION}-p#{RUBY_PATCHLEVEL}; #{os})".freeze

class << self
def options
Hash[Azure::Storage::Configurable.keys.map{|key| [key, send(key)]}]
Hash[Azure::Storage::Configurable.keys.map { |key| [key, send(key)] }]
end

# Default storage access key
# @return [String]
def storage_access_key
Expand All @@ -91,7 +91,7 @@ def storage_access_key
def storage_account_name
ENV['AZURE_STORAGE_ACCOUNT']
end

# Default storage connection string
# @return [String]
def storage_connection_string
Expand Down Expand Up @@ -121,7 +121,7 @@ def storage_blob_host
def storage_queue_host
ENV['AZURE_STORAGE_QUEUE_HOST']
end

# Default storage file host
# @return [String]
def storage_file_host
Expand Down Expand Up @@ -760,11 +760,9 @@ module HeaderConstants

# The returned response payload should be with full metadata.
ODATA_FULL_META = 'application/json;odata=fullmetadata'

end

module QueryStringConstants

# Query component for SAS API version.
API_VERSION = 'api-version'

Expand Down
2 changes: 1 addition & 1 deletion lib/azure/storage/table/edmtype.rb
Expand Up @@ -107,7 +107,7 @@ def self.serialize_query_value(value)
# type - String. The Edm datatype
#
# Returns an typed object
def self.unserialize_value(value, type)
def self.deserialize_value(value, type)
case type
when "Edm.DateTime"
Time.parse(value)
Expand Down
2 changes: 1 addition & 1 deletion lib/azure/storage/table/serialization.rb
Expand Up @@ -93,7 +93,7 @@ def self.entity_from_hash(h)
properties = {}
h.each do |k, v|
type = h[k + TableConstants::ODATA_TYPE_SUFFIX]
properties[k] = EdmType::unserialize_value(v, type.nil? ? EdmType::property_type(v) : type)
properties[k] = EdmType::deserialize_value(v, type.nil? ? EdmType::property_type(v) : type)
end
entity.properties = properties
end
Expand Down
71 changes: 42 additions & 29 deletions test/integration/blob/block_blob_test.rb
Expand Up @@ -24,18 +24,19 @@
require 'integration/test_helper'
require "azure/storage/blob/blob_service"
require 'base64'
require 'securerandom'

describe Azure::Storage::Blob::BlobService do
subject { Azure::Storage::Blob::BlobService.new }
after { ContainerNameHelper.clean }

let(:container_name) { ContainerNameHelper.name }
let(:blob_name) { "blobname" }
let(:content) { content = ""; 512.times.each{|i| content << "@" }; content }
before {
let(:content) { content = ""; 512.times.each { |i| content << "@" }; content }
before {
subject.create_container container_name
}

describe '#create_block_blob' do
it 'creates a block blob' do
blob = subject.create_block_blob container_name, blob_name, content
Expand All @@ -58,13 +59,13 @@
end
end
end
it 'should create a block blob with spaces in name' do
blob_name = 'blob with spaces'
blob = subject.create_block_blob container_name, blob_name, 'content'
blob.name.must_equal blob_name

it 'should create a block blob with spaces in name' do
blob_name = 'blob with spaces'
blob = subject.create_block_blob container_name, blob_name, 'content'
blob.name.must_equal blob_name
end

it 'should create block blob with complex in name' do
blob_name = 'with фбаф.txt'
blob = subject.create_block_blob container_name, blob_name, 'content'
Expand All @@ -73,11 +74,11 @@

it 'sets additional properties when the options hash is used' do
options = {
:content_type=>"application/xml",
:content_encoding=>"gzip",
:content_language=>"en-US",
:cache_control=>"max-age=1296000",
:metadata => { "CustomMetadataProperty"=>"CustomMetadataValue"}
content_type: "application/xml",
content_encoding: "gzip",
content_language: "en-US",
cache_control: "max-age=1296000",
metadata: { "CustomMetadataProperty" => "CustomMetadataValue" }
}

blob = subject.create_block_blob container_name, blob_name, content, options
Expand All @@ -102,23 +103,35 @@
end

describe '#put_blob_block' do
let(:blockid) {"anyblockid1" }
let(:blockid1) { "anyblockid1" }
let(:blockid2) { "anyblockid2" }

it 'creates a block as part of a block blob' do
subject.put_blob_block container_name, blob_name, blockid, content
subject.put_blob_block container_name, blob_name, blockid1, content

# verify
block_list = subject.list_blob_blocks container_name, blob_name
block = block_list[:uncommitted][0]
block.type.must_equal :uncommitted
block.size.must_equal 512
block.name.must_equal blockid
block.name.must_equal blockid1
end

it 'creates a 100M block as part of a block blob' do
content_100_mb = SecureRandom.random_bytes(100 * 1024 * 1024)
subject.put_blob_block container_name, blob_name, blockid2, content_100_mb
# verify
block_list = subject.list_blob_blocks container_name, blob_name
block = block_list[:uncommitted][0]
block.type.must_equal :uncommitted
block.size.must_equal 100 * 1024 * 1024
block.name.must_equal blockid2
end
end

describe '#commit_blob_blocks' do
let(:blocklist) { [["anyblockid0"], ["anyblockid1"]] }
before {
before {
blocklist.each { |block_entry|
subject.put_blob_block container_name, blob_name, block_entry[0], content
}
Expand Down Expand Up @@ -151,8 +164,8 @@

describe '#list_blob_blocks' do
let(:blocklist) { [["anyblockid0"], ["anyblockid1"], ["anyblockid2"], ["anyblockid3"]] }
before {
before {

subject.put_blob_block container_name, blob_name, blocklist[0][0], content
subject.put_blob_block container_name, blob_name, blocklist[1][0], content

Expand Down Expand Up @@ -180,7 +193,7 @@

uncommitted = result[:uncommitted]
uncommitted.length.must_equal 2

expected_blocks = blocklist.slice(2..3).each

uncommitted.each { |block|
Expand All @@ -192,14 +205,14 @@

describe 'when blocklist_type parameter is used' do
it 'lists uncommitted blocks only if :uncommitted is passed' do
result = subject.list_blob_blocks container_name, blob_name, { :blocklist_type => :uncommitted }
result = subject.list_blob_blocks container_name, blob_name, blocklist_type: :uncommitted

committed = result[:committed]
committed.length.must_equal 0

uncommitted = result[:uncommitted]
uncommitted.length.must_equal 2

expected_blocks = blocklist.slice(2..3).each

uncommitted.each { |block|
Expand All @@ -208,13 +221,13 @@
block.size.must_equal 512
}
end

it 'lists committed blocks only if :committed is passed' do
result = subject.list_blob_blocks container_name, blob_name, { :blocklist_type => :committed }
result = subject.list_blob_blocks container_name, blob_name, blocklist_type: :committed

committed = result[:committed]
committed.length.must_equal 2

expected_blocks = blocklist.slice(0..1).each

committed.each { |block|
Expand All @@ -228,7 +241,7 @@
end

it 'lists committed and uncommitted blocks if :all is passed' do
result = subject.list_blob_blocks container_name, blob_name, { :blocklist_type => :all }
result = subject.list_blob_blocks container_name, blob_name, blocklist_type: :all

committed = result[:committed]
committed.length.must_equal 2
Expand Down Expand Up @@ -272,7 +285,7 @@
block.size.must_equal 512
}

result = subject.list_blob_blocks container_name, blob_name, { :blocklist_type => :all, :snapshot => snapshot }
result = subject.list_blob_blocks container_name, blob_name, blocklist_type: :all, snapshot: snapshot

committed = result[:committed]
committed.length.must_equal 2
Expand Down
44 changes: 22 additions & 22 deletions test/unit/table/edmtype_test.rb
Expand Up @@ -71,47 +71,47 @@
end
end

describe "#unserialize_query_value" do
it "correctly unserializes int64 query values" do
describe "#deserialize_query_value" do
it "correctly deserializes int64 query values" do
value = "340282366920938463463374607431769467687"
unserializedValue = Azure::Storage::Table::EdmType.unserialize_value(value, "Edm.Int64")
unserializedValue.must_equal (2**128 + 1256231)
deserializedValue = Azure::Storage::Table::EdmType.deserialize_value(value, "Edm.Int64")
deserializedValue.must_equal (2**128 + 1256231)
end

it "correctly unserializes int32 query values" do
it "correctly deserializes int32 query values" do
value = "2"
unserializedValue = Azure::Storage::Table::EdmType.unserialize_value(value, "Edm.Int32")
unserializedValue.must_equal 2
deserializedValue = Azure::Storage::Table::EdmType.deserialize_value(value, "Edm.Int32")
deserializedValue.must_equal 2
end

it "correctly unserializes datetime query values" do
it "correctly deserializes datetime query values" do
value = "2001-02-03T04:05:06+00:00"
unserializedValue = Azure::Storage::Table::EdmType.unserialize_value(value, "Edm.DateTime")
unserializedValue.must_equal Time.new(2001, 2, 3, 4, 5, 6, "+00:00")
deserializedValue = Azure::Storage::Table::EdmType.deserialize_value(value, "Edm.DateTime")
deserializedValue.must_equal Time.new(2001, 2, 3, 4, 5, 6, "+00:00")
end

it "correctly unserializes guid query values" do
it "correctly deserializes guid query values" do
value = "81425519-6394-43e4-ac6e-28d91f5c3921"
unserializedValue = Azure::Storage::Table::EdmType.unserialize_value(value, "Edm.Guid")
unserializedValue.must_equal Azure::Storage::Table::GUID.new("81425519-6394-43e4-ac6e-28d91f5c3921")
deserializedValue = Azure::Storage::Table::EdmType.deserialize_value(value, "Edm.Guid")
deserializedValue.must_equal Azure::Storage::Table::GUID.new("81425519-6394-43e4-ac6e-28d91f5c3921")
end

it "correctly unserializes float query values" do
it "correctly deserializes float query values" do
value = "1.2"
unserializedValue = Azure::Storage::Table::EdmType.unserialize_value(value, "Edm.Double")
unserializedValue.must_equal 1.2
deserializedValue = Azure::Storage::Table::EdmType.deserialize_value(value, "Edm.Double")
deserializedValue.must_equal 1.2
end

it "correctly unserializes string query values" do
it "correctly deserializes string query values" do
value = "string"
unserializedValue = Azure::Storage::Table::EdmType.unserialize_value(value, "Edm.String")
unserializedValue.must_equal "string"
deserializedValue = Azure::Storage::Table::EdmType.deserialize_value(value, "Edm.String")
deserializedValue.must_equal "string"
end

it "correctly unserializes binary query values" do
it "correctly deserializes binary query values" do
value = "MTIzNDU=".force_encoding("BINARY")
unserializedValue = Azure::Storage::Table::EdmType.unserialize_value(value, "Edm.Binary")
unserializedValue.must_equal "12345"
deserializedValue = Azure::Storage::Table::EdmType.deserialize_value(value, "Edm.Binary")
deserializedValue.must_equal "12345"
end
end
end
2 changes: 1 addition & 1 deletion test/unit/table/serialization_test.rb
Expand Up @@ -75,7 +75,7 @@
]
}

it 'unserialize a table entries from json' do
it 'deserialize a table entries from json' do
result = subject.table_entries_from_json(query_tables_json)
result.must_equal table_entries
end
Expand Down

0 comments on commit 854f349

Please sign in to comment.