Statistics
| Branch: | Revision:

root / trunk / Pithos.Core.Test / NetworkAgentTest.cs @ 437abfca

History | View | Annotate | Download (3.4 kB)

1
using System;
2
using System.Collections.Generic;
3
using System.IO;
4
using System.Linq;
5
using System.Text;
6
using System.Threading.Tasks;
7
using NUnit.Framework;
8
using Pithos.Core.Agents;
9
using Pithos.Interfaces;
10
using Pithos.Network;
11

    
12
namespace Pithos.Core.Test
13
{
14
    [TestFixture]
15
    class NetworkAgentTest
16
    {
17
        [Test]
18
        public async void TestUpload()
19
        {
20
            var agent = new NetworkAgent();
21

    
22
            var account = "890329@vho.grnet.gr";
23
            var apiKey = "24989dce4e0fcb072f8cb60c8922be19";
24

    
25
            var client = new CloudFilesClient(account,apiKey)
26
                             {
27
                                 AuthenticationUrl = @"https://pithos.dev.grnet.gr",
28
                                 UsePithos = true
29
                             };
30

    
31
            
32
            var accountInfo=client.Authenticate();
33

    
34
            var fileName = "012345.dump";
35
            var filePath = Path.Combine(@"e:\pithos\", fileName);
36

    
37
            var random = new Random();
38
            var buffer = new byte[4096];
39
            random.NextBytes(buffer);
40

    
41
            if (File.Exists(filePath))
42
                File.Delete(filePath);
43

    
44
            using (var stream = File.OpenWrite(filePath))
45
            {
46
                for (var i = 0; i < 2* 1024;i++ )
47
                    stream.Write(buffer, 0, buffer.Length);
48
            }
49

    
50

    
51
            client.DeleteObject(null, FolderConstants.PithosContainer, fileName);
52

    
53
            var treeHash = await Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash);
54
            var cloudFile = new ObjectInfo {Account = account, Container = "pithos"};
55
            var fileInfo = new FileInfo(filePath);
56

    
57
            agent.UploadWithHashMap(accountInfo,cloudFile,fileInfo,fileName,treeHash);
58
            
59
            var newHash = await client.GetHashMap(null, FolderConstants.PithosContainer, fileName);
60

    
61

    
62
            
63
            Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
64

    
65
            Assert.AreEqual(treeHash.Hashes, newHash.Hashes);
66

    
67
        }
68

    
69
        [Test]
70
        public void TestDownload()
71
        {
72
            var fileAgent = new FileAgent {CachePath = @"e:\pithos\.pithos.cache"};
73

    
74
            var agent = new NetworkAgent();
75

    
76
            var account = "890329@vho.grnet.gr";
77
            var apiKey = "24989dce4e0fcb072f8cb60c8922be19";
78
            var client = new CloudFilesClient(account,apiKey)
79
            {
80
                AuthenticationUrl = @"https://pithos.dev.grnet.gr",
81
                UsePithos = true
82
            };
83

    
84
            var accountInfo=client.Authenticate();
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 cloudFile = new ObjectInfo {Account = account, Container = FolderConstants.PithosContainer};
93

    
94
            var newHash = client.GetHashMap(null, FolderConstants.PithosContainer, fileName).Result;
95
            agent.DownloadWithBlocks(accountInfo, client, cloudFile, new Uri(fileName, UriKind.Relative), filePath, newHash)
96
                .Wait();
97

    
98
            Assert.IsTrue(File.Exists(filePath));
99
            var treeHash = Signature.CalculateTreeHashAsync(filePath, accountInfo.BlockSize, accountInfo.BlockHash).Result;
100

    
101
            Assert.AreEqual(treeHash.TopHash, newHash.TopHash);
102

    
103
            Assert.AreEqual(treeHash.Hashes, newHash.Hashes);
104

    
105
        }
106

    
107
    }
108
}