Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the failed java unit test related to getBlob. #40

Merged
merged 2 commits into from
Apr 6, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
* Copyright 2011 Microsoft Corporation
*
* Licensed 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
* 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.
* 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.
*/
package com.microsoft.windowsazure.services.blob.implementation;

Expand Down Expand Up @@ -122,6 +122,10 @@ private void ThrowIfError(ClientResponse r) {
PipelineHelpers.ThrowIfError(r);
}

private void ThrowIfNotSuccess(ClientResponse clientResponse) {
PipelineHelpers.ThrowIfNotSuccess(clientResponse);
}

private WebResource addOptionalQueryParam(WebResource webResource, String key, Object value) {
return PipelineHelpers.addOptionalQueryParam(webResource, key, value);
}
Expand Down Expand Up @@ -630,7 +634,7 @@ public GetBlobResult getBlob(String container, String blob, GetBlobOptions optio
builder = addOptionalAccessContitionHeader(builder, options.getAccessCondition());

ClientResponse response = builder.get(ClientResponse.class);
ThrowIfError(response);
ThrowIfNotSuccess(response);

GetBlobPropertiesResult properties = getBlobPropertiesResultFromResponse(response);
GetBlobResult blobResult = new GetBlobResult();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,17 @@
import com.sun.jersey.api.client.WebResource.Builder;

public class PipelineHelpers {
public static void ThrowIfError(ClientResponse r) {
if (r.getStatus() >= 400) {
throw new UniformInterfaceException(r);
public static void ThrowIfNotSuccess(ClientResponse clientResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From grammatical point of view should this be ThrowIfNotSucceed or ThrowIfNotSucceeded. Also ThrowIfFailed would be good name candidate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here the Success is Http Status code according to HTTP standard. Only if the status is 2xx, no exception would be thrown.
http://en.wikipedia.org/wiki/List_of_HTTP_status_codes

int statusCode = clientResponse.getStatus();

if ((statusCode < 200) || (statusCode >= 300)) {
throw new UniformInterfaceException(clientResponse);
}
}

public static void ThrowIfError(ClientResponse clientResponse) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: add header doc to explain the different between error and failure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since the whole file doesn't have header doc, I would leave it for now when we have more resources to do it in a systematic and consistent fashion.

if (clientResponse.getStatus() >= 400) {
throw new UniformInterfaceException(clientResponse);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,31 +380,15 @@ public QueryTablesResult queryTables() throws ServiceException {

@Override
public QueryTablesResult queryTables(QueryTablesOptions options) throws ServiceException {

Query query = options.getQuery();
Query query = new Query();
String nextTableName = options.getNextTableName();
String prefix = options.getPrefix();

if (prefix != null) {
// Append Max char to end '{' is 1 + 'z' in AsciiTable ==> upperBound is prefix + '{'
Filter prefixFilter = Filter.and(Filter.ge(Filter.litteral("TableName"), Filter.constant(prefix)),
Filter.le(Filter.litteral("TableName"), Filter.constant(prefix + "{")));

// a new query is needed if prefix alone is passed in
if (query == null) {
query = new Query();
}

// examine the existing filter on the query
if (query.getFilter() == null) {
// use the prefix filter if the query filter is null
query.setFilter(prefixFilter);
}
else {
// combine and use the prefix filter if the query filter exists
Filter combinedFilter = Filter.and(query.getFilter(), prefixFilter);
query.setFilter(combinedFilter);
}
query.setFilter(prefixFilter);
}

WebResource webResource = getResource(options).path("Tables");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,8 @@

public class QueryTablesOptions extends TableServiceOptions {
private String nextTableName;
private Query query;
private String prefix;

public Query getQuery() {
return query;
}

public QueryTablesOptions setQuery(Query query) {
this.query = query;
return this;
}

public String getNextTableName() {
return nextTableName;
}
Expand Down