2 using System.Collections.Generic;
7 using Pithos.Core.Agents;
10 namespace Pithos.Core.Test
13 class NetworkAgentTest
16 public void TestUpload()
18 var agent = new NetworkAgent
20 PithosContainer = "pithos",
23 CloudClient = new CloudFilesClient
25 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
30 var account = "890329@vho.grnet.gr";
31 agent.CloudClient.Authenticate(account, "24989dce4e0fcb072f8cb60c8922be19");
33 var fileName = "012345.dump";
34 var filePath = Path.Combine(@"e:\pithos\", fileName);
36 var random = new Random();
37 var buffer = new byte[4096];
38 random.NextBytes(buffer);
40 if (File.Exists(filePath))
41 File.Delete(filePath);
43 using (var stream = File.OpenWrite(filePath))
45 for (var i = 0; i < 2* 1024;i++ )
46 stream.Write(buffer, 0, buffer.Length);
50 agent.CloudClient.DeleteObject(null, agent.PithosContainer, fileName,agent.TrashContainer);
52 var task = Signature.CalculateTreeHashAsync(filePath, agent.BlockSize, agent.BlockHash);
53 agent.UploadWithHashMap(account,"pithos",new FileInfo(filePath),fileName,task);
55 var newHash = agent.CloudClient.GetHashMap(null, agent.PithosContainer, fileName).Result;
58 var treeHash = task.Result;
59 Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
61 Assert.AreEqual(treeHash.Hashes, newHash.Hashes);
66 public void TestDownload()
68 var fileAgent = new FileAgent {FragmentsPath = @"e:\pithos\Fragments"};
70 var agent = new NetworkAgent
72 PithosContainer = "pithos",
75 CloudClient = new CloudFilesClient
77 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
83 var account = "890329@vho.grnet.gr";
84 agent.CloudClient.Authenticate(account, "24989dce4e0fcb072f8cb60c8922be19");
86 var fileName = @"AccessDatabaseEngine_x64.exe";
88 var filePath = Path.Combine(@"e:\pithos\", fileName);
89 if (File.Exists(filePath))
90 File.Delete(filePath);
92 var newHash = agent.CloudClient.GetHashMap(null, agent.PithosContainer, fileName).Result;
93 agent.DownloadWithBlocks(account,agent.PithosContainer,new Uri(fileName,UriKind.Relative),filePath,newHash)
96 Assert.IsTrue(File.Exists(filePath));
97 var treeHash = Signature.CalculateTreeHashAsync(filePath, agent.BlockSize, agent.BlockHash).Result;
99 Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
101 Assert.AreEqual(treeHash.Hashes, newHash.Hashes);