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