root / trunk / Pithos.Core.Test / NetworkAgentTest.cs @ d78d765c
History | View | Annotate | Download (3.4 kB)
1 |
using System; |
---|---|
2 |
using System.Collections.Concurrent; |
3 |
using System.Collections.Generic; |
4 |
using System.IO; |
5 |
using System.Linq; |
6 |
using System.Text; |
7 |
using System.Threading.Tasks; |
8 |
using NUnit.Framework; |
9 |
using Pithos.Core.Agents; |
10 |
using Pithos.Interfaces; |
11 |
using Pithos.Network; |
12 |
|
13 |
namespace Pithos.Core.Test |
14 |
{ |
15 |
[TestFixture] |
16 |
class NetworkAgentTest |
17 |
{ |
18 |
[Test] |
19 |
public async void TestUpload() |
20 |
{ |
21 |
var agent = new NetworkAgent(); |
22 |
|
23 |
var account = "890329@vho.grnet.gr"; |
24 |
var apiKey = "24989dce4e0fcb072f8cb60c8922be19"; |
25 |
|
26 |
var client = new CloudFilesClient(account,apiKey) |
27 |
{ |
28 |
AuthenticationUrl = @"https://pithos.dev.grnet.gr", |
29 |
UsePithos = true |
30 |
}; |
31 |
|
32 |
|
33 |
var accountInfo=client.Authenticate(); |
34 |
|
35 |
var fileName = "012345.dump"; |
36 |
var filePath = Path.Combine(@"e:\pithos\", fileName); |
37 |
|
38 |
var random = new Random(); |
39 |
var buffer = new byte[4096]; |
40 |
random.NextBytes(buffer); |
41 |
|
42 |
if (File.Exists(filePath)) |
43 |
File.Delete(filePath); |
44 |
|
45 |
using (var stream = File.OpenWrite(filePath)) |
46 |
{ |
47 |
for (var i = 0; i < 2* 1024;i++ ) |
48 |
stream.Write(buffer, 0, buffer.Length); |
49 |
} |
50 |
|
51 |
|
52 |
client.DeleteObject(null, FolderConstants.PithosContainer, fileName); |
53 |
|
54 |
var treeHash = await Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash, 2); |
55 |
var cloudFile = new ObjectInfo {Account = account, Container = "pithos"}; |
56 |
var fileInfo = new FileInfo(filePath); |
57 |
|
58 |
var uploader = new Uploader(); |
59 |
uploader.UploadWithHashMap(accountInfo,cloudFile,fileInfo,fileName,treeHash); |
60 |
|
61 |
var newHash = await client.GetHashMap(null, FolderConstants.PithosContainer, fileName); |
62 |
|
63 |
|
64 |
|
65 |
Assert.AreEqual(treeHash.TopHash, newHash.TopHash); |
66 |
|
67 |
Assert.AreEqual(treeHash.Hashes, newHash.Hashes); |
68 |
|
69 |
} |
70 |
|
71 |
[Test] |
72 |
public void TestDownload() |
73 |
{ |
74 |
var agent = new NetworkAgent(); |
75 |
|
76 |
var account = ""; |
77 |
var apiKey = ""; |
78 |
var client = new CloudFilesClient(account,apiKey) |
79 |
{ |
80 |
AuthenticationUrl = @"https://pithos.dev.grnet.gr", |
81 |
UsePithos = true |
82 |
}; |
83 |
|
84 |
var accountInfo=client.Authenticate(); |
85 |
|
86 |
var fileName = @"AccessDatabaseEngine_x64.exe"; |
87 |
|
88 |
var filePath = Path.Combine(@"e:\pithos\", fileName); |
89 |
if (File.Exists(filePath)) |
90 |
File.Delete(filePath); |
91 |
|
92 |
var cloudFile = new ObjectInfo {Account = account, Container = FolderConstants.PithosContainer}; |
93 |
|
94 |
var newHash = client.GetHashMap(null, FolderConstants.PithosContainer, fileName).Result; |
95 |
var downloader = new Downloader(); |
96 |
downloader.DownloadWithBlocks(accountInfo, client, cloudFile, new Uri(fileName, UriKind.Relative), filePath, newHash) |
97 |
.Wait(); |
98 |
|
99 |
Assert.IsTrue(File.Exists(filePath)); |
100 |
var treeHash = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash, 2).Result; |
101 |
|
102 |
Assert.AreEqual(treeHash.TopHash, newHash.TopHash); |
103 |
|
104 |
Assert.AreEqual(treeHash.Hashes, newHash.Hashes); |
105 |
|
106 |
} |
107 |
|
108 |
} |
109 |
} |