2 using System.Collections.Concurrent;
3 using System.Collections.Generic;
7 using System.Threading.Tasks;
9 using Pithos.Core.Agents;
10 using Pithos.Interfaces;
13 namespace Pithos.Core.Test
16 class NetworkAgentTest
19 public async void TestUpload()
21 var agent = new NetworkAgent();
23 var account = "890329@vho.grnet.gr";
24 var apiKey = "24989dce4e0fcb072f8cb60c8922be19";
26 var client = new CloudFilesClient(account,apiKey)
28 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
33 var accountInfo=client.Authenticate();
35 var fileName = "012345.dump";
36 var filePath = Path.Combine(@"e:\pithos\", fileName);
38 var random = new Random();
39 var buffer = new byte[4096];
40 random.NextBytes(buffer);
42 if (File.Exists(filePath))
43 File.Delete(filePath);
45 using (var stream = File.OpenWrite(filePath))
47 for (var i = 0; i < 2* 1024;i++ )
48 stream.Write(buffer, 0, buffer.Length);
52 client.DeleteObject(null, FolderConstants.PithosContainer, fileName);
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);
58 agent.UploadWithHashMap(accountInfo,cloudFile,fileInfo,fileName,treeHash);
60 var newHash = await client.GetHashMap(null, FolderConstants.PithosContainer, fileName);
64 Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
66 Assert.AreEqual(treeHash.Hashes, newHash.Hashes);
71 public void TestDownload()
73 var agent = new NetworkAgent();
77 var client = new CloudFilesClient(account,apiKey)
79 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
83 var accountInfo=client.Authenticate();
85 var fileName = @"AccessDatabaseEngine_x64.exe";
87 var filePath = Path.Combine(@"e:\pithos\", fileName);
88 if (File.Exists(filePath))
89 File.Delete(filePath);
91 var cloudFile = new ObjectInfo {Account = account, Container = FolderConstants.PithosContainer};
93 var newHash = client.GetHashMap(null, FolderConstants.PithosContainer, fileName).Result;
94 agent.DownloadWithBlocks(accountInfo, client, cloudFile, new Uri(fileName, UriKind.Relative), filePath, newHash)
97 Assert.IsTrue(File.Exists(filePath));
98 var treeHash = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash, 2).Result;
100 Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
102 Assert.AreEqual(treeHash.Hashes, newHash.Hashes);