Esempio n. 1
0
        public void WriteRead_Test()
        {
            var dataGenerator = new DataManager(_seed);
            var sourceStream  = dataGenerator.GenerateData(SourceStreamSize);
            var targetStream  = new MemoryStream();

            using (var repo = new ManagedRepository(BlockSize, ChecksumSize, _workDir))
            {
                using (var map = repo.Write(sourceStream))
                    using (new MapMonitor(map))
                    {
                        map.Start();
                        map.Wait();
                    }

                Console.WriteLine();

                using (var map = repo.Read(0, targetStream))
                    using (new MapMonitor(map))
                    {
                        map.Start();
                        map.Wait();
                    }
            }

            Assert.AreEqual(sourceStream, targetStream);
        }
Esempio n. 2
0
        public void Deduplication_Test()
        {
            // Generate test data
            var dataGenerator = new DataManager(_seed);
            var sourceStream  = dataGenerator.GenerateData(SourceStreamSize);

            using (var repo = new ManagedRepository(BlockSize, ChecksumSize, _workDir))
            {
                sourceStream.Seek(0, SeekOrigin.Begin);
                using (var map = repo.Write(sourceStream))
                    using (new MapMonitor(map))
                    {
                        map.Start();
                        map.Wait();
                    }

                Console.WriteLine();

                // Calculate expecdet values
                var expectedDataSize     = repo.DataStream.Length;
                var expectedMetadataSize = repo.MetadataStream.Length;

                sourceStream.Seek(0, SeekOrigin.Begin);
                using (var map = repo.Write(sourceStream))
                    using (new MapMonitor(map))
                    {
                        map.Start();
                        map.Wait();
                    }

                // Second addition of the same data should not change expected values
                var actualdDataSize    = repo.DataStream.Length;
                var actualMetadataSize = repo.MetadataStream.Length;

                Assert.AreEqual(expectedMetadataSize, actualMetadataSize, "Metadata");
                Assert.AreEqual(expectedDataSize, actualdDataSize, "Data");
            }
        }
Esempio n. 3
0
        public void Delete_Test()
        {
            var dataGenerator = new DataManager(_seed);
            var sourceStream  = dataGenerator.GenerateData(10);

            using (var repo = new ManagedRepository(BlockSize, ChecksumSize, _workDir))
            {
                for (var i = 0; i < 3; i++)
                {
                    sourceStream.Seek(0, SeekOrigin.Begin);
                    using (var map = repo.Write(sourceStream))
                        using (new MapMonitor(map))
                        {
                            map.Start();
                            map.Wait();
                        }

                    Console.WriteLine();
                }

                Assert.Contains(0, repo.Maps.ToList());
                Assert.Contains(1, repo.Maps.ToList());
                Assert.Contains(2, repo.Maps.ToList());

                using (var map = repo.Delete(1))
                    using (new MapMonitor(map))
                    {
                        map.Start();
                        map.Wait();
                    }

                Assert.Contains(0, repo.Maps.ToList());
                Assert.Contains(2, repo.Maps.ToList());

                Assert.IsFalse(repo.Maps.Any(x => x == 1), "Map with id 1 should be deleted!");
            }
        }