Exemplo n.º 1
0
		public void Generate_check()
		{
			IList<SignatureInfo> sourceSignatureInfos;
			IList<SignatureInfo> seedSignatureInfos;
			using (var sourceSignatureRepository = CreateSignatureRepositoryFor("test"))
			using (var seedSignatureRepository = CreateSignatureRepositoryFor("test"))
			{
				using (var generator = new SigGenerator())
				{
					seedSignatureInfos = generator.GenerateSignatures(GetSeedStream(), "test", seedSignatureRepository);
				}
				var sourceStream = GetSourceStream();
				using (var generator = new SigGenerator())
				{
					sourceSignatureInfos = generator.GenerateSignatures(sourceStream, "test", sourceSignatureRepository);
				}
				var sourceSize = sourceStream.Length;
				using (var tested = new NeedListGenerator(sourceSignatureRepository, seedSignatureRepository))
				{
					var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last());
					Assert.NotNull(result);

					Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength)));
				}
			}
		}
Exemplo n.º 2
0
        public void Should_be_the_same_signatures()
        {
            const int size = 1024 * 1024 * 5;
            var randomStream = new RandomStream(size);
            var buffer = new byte[size];
            randomStream.Read(buffer, 0, size);
            var stream = new MemoryStream(buffer);

            var firstSigContentHashes = new List<string>();

            using (var signatureRepository = new VolatileSignatureRepository("test"))
            using (var rested = new SigGenerator())
            {
                var result = rested.GenerateSignatures(stream, "test", signatureRepository);

                foreach (var signatureInfo in result)
                {
                    using (var content = signatureRepository.GetContentForReading(signatureInfo.Name))
                    {
                        firstSigContentHashes.Add(content.GetMD5Hash());
                    }
                }
            }

            stream.Position = 0;

            var secondSigContentHashes = new List<string>();

            using (var signatureRepository = new VolatileSignatureRepository("test"))
            using (var rested = new SigGenerator())
            {
                var result = rested.GenerateSignatures(stream, "test", signatureRepository);

                foreach (var signatureInfo in result)
                {
                    using (var content = signatureRepository.GetContentForReading(signatureInfo.Name))
                    {
                        secondSigContentHashes.Add(content.GetMD5Hash());
                    }
                }
            }

            Assert.Equal(firstSigContentHashes.Count, secondSigContentHashes.Count);

            for (var i = 0; i < firstSigContentHashes.Count; i++)
            {
                Assert.Equal(firstSigContentHashes[i], secondSigContentHashes[i]);
            }
        }
Exemplo n.º 3
0
 public void Generate_check()
 {
     using (var signatureRepository = new VolatileSignatureRepository("test"))
     using (var rested = new SigGenerator())
     {
         var result = rested.GenerateSignatures(_stream, "test", signatureRepository);
         Assert.Equal(2, result.Count);
         using (var content = signatureRepository.GetContentForReading(result[0].Name))
         {
             Assert.Equal("91b64180c75ef27213398979cc20bfb7", content.GetMD5Hash());
         }
         using (var content = signatureRepository.GetContentForReading(result[1].Name))
         {
             Assert.Equal("9fe9d408aed35769e25ece3a56f2d12f", content.GetMD5Hash());
         }
     }
 }
Exemplo n.º 4
0
		public void Synchronize_file_with_different_beginning()
		{
			const int size = 5000;
			var differenceChunk = new MemoryStream();
			var sw = new StreamWriter(differenceChunk);

			sw.Write("Coconut is Stupid");
			sw.Flush();

			var sourceContent = PrepareSourceStream(size);
			sourceContent.Position = 0;
			var seedContent = new CombinedStream(differenceChunk, sourceContent);

			using (var sourceSignatureRepository = CreateSignatureRepositoryFor("test2"))
			using (var seedSignatureRepository = CreateSignatureRepositoryFor("test1"))
			{
				IList<SignatureInfo> seedSignatureInfos;
				using (var generator = new SigGenerator())
				{
					seedContent.Seek(0, SeekOrigin.Begin);
					seedSignatureInfos = generator.GenerateSignatures(seedContent, "test1", seedSignatureRepository);
				}
				IList<SignatureInfo> sourceSignatureInfos;
				using (var generator = new SigGenerator())
				{
					sourceContent.Seek(0, SeekOrigin.Begin);
					sourceSignatureInfos = generator.GenerateSignatures(sourceContent, "test2", sourceSignatureRepository);
				}
				var sourceSize = sourceContent.Length;

				using (var tested = new NeedListGenerator(seedSignatureRepository, sourceSignatureRepository))
				{
					var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last());
					Assert.NotNull(result);
					Assert.Equal(2, result.Count);
					Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength)));
				}
			}
		}
Exemplo n.º 5
0
        public void Synchronize_file_with_different_sizes_and_completely_different_content()
        {
            var seedBuffer = new byte[1024 * 1024 * 2]; // 2 MB     
            new Random().NextBytes(seedBuffer);
            var seedContent = new MemoryStream(seedBuffer);

            var smallerBuffer = new byte[1024 * 1024];
            new Random().NextBytes(smallerBuffer);
            var changedContent = new MemoryStream(smallerBuffer);

            using (var seedSignatureRepository = CreateSignatureRepositoryFor("seed"))
            using (var sourceSignatureRepository = CreateSignatureRepositoryFor("source"))
            {
                IList<SignatureInfo> seedSignatureInfos;
                using (var generator = new SigGenerator())
                {
                    seedContent.Seek(0, SeekOrigin.Begin);
                    seedSignatureInfos = generator.GenerateSignatures(seedContent, "seed", seedSignatureRepository);
                }
                IList<SignatureInfo> sourceSignatureInfos;
                using (var generator = new SigGenerator())
                {
                    changedContent.Seek(0, SeekOrigin.Begin);
                    sourceSignatureInfos = generator.GenerateSignatures(changedContent, "source", sourceSignatureRepository);
                }

                var sourceSize = changedContent.Length;

                using (var tested = new NeedListGenerator(seedSignatureRepository, sourceSignatureRepository))
                {
                    var result = tested.CreateNeedsList(seedSignatureInfos.Last(), sourceSignatureInfos.Last());
                    Assert.NotNull(result);
                    Assert.Equal(0, sourceSize - result.Sum(x => Convert.ToInt32(x.BlockLength)));
                }
            }
        }
Exemplo n.º 6
0
        public void Signatures_can_be_generated_on_the_same_repository()
        {
            const int size = 1024 * 1024 * 5;
            var randomStream = new RandomStream(size);
            var buffer = new byte[size];
            randomStream.Read(buffer, 0, size);
            var stream = new MemoryStream(buffer);

            foreach (var fileName in new [] { "test", "content/test", "/content/test"})
            {
                using (var signatureRepository = new VolatileSignatureRepository(fileName))
                using (var rested = new SigGenerator())
                {
                    var signatures = signatureRepository.GetByFileName();
                    Assert.Equal(0, signatures.Count());

                    stream.Position = 0;
                    var result = rested.GenerateSignatures(stream, fileName, signatureRepository);

                    signatures = signatureRepository.GetByFileName();
                    Assert.Equal(2, signatures.Count());

                    stream.Position = 0;
                    result = rested.GenerateSignatures(stream, fileName, signatureRepository);

                    signatures = signatureRepository.GetByFileName();
                    Assert.Equal(2, signatures.Count());
                }
            }
        }