예제 #1
0
        public void TestZipper()
        {
            var fileSize               = 1024 * 1024;
            var bufferSize             = 32 * 1024;
            var dataContext            = new DataContext();
            var synchronizationContext = new SynchronizationContext();

            FileGenerator.CreateOrReadCyclicFile(fileSize);
            var fileName        = FileGenerator.GetInputFileName(fileSize);
            var segmentProvider = new SegmentProvider(false, bufferSize);

            Zipper.Process(fileName, segmentProvider, CompressionMode.Compress, 100, dataContext, synchronizationContext);
            Assert.AreEqual(fileSize / bufferSize + 1, dataContext.OutputData.Keys.Count());
        }
예제 #2
0
        [DataRow(32L * 1024 * 1024 * 1024)] // 32 Gb
        public void TestFile(long fileSize)
        {
            var buffer               = FileGenerator.CreateOrReadCyclicFile(fileSize);
            var inputFilename        = FileGenerator.GetInputFileName(fileSize);
            var compressedFileName   = $"{fileSize}compressed.test";
            var decompressedFileName = $"{fileSize}decompressed.test";
            var inputFileSize        = 0L;

            var sw = Stopwatch.StartNew();

            using (var compressor = new GZipArchiver(inputFilename, compressedFileName, CompressionMode.Compress))
            {
                compressor.Process();
            }

            sw.Stop();
            Console.WriteLine($"Compressed in {sw.Elapsed.TotalSeconds} s");

            Assert.IsTrue(File.Exists(compressedFileName));

            sw.Restart();
            using (var compressor = new GZipArchiver(compressedFileName, decompressedFileName, CompressionMode.Decompress))
                compressor.Process();

            sw.Stop();
            Console.WriteLine($"Decompressed in {sw.Elapsed.TotalSeconds} s");

            Assert.IsTrue(File.Exists(decompressedFileName));

            using (var file = File.OpenRead(decompressedFileName))
            {
                inputFileSize = new FileInfo(inputFilename).Length;
                Assert.AreEqual(inputFileSize, file.Length);

                var  newData        = new byte[buffer.Length];
                long alreadyChecked = 0;

                while (alreadyChecked < file.Length && alreadyChecked <= 100 * 1024 * 1024)
                {
                    file.Read(newData, 0, buffer.Length);
                    CollectionAssert.AreEqual(buffer, newData);
                    alreadyChecked += buffer.Length;
                }
            }
        }
예제 #3
0
        public void TestZipper_Concurrency()
        {
            var fileSize               = 1024 * 1024;
            var bufferSize             = 32 * 1024;
            var dataContext            = new DataContext();
            var synchronizationContext = new SynchronizationContext();

            FileGenerator.CreateOrReadCyclicFile(fileSize);
            var           fileName        = FileGenerator.GetInputFileName(fileSize);
            var           segmentProvider = new SegmentProvider(false, bufferSize);
            List <Thread> workerThreads   = new List <Thread>();

            for (var i = 0; i < 3; i++)
            {
                var workerThread = new Thread(
                    () =>
                    Zipper.Process(
                        fileName,
                        segmentProvider,
                        CompressionMode.Compress,
                        100,
                        dataContext,
                        synchronizationContext));
                workerThread.Start();
                workerThreads.Add(workerThread);
            }

            foreach (var workerThread in workerThreads)
            {
                workerThread.Join();
            }

            var lastElementIndex = fileSize / bufferSize;

            Assert.AreEqual(lastElementIndex + 1, dataContext.OutputData.Keys.Count());
            Assert.AreEqual(0, dataContext.OutputData[lastElementIndex].Data.Length);
        }