Revision 422c9598 trunk/Pithos.Network.Test/SignatureTest.cs
b/trunk/Pithos.Network.Test/SignatureTest.cs | ||
---|---|---|
1 | 1 |
using System; |
2 |
using System.Collections.Concurrent; |
|
2 | 3 |
using System.Collections.Generic; |
4 |
using System.Diagnostics; |
|
3 | 5 |
using System.IO; |
4 | 6 |
using System.Linq; |
5 | 7 |
using System.Security.Cryptography; |
... | ... | |
35 | 37 |
|
36 | 38 |
var md5 = Signature.CalculateMD5(file); |
37 | 39 |
|
38 |
var hash1 = Signature.CalculateTreeHashAsync(file, (int) blockSize,"sha256").Result; |
|
40 |
var hash1 = Signature.CalculateTreeHashAsync(file, (int) blockSize,"sha256", 2).Result;
|
|
39 | 41 |
Assert.IsNotNull(hash1.Hashes); |
40 | 42 |
Assert.AreEqual(numBlocks, hash1.Hashes.Count()); |
41 | 43 |
|
... | ... | |
60 | 62 |
|
61 | 63 |
var md5 = Signature.CalculateMD5(file); |
62 | 64 |
|
63 |
var hash1 = Signature.CalculateTreeHashAsync(file, (int) blockSize, "sha256").Result; |
|
65 |
var hash1 = Signature.CalculateTreeHashAsync(file, (int) blockSize, "sha256", 2).Result;
|
|
64 | 66 |
hash1.FileId = Guid.NewGuid(); |
65 | 67 |
var task = hash1.Save(@"e:\") |
66 | 68 |
.ContinueWith(_ => TreeHash.LoadTreeHash(@"e:\", hash1.FileId)).Unwrap(); |
... | ... | |
71 | 73 |
}).Wait(); |
72 | 74 |
} |
73 | 75 |
|
76 |
[Test] |
|
77 |
public void TestLargeHashCalculation() |
|
78 |
{ |
|
79 |
|
|
80 |
var file = "e:\\testFile.tmp"; |
|
81 |
if (!File.Exists(file)) |
|
82 |
{ |
|
83 |
byte[] buffer= new byte[300 * 1048576]; |
|
84 |
Random rnd=new Random(); |
|
85 |
rnd.NextBytes(buffer); |
|
86 |
//Create a 100MB buffer |
|
87 |
File.WriteAllBytes(file,buffer); |
|
88 |
} |
|
89 |
|
|
90 |
decimal blockSize = 4 * 1048576; |
|
91 |
|
|
92 |
Trace.WriteLine("1"); |
|
93 |
var stopwatch = Stopwatch.StartNew(); |
|
94 |
var hash1 = Signature.CalculateTreeHashAsync(file, (int)blockSize, "sha256", 1).Result; |
|
95 |
stopwatch.Stop(); |
|
96 |
Trace.WriteLine(stopwatch.Elapsed); |
|
97 |
|
|
98 |
Trace.WriteLine("2"); |
|
99 |
stopwatch.Restart(); |
|
100 |
var hash2 = Signature.CalculateTreeHashAsync(file, (int)blockSize, "sha256", 2).Result; |
|
101 |
stopwatch.Stop(); |
|
102 |
Trace.WriteLine(stopwatch.Elapsed); |
|
103 |
|
|
104 |
Trace.WriteLine("3"); |
|
105 |
stopwatch.Restart(); |
|
106 |
var hash3 = Signature.CalculateTreeHashAsync(file, (int)blockSize, "sha256", 3).Result; |
|
107 |
stopwatch.Stop(); |
|
108 |
Trace.WriteLine(stopwatch.Elapsed); |
|
109 |
|
|
110 |
Assert.That(hash3.TopHash,Is.EquivalentTo(hash2.TopHash)); |
|
111 |
|
|
112 |
|
|
113 |
|
|
114 |
} |
|
115 |
|
|
74 | 116 |
public static string BytesToStr(byte[] bytes) |
75 | 117 |
{ |
76 | 118 |
var str = new StringBuilder(); |
... | ... | |
106 | 148 |
client.UsePithos = true; |
107 | 149 |
client.Authenticate(); |
108 | 150 |
var fileName = @"vlc-1.1.11-win32.exe"; |
109 |
var localHash= Signature.CalculateTreeHashAsync(Path.Combine(@"e:\pithos\", fileName), 4 * 1024 * 1024, "sha256").Result; |
|
151 |
var localHash= Signature.CalculateTreeHashAsync(Path.Combine(@"e:\pithos\", fileName), 4 * 1024 * 1024, "sha256", 2).Result;
|
|
110 | 152 |
var upHash= client.GetHashMap(fileName, account, "pithos").Result; |
111 | 153 |
|
112 | 154 |
Assert.AreEqual(upHash.TopHash, localHash.TopHash); |
... | ... | |
120 | 162 |
|
121 | 163 |
var fileName = @"vlc-1.1.11-win32.exe"; |
122 | 164 |
var syncHash= Signature.CalculateTreeHash(Path.Combine(@"e:\pithos\", fileName), 4 * 1024 * 1024, "sha256"); |
123 |
var asyncHash = Signature.CalculateTreeHashAsync(Path.Combine(@"e:\pithos\", fileName), 4 * 1024 * 1024, "sha256") |
|
165 |
var asyncHash = Signature.CalculateTreeHashAsync(Path.Combine(@"e:\pithos\", fileName), 4 * 1024 * 1024, "sha256", 2)
|
|
124 | 166 |
.Result; |
125 | 167 |
|
126 | 168 |
Assert.AreEqual(syncHash.TopHash, asyncHash.TopHash); |
Also available in: Unified diff