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