Esempio n. 1
0
        public void ShouldKeepSizeTheSame()
        {
            long size = 2 * 1024 * 1024; // 2 mega
            var password = new byte[] { 0x33, 0xFF, 0xAB };

            ReynaService.ResetStorageSizeLimit();
            var sqliteRepository = new SQLiteRepository(password);
            sqliteRepository.Create();

            var reynaService = new ReynaService(password, null, new ReynaNullLogger());
            reynaService.Start();

            var assemblyFile = new FileInfo(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
            var path = Path.Combine(assemblyFile.DirectoryName, "reyna.db");

            putMessageFromFile(reynaService, assemblyFile.DirectoryName, 100);
            
            FileInfo fileInfo = new FileInfo(path);
            Assert.AreEqual(5649408, fileInfo.Length);

            ReynaService.SetStorageSizeLimit(password, size);
            reynaService.Stop();
            fileInfo = new FileInfo(path);
            Assert.AreEqual(1754112, fileInfo.Length);
            File.Delete(path);
        }
Esempio n. 2
0
        public static void SetStorageSizeLimit(byte[] password, long limit)
        {
            limit = limit < MinimumStorageLimit ? MinimumStorageLimit : limit;
            new Preferences().SetStorageSizeLimit(limit);

            var repository = new SQLiteRepository(password);
            repository.Initialise();
            repository.ShrinkDb(limit);
        }
Esempio n. 3
0
        public void ShouldEncryptDbIfPasswordIsPassedAndDbIsNotEncrypted()
        {
            var sqliteRepository = new SQLiteRepository(new byte[] { 0x33, 0xFF, 0xAB });
            sqliteRepository.Create();

            var reynaService = new ReynaService(new byte[] { 0x33, 0xFF, 0xAB }, null, new ReynaNullLogger());
            reynaService.Start();

            var assemblyFile = new FileInfo(Assembly.GetExecutingAssembly().ManifestModule.FullyQualifiedName);
            var path = Path.Combine(assemblyFile.DirectoryName, "reyna.db");

            var bytes = new byte[16];
            using (var file = File.OpenRead(path))
            {
                file.Read(bytes, 0, bytes.Length);
            }

            var stringResult = System.Text.Encoding.UTF8.GetString(bytes, 0, bytes.Length);
            Assert.AreNotEqual("SQLite format 3\0", stringResult);

            reynaService.Stop();
            File.Delete(path);
        }
Esempio n. 4
0
        public void WhenAddingAndRemovingFromDifferentThreadShouldNotThrow()
        {
            var password = new byte[] { 0x33, 0xFF, 0xAB };

            ReynaService.ResetStorageSizeLimit();
            this.Repository = new SQLiteRepository(password);
            this.Repository.Create();

            Thread injectingThread = new Thread(this.AddMessage);
            Thread removingThread = new Thread(this.RemoveMessage);
            Thread readThread = new Thread(this.ReadMessages);
            Thread deleteThread = new Thread(this.DeleteMessages);

            injectingThread.Start();
            removingThread.Start();
            readThread.Start();
            deleteThread.Start();

            injectingThread.Join();
            removingThread.Join();
            readThread.Join();
            deleteThread.Join();

            Assert.AreEqual(0, this.Repository.AvailableMessagesCount);
        }