Skip to content

Commit

Permalink
Fixed ShareStats bug (#7595)
Browse files Browse the repository at this point in the history
  • Loading branch information
gapra-msft authored Jan 29, 2020
1 parent 5a19707 commit 2f86baf
Show file tree
Hide file tree
Showing 17 changed files with 665 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ public final class Constants {
*/
public static final int MB = 1024 * KB;

/**
* Represents a non-SI gigabyte.
*/
public static final int GB = 1024 * MB;

/**
* Represents the value for {@link SasProtocol#HTTPS_ONLY}.
*/
Expand Down
1 change: 1 addition & 0 deletions sdk/storage/azure-storage-file-share/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Release History

## 12.2.0-beta.1 (Unreleased)
- Fixed bug in ShareClient.getStatistics where shareUsageInGB was not properly converted. Added parameter to ShareStatistics to include a shareUsageInBytes parameter.
- Fixed bug where ShareDirectoryAsyncClient.getFileClient appended an extra / for files in the root directory.

## 12.1.0 (2020-01-08)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,8 @@ private Response<ShareProperties> mapGetPropertiesResponse(SharesGetPropertiesRe
}

private Response<ShareStatistics> mapGetStatisticsResponse(SharesGetStatisticsResponse response) {
ShareStatistics shareStatistics = new ShareStatistics((int) (response.getValue().getShareUsageBytes() / 1024));
ShareStatistics shareStatistics =
new ShareStatistics(response.getValue().getShareUsageBytes());

return new SimpleResponse<>(response, shareStatistics);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@

package com.azure.storage.file.share.models;

import com.azure.storage.common.implementation.Constants;

/**
* Contains statistics about a Share in the storage File service.
*/
public final class ShareStatistics {
private final int shareUsageInGB;
private final long shareUsageInBytes;

/**
* Creates an instance of storage statistics for a Share.
Expand All @@ -16,6 +19,17 @@ public final class ShareStatistics {
*/
public ShareStatistics(int shareUsageInGB) {
this.shareUsageInGB = shareUsageInGB;
this.shareUsageInBytes = -1;
}

/**
* Creates an instance of storage statistics for a Share.
*
* @param shareUsageInBytes Size in bytes of the Share
*/
public ShareStatistics(long shareUsageInBytes) {
this.shareUsageInGB = (int) Math.ceil((double) shareUsageInBytes / Constants.GB);
this.shareUsageInBytes = shareUsageInBytes;
}

/**
Expand All @@ -24,4 +38,11 @@ public ShareStatistics(int shareUsageInGB) {
public int getShareUsageInGB() {
return shareUsageInGB;
}

/**
* @return the size in bytes of the Share
*/
public long getShareUsageInBytes() {
return shareUsageInBytes;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class APISpec extends Specification {
}

static boolean liveMode() {
return testMode == TestMode.LIVE
return testMode != TestMode.PLAYBACK
}

def fileServiceBuilderHelper(final InterceptorManager interceptorManager) {
Expand Down Expand Up @@ -161,7 +161,7 @@ class APISpec extends Specification {
builder.addPolicy(policy)
}

if (!liveMode()) {
if (testMode == TestMode.RECORD) {
builder.addPolicy(interceptorManager.getRecordPolicy())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.azure.storage.file.share.models.NtfsFileAttributes
import com.azure.storage.file.share.models.ShareErrorCode
import com.azure.storage.file.share.models.ShareFileHttpHeaders
import com.azure.storage.file.share.models.ShareSnapshotInfo
import com.azure.storage.file.share.models.ShareStatistics
import com.azure.storage.file.share.models.ShareStorageException
import spock.lang.Unroll

Expand Down Expand Up @@ -249,6 +250,37 @@ class ShareAPITests extends APISpec {
FileTestHelper.assertExceptionStatusCodeAndMessage(e, 404, ShareErrorCode.SHARE_NOT_FOUND)
}

@Unroll
def "Get statistics"() {
setup:
primaryShareClient.create()
primaryShareClient.createFile("tempFile", (long) size)

when:
def resp = primaryShareClient.getStatisticsWithResponse(null, null)

then:
FileTestHelper.assertResponseStatusCode(resp, 200)
resp.getValue().getShareUsageInBytes() == size
resp.getValue().getShareUsageInGB() == gigabytes

where:
size || gigabytes
0 || 0
Constants.KB || 1
Constants.GB || 1
(long) 3 * Constants.GB || 3
}

def "Get statistics error"() {
when:
primaryShareClient.getStatistics()

then:
def e = thrown(ShareStorageException)
FileTestHelper.assertExceptionStatusCodeAndMessage(e, 404, ShareErrorCode.SHARE_NOT_FOUND)
}

def "Create directory"() {
given:
primaryShareClient.create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ package com.azure.storage.file.share

import com.azure.core.http.netty.NettyAsyncHttpClientBuilder
import com.azure.storage.common.StorageSharedKeyCredential
import com.azure.storage.common.implementation.Constants
import com.azure.storage.file.share.models.ShareErrorCode
import com.azure.storage.file.share.models.ShareFileHttpHeaders
import com.azure.storage.file.share.models.NtfsFileAttributes
import com.azure.storage.file.share.models.ShareStorageException
import reactor.test.StepVerifier
import spock.lang.Ignore
import spock.lang.Unroll
Expand Down Expand Up @@ -244,6 +246,38 @@ class ShareAsyncAPITests extends APISpec {
}
}

@Unroll
def "Get statistics"() {
setup:
primaryShareAsyncClient.create().block()
primaryShareAsyncClient.createFile("tempFile", (long) size).block()

when:
def respVerifier = StepVerifier.create(primaryShareAsyncClient.getStatisticsWithResponse())

then:
respVerifier.assertNext {
assert FileTestHelper.assertResponseStatusCode(it, 200)
assert it.getValue().getShareUsageInBytes() == size
assert it.getValue().getShareUsageInGB() == gigabytes
}

where:
size || gigabytes
0 || 0
Constants.KB || 1
Constants.GB || 1
(long) 3 * Constants.GB || 3
}

def "Get statistics error"() {
expect:
StepVerifier.create(primaryShareAsyncClient.getStatistics())
.verifyErrorSatisfies {
assert FileTestHelper.assertExceptionStatusCodeAndMessage(it, 404, ShareErrorCode.SHARE_NOT_FOUND)
}
}

def "Create directory"() {
given:
primaryShareAsyncClient.create().block()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "http://gaprastg71.file.core.windows.net/shareapitestsgetstatistics014066dc6f715ba43e4b?restype=share",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.2.0-beta.1 (11.0.4; Windows 10 10.0)",
"x-ms-client-request-id" : "6c04c3dc-9c9f-4509-afeb-eb45368396d7"
},
"Response" : {
"x-ms-version" : "2019-02-02",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8D79ED007C829F8",
"Last-Modified" : "Wed, 22 Jan 2020 00:14:21 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "ed3757c8-f01a-0002-11b8-d02c83000000",
"Date" : "Wed, 22 Jan 2020 00:14:21 GMT",
"x-ms-client-request-id" : "6c04c3dc-9c9f-4509-afeb-eb45368396d7"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "http://gaprastg71.file.core.windows.net/shareapitestsgetstatistics014066dc6f715ba43e4b/tempFile",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.2.0-beta.1 (11.0.4; Windows 10 10.0)",
"x-ms-client-request-id" : "1cc19890-dc63-42e6-abd5-575854ee1798"
},
"Response" : {
"x-ms-version" : "2019-02-02",
"x-ms-file-permission-key" : "15729343842853002337*8280205063999649007",
"x-ms-file-id" : "13835128424026341376",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-file-creation-time" : "2020-01-22T00:14:21.9037046Z",
"Last-Modified" : "Wed, 22 Jan 2020 00:14:21 GMT",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Wed, 22 Jan 2020 00:14:21 GMT",
"ETag" : "0x8D79ED007E4D176",
"x-ms-file-attributes" : "Archive",
"x-ms-file-change-time" : "2020-01-22T00:14:21.9037046Z",
"x-ms-file-parent-id" : "0",
"Content-Length" : "0",
"x-ms-request-id" : "ed3757cb-f01a-0002-12b8-d02c83000000",
"x-ms-client-request-id" : "1cc19890-dc63-42e6-abd5-575854ee1798",
"x-ms-file-last-write-time" : "2020-01-22T00:14:21.9037046Z"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "http://gaprastg71.file.core.windows.net/shareapitestsgetstatistics014066dc6f715ba43e4b?restype=share&comp=stats",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.2.0-beta.1 (11.0.4; Windows 10 10.0)",
"x-ms-client-request-id" : "4f01e36c-7005-41e5-b201-ab442049930a"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"x-ms-version" : "2019-02-02",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"StatusCode" : "200",
"x-ms-request-id" : "ed3757cd-f01a-0002-13b8-d02c83000000",
"Body" : "<?xml version=\"1.0\" encoding=\"utf-8\"?><ShareStats><ShareUsageBytes>0</ShareUsageBytes></ShareStats>",
"Date" : "Wed, 22 Jan 2020 00:14:21 GMT",
"x-ms-client-request-id" : "4f01e36c-7005-41e5-b201-ab442049930a",
"Content-Type" : "application/xml"
},
"Exception" : null
} ],
"variables" : [ "shareapitestsgetstatistics014066dc6f715ba43e4b" ]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
"networkCallRecords" : [ {
"Method" : "PUT",
"Uri" : "http://gaprastg71.file.core.windows.net/shareapitestsgetstatistics13687515490b8fb3ac45?restype=share",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.2.0-beta.1 (11.0.4; Windows 10 10.0)",
"x-ms-client-request-id" : "cf77a2b0-00bf-4019-8d90-3a8809fa5961"
},
"Response" : {
"x-ms-version" : "2019-02-02",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"ETag" : "0x8D79ED0083D3325",
"Last-Modified" : "Wed, 22 Jan 2020 00:14:22 GMT",
"retry-after" : "0",
"Content-Length" : "0",
"StatusCode" : "201",
"x-ms-request-id" : "ed3757cf-f01a-0002-14b8-d02c83000000",
"Date" : "Wed, 22 Jan 2020 00:14:22 GMT",
"x-ms-client-request-id" : "cf77a2b0-00bf-4019-8d90-3a8809fa5961"
},
"Exception" : null
}, {
"Method" : "PUT",
"Uri" : "http://gaprastg71.file.core.windows.net/shareapitestsgetstatistics13687515490b8fb3ac45/tempFile",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.2.0-beta.1 (11.0.4; Windows 10 10.0)",
"x-ms-client-request-id" : "fcf25cbd-04f1-4a4e-8977-aec9b2e82b08"
},
"Response" : {
"x-ms-version" : "2019-02-02",
"x-ms-file-permission-key" : "15729343842853002337*8280205063999649007",
"x-ms-file-id" : "13835128424026341376",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"x-ms-file-creation-time" : "2020-01-22T00:14:22.5782962Z",
"Last-Modified" : "Wed, 22 Jan 2020 00:14:22 GMT",
"retry-after" : "0",
"StatusCode" : "201",
"x-ms-request-server-encrypted" : "true",
"Date" : "Wed, 22 Jan 2020 00:14:22 GMT",
"ETag" : "0x8D79ED0084BC0B2",
"x-ms-file-attributes" : "Archive",
"x-ms-file-change-time" : "2020-01-22T00:14:22.5782962Z",
"x-ms-file-parent-id" : "0",
"Content-Length" : "0",
"x-ms-request-id" : "ed3757d1-f01a-0002-15b8-d02c83000000",
"x-ms-client-request-id" : "fcf25cbd-04f1-4a4e-8977-aec9b2e82b08",
"x-ms-file-last-write-time" : "2020-01-22T00:14:22.5782962Z"
},
"Exception" : null
}, {
"Method" : "GET",
"Uri" : "http://gaprastg71.file.core.windows.net/shareapitestsgetstatistics13687515490b8fb3ac45?restype=share&comp=stats",
"Headers" : {
"x-ms-version" : "2019-02-02",
"User-Agent" : "azsdk-java-azure-storage-file-share/12.2.0-beta.1 (11.0.4; Windows 10 10.0)",
"x-ms-client-request-id" : "9503a331-4d07-4657-be16-ed9a306c35d8"
},
"Response" : {
"Transfer-Encoding" : "chunked",
"x-ms-version" : "2019-02-02",
"Server" : "Windows-Azure-File/1.0 Microsoft-HTTPAPI/2.0",
"retry-after" : "0",
"StatusCode" : "200",
"x-ms-request-id" : "ed3757d2-f01a-0002-16b8-d02c83000000",
"Body" : "<?xml version=\"1.0\" encoding=\"utf-8\"?><ShareStats><ShareUsageBytes>1024</ShareUsageBytes></ShareStats>",
"Date" : "Wed, 22 Jan 2020 00:14:22 GMT",
"x-ms-client-request-id" : "9503a331-4d07-4657-be16-ed9a306c35d8",
"Content-Type" : "application/xml"
},
"Exception" : null
} ],
"variables" : [ "shareapitestsgetstatistics13687515490b8fb3ac45" ]
}
Loading

0 comments on commit 2f86baf

Please sign in to comment.