public void Ds3ObjectsReturnConsistentHashCodes(Ds3Object ds3Object) { var hashCode1 = ds3Object.GetHashCode(); Assert.AreNotEqual(hashCode1, 0); Assert.AreEqual(hashCode1, ds3Object.GetHashCode()); Assert.AreEqual(hashCode1, new Ds3Object(ds3Object.Name, ds3Object.Size).GetHashCode()); }
protected void runPutFromStream(string bucket, string filename, long size) { runCreateBucket(bucket); // create Ds3Object to store name and size var ds3Obj = new Ds3Object(filename, size); var ds3Objs = new List<Ds3Object>(); ds3Objs.Add(ds3Obj); // start bulk put for objects list IJob job = _helpers.StartWriteJob(bucket, ds3Objs); if (clientSwitch.TraceInfo) { Trace.WriteLine(string.Format("runPutFromStream(): Job id {0}", job.JobId)); } Console.WriteLine("Started job runPutFromStream()"); // Provide Func<string, stream> to be called on each object job.Transfer(key => { var data = new byte[size]; var stream = new MemoryStream(data); for (int i = 0; i < size; i++) { stream.WriteByte((byte)(i & 0x7f)); } stream.Seek(0, SeekOrigin.Begin); return stream; }); }
public void Ds3ObjectEqualsReturnsTrueWhenCopyOfSelf(Ds3Object ds3Object) { Assert.IsTrue(ds3Object.Equals(new Ds3Object(ds3Object.Name, ds3Object.Size))); }
public void Ds3ObjectEqualsReturnsFalseWhenComparingNull(Ds3Object ds3Object) { Assert.IsFalse(ds3Object.Equals(null)); }
protected void runPut(string bucket, string srcDirectory, string filename) { // Creates a bucket if it does not already exist. runCreateBucket(bucket); // get file size, instantiate Ds3Object, add to list FileInfo fileInfo = new FileInfo(Path.Combine(srcDirectory, filename)); var ds3Obj = new Ds3Object(filename, fileInfo.Length); var ds3Objs = new List<Ds3Object>(); ds3Objs.Add(ds3Obj); // Creates a bulk job with the server based on the files in a directory (recursively). IJob job = _helpers.StartWriteJob(bucket, ds3Objs); if (clientSwitch.TraceInfo) { Trace.WriteLine(string.Format("runPut({1}): Job id {0}", job.JobId, filename)); } Console.WriteLine(string.Format("Started job runPut({0})", filename)); // Provide Func<string, stream> to be called on each object job.Transfer(FileHelpers.BuildFilePutter(srcDirectory)); }
protected void runPutWithChecksum(string bucket, string srcDirectory, string filename, string hashString = null, Checksum.ChecksumType checksumType = Checksum.ChecksumType.Md5) { _helpers.EnsureBucketExists(bucket); FileInfo fileInfo = new FileInfo(Path.Combine(srcDirectory, filename)); var ds3Obj = new Ds3Object(filename, fileInfo.Length); var ds3Objs = new List<Ds3Object>(); ds3Objs.Add(ds3Obj); // create a job var job = _helpers.StartWriteJob(bucket, ds3Objs); // instantiate a PutObjectRequest FileStream fs = File.Open(srcDirectory + Path.DirectorySeparatorChar + filename, FileMode.Open); PutObjectRequest putRequest = new PutObjectRequest(bucket, filename, job.JobId, 0L, fs); if (string.IsNullOrEmpty(hashString)) { // Compute checksum putRequest.WithChecksum(Checksum.Compute, checksumType); } else { // or pass in a precomputed Base64 string representation of the hash putRequest.WithChecksum(Checksum.Value(Convert.FromBase64String(hashString)), checksumType); } _client.PutObject(putRequest); fs.Close(); }
public DeleteObjectRequest(Bucket bucket, Ds3Object ds3Object): this (bucket.Name, ds3Object.Name) { }
public void TestPutWithSuppliedChecksum() { const string bucketName = "TestPutWithSuppliedChecksum"; //This test is supported only for BP 1.2 if (!IsTestSupported(_client, 1.2)) { Assert.Ignore(); } try { // "123456789" has a well known checksum const string content = "123456789"; const string testChecksumCrc32C = "4waSgw=="; var testObject = new Ds3Object("numbers.txt", 9); var ds3Objs = new List<Ds3Object> {testObject}; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(content))) { // create or ensure bucket _helpers.EnsureBucketExists(bucketName); // create a job var job = _helpers.StartWriteJob(bucketName, ds3Objs); var putRequest = new PutObjectRequest(bucketName, testObject.Name, stream) .WithJob(job.JobId) .WithOffset(0L); putRequest.WithChecksum(ChecksumType.Value(Convert.FromBase64String(testChecksumCrc32C)), ChecksumType.Type.CRC_32C); _client.PutObject(putRequest); } } finally { Ds3TestUtils.DeleteBucket(_client, bucketName); } }
public static void CheckContents(Ds3Object contents, string key, long size) { Assert.AreEqual(key, contents.Name); Assert.AreEqual(size, contents.Size); }
public void TestSpecialCharacter() { var bucketName = TESTBUCKET; _helpers.EnsureBucketExists(bucketName); var fileName = "varsity1314/_projects/VARSITY 13-14/_versions/Varsity 13-14 (2015-10-05 1827)/_project/Trash/PCMAC HD.avb"; var obj = new Ds3Object(fileName, 1024); var objs = new List<Ds3Object>(); objs.Add(obj); try { var job = _helpers.StartWriteJob(bucketName, objs); job.Transfer(key => { var data = new byte[1024]; var stream = new MemoryStream(data); for (int i = 0; i < 1024; i++) { stream.WriteByte(97); } stream.Seek(0, SeekOrigin.Begin); return stream; }); } finally { // DeleteObject(bucketName, fileName); ** will fail in mono } }
public void TestSpecialCharacterInObjectName() { var bucketName = TESTBUCKET; _helpers.EnsureBucketExists(bucketName); var fileName = "varsity1314/_projects/VARSITY 13-14/_versions/Varsity 13-14 (2015-10-05 1827)/_project/Trash/PCMAC HD.avb"; var obj = new Ds3Object(fileName, 1024); var objs = new List<Ds3Object>(); objs.Add(obj); var job = _helpers.StartWriteJob(bucketName, objs); job.Transfer(key => { var data = new byte[1024]; var stream = new MemoryStream(data); for (int i = 0; i < 1024; i++) { stream.WriteByte(97); } stream.Seek(0, SeekOrigin.Begin); return stream; }); // Is it there? var putfile = from f in ListBucketObjects() where f.Name == fileName select f; Assert.AreEqual(1, putfile.Count()); DeleteObject(bucketName, fileName); }
public void TestPutWithBadChecksum() { // "123456789" has a well known checksum string content = "123456789"; string testBadChecksumCrc32C = "4awSwg=="; // transposed two pairs Ds3Object testObject = new Ds3Object("numbers_badcrc.txt", 9); var ds3Objs = new List<Ds3Object>(); ds3Objs.Add(testObject); using (MemoryStream stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(content))) { // create or ensure bucket _helpers.EnsureBucketExists(TESTBUCKET); // create a job var job = _helpers.StartWriteJob(TESTBUCKET, ds3Objs); PutObjectRequest putRequest = new PutObjectRequest(TESTBUCKET, testObject.Name, job.JobId, 0L, stream); putRequest.WithChecksum(Checksum.Value(Convert.FromBase64String(testBadChecksumCrc32C)), Checksum.ChecksumType.Crc32C); _client.PutObject(putRequest); } // CURRENT SIMULATOR CREATES THIS OBJECT -- PROBABLY SHOULD NOT DeleteObject(TESTBUCKET, testObject.Name); }
public void TestPutWithSuppliedChecksum() { // "123456789" has a well known checksum string content = "123456789"; string testChecksumCrc32C = "4waSgw=="; Ds3Object testObject = new Ds3Object("numbers.txt", 9); var ds3Objs = new List<Ds3Object> {testObject}; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(content))) { // create or ensure bucket _helpers.EnsureBucketExists(TESTBUCKET); // create a job var job = _helpers.StartWriteJob(TESTBUCKET, ds3Objs); PutObjectRequest putRequest = new PutObjectRequest(TESTBUCKET, testObject.Name, job.JobId, 0L, stream); putRequest.WithChecksum(Checksum.Value(Convert.FromBase64String(testChecksumCrc32C)), Checksum.ChecksumType.Crc32C); _client.PutObject(putRequest); } //clean up DeleteObject(TESTBUCKET, testObject.Name); }
public void TestPlusCharacterInQueryParam() { const string bucketName = "TestPlusCharacterInQueryParam"; try { _helpers.EnsureBucketExists(bucketName); const string fileName = "Test+Plus+Character"; var obj = new Ds3Object(fileName, 1024); var objs = new List<Ds3Object> {obj}; var job = _helpers.StartWriteJob(bucketName, objs); job.Transfer(key => { var data = new byte[1024]; var stream = new MemoryStream(data); for (var i = 0; i < 1024; i++) { stream.WriteByte(97); } stream.Seek(0, SeekOrigin.Begin); return stream; }); // Does a query param escape properly? GetObjectsDetailsSpectraS3Request getObjectsWithNameRequest = new GetObjectsDetailsSpectraS3Request() .WithName(fileName); var getObjectsResponse = _client.GetObjectsDetailsSpectraS3(getObjectsWithNameRequest); var filename = from f in getObjectsResponse.ResponsePayload.S3Objects where f.Name == fileName select f; Assert.AreEqual(1, filename.Count()); } finally { Ds3TestUtils.DeleteBucket(_client, bucketName); } }
public void TestSpecialCharacterInObjectName() { const string bucketName = "TestSpecialCharacterInObjectName"; try { _helpers.EnsureBucketExists(bucketName); const string fileName = "varsity1314/_projects/VARSITY 13-14/_versions/Varsity 13-14 (2015-10-05 1827)/_project/Trash/PCMAC HD.avb"; var obj = new Ds3Object(fileName, 1024); var objs = new List<Ds3Object> {obj}; var job = _helpers.StartWriteJob(bucketName, objs); job.Transfer(key => { var data = new byte[1024]; var stream = new MemoryStream(data); for (var i = 0; i < 1024; i++) { stream.WriteByte(97); } stream.Seek(0, SeekOrigin.Begin); return stream; }); // Is it there? var putfile = from f in ListBucketObjects(bucketName) where f.Name == fileName select f; Assert.AreEqual(1, putfile.Count()); } finally { Ds3TestUtils.DeleteBucket(_client, bucketName); } }
public void Ds3ObjectEqualsReturnsTrueWhenSameInstance(Ds3Object ds3Object) { Assert.IsTrue(ds3Object.Equals(ds3Object)); }
internal string toDs3ObjectSize(Ds3Object ds3Object) { if (ds3Object.Size == null) { return null; } return ds3Object.Size.Value.ToString("D"); }
public void TestPutWithBadChecksum() { const string bucketName = "TestPutWithBadChecksum"; try { // "123456789" has a well known checksum const string content = "123456789"; const string testBadChecksumCrc32C = "4awSwg=="; // transposed two pairs var testObject = new Ds3Object("numbers_badcrc.txt", 9); var ds3Objs = new List<Ds3Object> {testObject}; using (var stream = new MemoryStream(System.Text.Encoding.UTF8.GetBytes(content))) { // create or ensure bucket _helpers.EnsureBucketExists(bucketName); // create a job var job = _helpers.StartWriteJob(bucketName, ds3Objs); var putRequest = new PutObjectRequest(bucketName, testObject.Name, stream) .WithJob(job.JobId) .WithOffset(0L); putRequest.WithChecksum(ChecksumType.Value(Convert.FromBase64String(testBadChecksumCrc32C)), ChecksumType.Type.CRC_32C); Assert.Throws<Ds3BadStatusCodeException>(() => _client.PutObject(putRequest)); } } finally { Ds3TestUtils.DeleteBucket(_client, bucketName); } }