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 agent.CloudClient.Authenticate("890329@vho.grnet.gr", "24989dce4e0fcb072f8cb60c8922be19");
32 var fileName = "012345.dump";
33 var filePath = Path.Combine(@"e:\pithos\", fileName);
35 var random = new Random();
36 var buffer = new byte[4096];
37 random.NextBytes(buffer);
39 if (File.Exists(filePath))
40 File.Delete(filePath);
42 using (var stream = File.OpenWrite(filePath))
44 for (var i = 0; i < 2* 1024;i++ )
45 stream.Write(buffer, 0, buffer.Length);
49 agent.CloudClient.DeleteObject(agent.PithosContainer, fileName);
51 var task = Signature.CalculateTreeHashAsync(filePath, agent.BlockSize, agent.BlockHash);
52 agent.UploadWithHashMap(new FileInfo(filePath),fileName,task);
54 var newHash = agent.CloudClient.GetHashMap(agent.PithosContainer, fileName).Result;
57 var treeHash = task.Result;
58 Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
60 Assert.AreEqual(treeHash.Hashes, newHash.Hashes);
65 public void TestDownload()
67 var fileAgent = new FileAgent {FragmentsPath = @"e:\pithos\Fragments"};
69 var agent = new NetworkAgent
71 PithosContainer = "pithos",
74 CloudClient = new CloudFilesClient
76 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
82 agent.CloudClient.Authenticate("890329@vho.grnet.gr", "24989dce4e0fcb072f8cb60c8922be19");
84 var fileName = @"AccessDatabaseEngine_x64.exe";
86 var filePath = Path.Combine(@"e:\pithos\", fileName);
87 if (File.Exists(filePath))
88 File.Delete(filePath);
90 var newHash = agent.CloudClient.GetHashMap(agent.PithosContainer, fileName).Result;
91 agent.DownloadWithBlocks(agent.PithosContainer,new Uri(fileName,UriKind.Relative),filePath,newHash)
94 Assert.IsTrue(File.Exists(filePath));
95 var treeHash = Signature.CalculateTreeHashAsync(filePath, agent.BlockSize, agent.BlockHash).Result;
97 Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
99 Assert.AreEqual(treeHash.Hashes, newHash.Hashes);