Set the correct Storage Object Length in CreateStorageObject

Closes-Bug:1437750

Change-Id: I63a73d5e881f727317d877a27e98be0d40ccd6f1
This commit is contained in:
plemanach
2015-03-29 12:39:55 +01:00
parent 147864bc78
commit 9a22fb78f8
7 changed files with 41 additions and 9 deletions

View File

@@ -70,7 +70,7 @@ namespace OpenStack.Test.HttpAbstraction
Assert.IsTrue(response.Headers.Contains("Content-Length"));
Assert.IsTrue(response.Headers.Contains("Content-Type"));
Assert.IsTrue(int.Parse(response.Headers["Content-Length"].First()) > 200);
Assert.IsTrue(int.Parse(response.Headers["Content-Length"].First()) > 100);
Assert.AreEqual("application/json", response.Headers["Content-Type"].First());
Assert.IsNotNull(response.Content);

View File

@@ -322,6 +322,33 @@ namespace OpenStack.Test.Storage
Assert.AreEqual(containerName, obj.ContainerName);
}
[TestMethod]
public void CanParseObjectFromHeadersAndSpecificObjectLength()
{
var containerName = "TestContainer";
var objectName = "TestObject";
var headers = new HttpHeadersAbstraction()
{
{"Content-Length", "1234"},
{"Content-Type", "application/octet-stream"},
{"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"},
{"ETag", "d41d8cd98f00b204e9800998ecf8427e"}
};
var converter = new StorageObjectPayloadConverter();
var obj = converter.Convert(containerName, objectName, headers, 100);
Assert.IsNotNull(obj);
Assert.IsInstanceOfType(obj, typeof(StorageObject));
Assert.AreEqual(100, obj.Length);
Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", obj.ETag);
Assert.AreEqual("application/octet-stream", obj.ContentType);
Assert.AreEqual(DateTime.Parse("Wed, 12 Mar 2014 23:42:23 GMT"), obj.LastModified);
Assert.AreEqual(objectName, obj.Name);
Assert.AreEqual(containerName, obj.ContainerName);
}
[TestMethod]
public void CanParseObjectFromHeadersWithMetadata()
{

View File

@@ -1232,7 +1232,7 @@ namespace OpenStack.Test.Storage
var headers = new HttpHeadersAbstraction()
{
{"Content-Length", "1234"},
{"Content-Length", "0"},
{"Content-Type", "application/octet-stream"},
{"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"},
{"ETag", "d41d8cd98f00b204e9800998ecf8427e"}
@@ -1250,7 +1250,7 @@ namespace OpenStack.Test.Storage
Assert.IsNotNull(result);
Assert.AreEqual(objectName, result.Name);
Assert.AreEqual(containerName, result.ContainerName);
Assert.AreEqual(1234, result.Length);
Assert.AreEqual(12, result.Length); //length of content stream
Assert.AreEqual("application/octet-stream", result.ContentType);
Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", result.ETag);
Assert.AreEqual(DateTime.Parse("Wed, 12 Mar 2014 23:42:23 GMT"), result.LastModified);
@@ -1264,7 +1264,7 @@ namespace OpenStack.Test.Storage
var headers = new HttpHeadersAbstraction()
{
{"Content-Length", "1234"},
{"Content-Length", "0"},
{"Content-Type", "application/octet-stream"},
{"Last-Modified", "Wed, 12 Mar 2014 23:42:23 GMT"},
{"ETag", "d41d8cd98f00b204e9800998ecf8427e"}
@@ -1282,7 +1282,7 @@ namespace OpenStack.Test.Storage
Assert.IsNotNull(result);
Assert.AreEqual(objectName, result.FullName);
Assert.AreEqual(containerName, result.ContainerName);
Assert.AreEqual(1234, result.Length);
Assert.AreEqual(12, result.Length);//12 length of the content stream
Assert.AreEqual("application/octet-stream", result.ContentType);
Assert.AreEqual("d41d8cd98f00b204e9800998ecf8427e", result.ETag);
Assert.AreEqual(DateTime.Parse("Wed, 12 Mar 2014 23:42:23 GMT"), result.LastModified);

View File

@@ -39,8 +39,9 @@ namespace OpenStack.Storage
/// <param name="containerName">The name of the parent container.</param>
/// <param name="objectName">The name of the storage object.</param>
/// <param name="headers">The collection of headers</param>
/// <param name="objectLength">The storage object length just created</param>
/// <returns>The storage object.</returns>
StorageObject Convert(string containerName, string objectName, IHttpHeadersAbstraction headers);
StorageObject Convert(string containerName, string objectName, IHttpHeadersAbstraction headers, long? objectLength = null);
/// <summary>
/// Converts a collection of StorageObjects into a Json payload.

View File

@@ -105,7 +105,7 @@ namespace OpenStack.Storage
}
/// <inheritdoc/>
public StorageObject Convert(string containerName, string objectName, IHttpHeadersAbstraction headers)
public StorageObject Convert(string containerName, string objectName, IHttpHeadersAbstraction headers, long? objectLength = null)
{
containerName.AssertIsNotNullOrEmpty("containerName");
objectName.AssertIsNotNullOrEmpty("objectName");
@@ -116,6 +116,10 @@ namespace OpenStack.Storage
var lastModified = DateTime.Parse(headers["Last-Modified"].First());
var eTag = headers["ETag"].First();
var length = long.Parse(headers["Content-Length"].First());
if (objectLength.HasValue)
{
length = objectLength.Value;
}
var contentType = headers["Content-Type"].First();
var metadata = headers.Where(kvp => kvp.Key.StartsWith("X-Object-Meta")).ToDictionary(header => header.Key.Substring(14, header.Key.Length - 14), header => header.Value.First());

View File

@@ -61,7 +61,7 @@ namespace OpenStack.Storage
}
var converter = this.ServiceLocator.Locate<IStorageObjectPayloadConverter>();
var respObj = converter.Convert(obj.ContainerName, obj.FullName, resp.Headers);
var respObj = converter.Convert(obj.ContainerName, obj.FullName, resp.Headers, content.Length);
return respObj;
}

View File

@@ -34,4 +34,4 @@ For more examples see the *OpenStack/Examples* directory.
Development
-----------
The `homepage for the development effort <https://wiki.openstack.org/wiki/OpenStack-SDK-DotNet>`_ is on the OpenStack Wiki. The .NET SDK is developed through the same processes as the OpenStack services. `Features requests <https://blueprints.launchpad.net/openstack-sdk-dotnet>`_ and `bugs <https://bugss.launchpad.net/openstack-sdk-dotnet>`_ are filed through launchpad.
The `homepage for the development effort <https://wiki.openstack.org/wiki/OpenStack-SDK-DotNet>`_ is on the OpenStack Wiki. The .NET SDK is developed through the same processes as the OpenStack services. `Features requests <https://blueprints.launchpad.net/openstack-sdk-dotnet>`_ and `bugs <https://bugs.launchpad.net/openstack-sdk-dotnet>`_ are filed through launchpad.