示例#1
0
        public void name_is_set()
        {
            var checksum = new FileCheckpoint(HelperExtensions.GetFilePathFromAssembly("filename"), "test");

            Assert.AreEqual("test", checksum.Name);
            checksum.Close();
        }
示例#2
0
        public void name_is_set()
        {
            var checksum = new FileCheckpoint("filename", "test");

            Assert.AreEqual("test", checksum.Name);
            checksum.Close();
        }
示例#3
0
        private static TFChunkDbConfig CreateTfDbConfig(int chunkSize, string dbPath, int chunksToCache)
        {
            if (!Directory.Exists(dbPath)) // mono crashes without this check
            {
                Directory.CreateDirectory(dbPath);
            }

            ICheckpoint writerChk;
            ICheckpoint chaserChk;

            if (Runtime.IsMono)
            {
                writerChk = new FileCheckpoint(Path.Combine(dbPath, Checkpoint.Writer + ".chk"), Checkpoint.Writer, cached: true);
                chaserChk = new FileCheckpoint(Path.Combine(dbPath, Checkpoint.Chaser + ".chk"), Checkpoint.Chaser, cached: true);
            }
            else
            {
                writerChk = new MemoryMappedFileCheckpoint(Path.Combine(dbPath, Checkpoint.Writer + ".chk"), Checkpoint.Writer, cached: true);
                chaserChk = new MemoryMappedFileCheckpoint(Path.Combine(dbPath, Checkpoint.Chaser + ".chk"), Checkpoint.Chaser, cached: true);
            }
            var nodeConfig = new TFChunkDbConfig(dbPath,
                                                 new VersionedPatternFileNamingStrategy(dbPath, "chunk-"),
                                                 chunkSize,
                                                 chunksToCache,
                                                 writerChk,
                                                 new[] { chaserChk });

            return(nodeConfig);
        }
示例#4
0
        protected static TFChunkDbConfig CreateDbConfig(string dbPath, int cachedChunks, long chunksCacheSize, bool inMemDb)
        {
            ICheckpoint writerChk;
            ICheckpoint chaserChk;
            ICheckpoint epochChk;
            ICheckpoint truncateChk;

            if (inMemDb)
            {
                writerChk   = new InMemoryCheckpoint(Checkpoint.Writer);
                chaserChk   = new InMemoryCheckpoint(Checkpoint.Chaser);
                epochChk    = new InMemoryCheckpoint(Checkpoint.Epoch, initValue: -1);
                truncateChk = new InMemoryCheckpoint(Checkpoint.Truncate, initValue: -1);
            }
            else
            {
                if (!Directory.Exists(dbPath)) // mono crashes without this check
                {
                    Directory.CreateDirectory(dbPath);
                }

                var writerCheckFilename   = Path.Combine(dbPath, Checkpoint.Writer + ".chk");
                var chaserCheckFilename   = Path.Combine(dbPath, Checkpoint.Chaser + ".chk");
                var epochCheckFilename    = Path.Combine(dbPath, Checkpoint.Epoch + ".chk");
                var truncateCheckFilename = Path.Combine(dbPath, Checkpoint.Truncate + ".chk");
                if (Runtime.IsMono)
                {
                    writerChk   = new FileCheckpoint(writerCheckFilename, Checkpoint.Writer, cached: true);
                    chaserChk   = new FileCheckpoint(chaserCheckFilename, Checkpoint.Chaser, cached: true);
                    epochChk    = new FileCheckpoint(epochCheckFilename, Checkpoint.Epoch, cached: true, initValue: -1);
                    truncateChk = new FileCheckpoint(truncateCheckFilename, Checkpoint.Truncate, cached: true, initValue: -1);
                }
                else
                {
                    writerChk   = new MemoryMappedFileCheckpoint(writerCheckFilename, Checkpoint.Writer, cached: true);
                    chaserChk   = new MemoryMappedFileCheckpoint(chaserCheckFilename, Checkpoint.Chaser, cached: true);
                    epochChk    = new MemoryMappedFileCheckpoint(epochCheckFilename, Checkpoint.Epoch, cached: true, initValue: -1);
                    truncateChk = new MemoryMappedFileCheckpoint(truncateCheckFilename, Checkpoint.Truncate, cached: true, initValue: -1);
                }
            }
            var cache = cachedChunks >= 0
                                ? cachedChunks * (long)(TFConsts.ChunkSize + ChunkHeader.Size + ChunkFooter.Size)
                                : chunksCacheSize;
            var nodeConfig = new TFChunkDbConfig(dbPath,
                                                 new VersionedPatternFileNamingStrategy(dbPath, "chunk-"),
                                                 TFConsts.ChunkSize,
                                                 cache,
                                                 writerChk,
                                                 chaserChk,
                                                 epochChk,
                                                 truncateChk,
                                                 inMemDb);

            return(nodeConfig);
        }
示例#5
0
        public void the_new_value_is_accessible_after_flush()
        {
            var checkSum     = new FileCheckpoint(Filename);
            var readChecksum = new FileCheckpoint(Filename);

            checkSum.Write(1011);
            checkSum.Flush();
            Assert.AreEqual(1011, readChecksum.Read());
            checkSum.Close();
            readChecksum.Close();
        }
示例#6
0
        public void reading_off_same_instance_gives_most_up_to_date_info()
        {
            var checkSum = new FileCheckpoint(Filename);

            checkSum.Write(0xDEAD);
            checkSum.Flush();
            var read = checkSum.Read();

            checkSum.Close();
            Assert.AreEqual(0xDEAD, read);
        }
示例#7
0
        public void the_new_value_is_not_accessible_if_not_flushed_even_with_delay()
        {
            var checkSum     = new FileCheckpoint(Filename);
            var readChecksum = new FileCheckpoint(Filename);

            checkSum.Write(1011);
            Thread.Sleep(200);
            Assert.AreEqual(0, readChecksum.Read());
            checkSum.Close();
            readChecksum.Close();
        }
示例#8
0
        public void can_read_existing_checksum()
        {
            var checksum = new FileCheckpoint(Filename);

            checksum.Write(0xDEAD);
            checksum.Close();
            checksum = new FileCheckpoint(Filename);
            var val = checksum.Read();

            checksum.Close();
            Assert.AreEqual(0xDEAD, val);
        }
        public void mem_mapped_file_checkpoint_can_be_read_as_file_checkpoint()
        {
            var memoryMapped = new MemoryMappedFileCheckpoint(Filename);

            memoryMapped.Write(0xDEAD);
            memoryMapped.Flush();
            memoryMapped.Dispose();

            var fileCheckpoint = new FileCheckpoint(Filename);
            var read           = fileCheckpoint.Read();

            fileCheckpoint.Dispose();
            Assert.AreEqual(0xDEAD, read);
        }
示例#10
0
        private static TFChunkDbConfig CreateDbConfig(int chunkSize, string dbPath, long chunksCacheSize, bool inMemDb)
        {
            ICheckpoint writerChk;
            ICheckpoint chaserChk;
            ICheckpoint epochChk;
            ICheckpoint truncateChk;

            if (inMemDb)
            {
                writerChk   = new InMemoryCheckpoint(Checkpoint.Writer);
                chaserChk   = new InMemoryCheckpoint(Checkpoint.Chaser);
                epochChk    = new InMemoryCheckpoint(Checkpoint.Epoch, initValue: -1);
                truncateChk = new InMemoryCheckpoint(Checkpoint.Truncate, initValue: -1);
            }
            else
            {
                var writerCheckFilename   = Path.Combine(dbPath, Checkpoint.Writer + ".chk");
                var chaserCheckFilename   = Path.Combine(dbPath, Checkpoint.Chaser + ".chk");
                var epochCheckFilename    = Path.Combine(dbPath, Checkpoint.Epoch + ".chk");
                var truncateCheckFilename = Path.Combine(dbPath, Checkpoint.Truncate + ".chk");
                if (Runtime.IsMono)
                {
                    writerChk   = new FileCheckpoint(writerCheckFilename, Checkpoint.Writer, cached: true);
                    chaserChk   = new FileCheckpoint(chaserCheckFilename, Checkpoint.Chaser, cached: true);
                    epochChk    = new FileCheckpoint(epochCheckFilename, Checkpoint.Epoch, cached: true, initValue: -1);
                    truncateChk = new FileCheckpoint(truncateCheckFilename, Checkpoint.Truncate, cached: true, initValue: -1);
                }
                else
                {
                    writerChk   = new MemoryMappedFileCheckpoint(writerCheckFilename, Checkpoint.Writer, cached: true);
                    chaserChk   = new MemoryMappedFileCheckpoint(chaserCheckFilename, Checkpoint.Chaser, cached: true);
                    epochChk    = new MemoryMappedFileCheckpoint(epochCheckFilename, Checkpoint.Epoch, cached: true, initValue: -1);
                    truncateChk = new MemoryMappedFileCheckpoint(truncateCheckFilename, Checkpoint.Truncate, cached: true, initValue: -1);
                }
            }
            var nodeConfig = new TFChunkDbConfig(dbPath,
                                                 new VersionedPatternFileNamingStrategy(dbPath, "chunk-"),
                                                 chunkSize,
                                                 chunksCacheSize,
                                                 writerChk,
                                                 chaserChk,
                                                 epochChk,
                                                 truncateChk,
                                                 inMemDb);

            return(nodeConfig);
        }
示例#11
0
        protected static TFChunkDbConfig CreateDbConfig(string dbPath, int cachedChunks, long chunksCacheSize, bool inMemDb)
        {
            ICheckpoint writerChk;
            ICheckpoint chaserChk;
            ICheckpoint epochChk;
            ICheckpoint truncateChk;

            if (inMemDb)
            {
                writerChk   = new InMemoryCheckpoint(Checkpoint.Writer);
                chaserChk   = new InMemoryCheckpoint(Checkpoint.Chaser);
                epochChk    = new InMemoryCheckpoint(Checkpoint.Epoch, initValue: -1);
                truncateChk = new InMemoryCheckpoint(Checkpoint.Truncate, initValue: -1);
            }
            else
            {
                try
                {
                    if (!Directory.Exists(dbPath)) // mono crashes without this check
                    {
                        Directory.CreateDirectory(dbPath);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                    if (dbPath == Locations.DefaultDataDirectory)
                    {
                        Log.Info("Access to path {0} denied. The Event Store database will be created in {1}", dbPath, Locations.FallbackDefaultDataDirectory);
                        dbPath = Locations.FallbackDefaultDataDirectory;
                        Log.Info("Defaulting DB Path to {0}", dbPath);

                        if (!Directory.Exists(dbPath)) // mono crashes without this check
                        {
                            Directory.CreateDirectory(dbPath);
                        }
                    }
                    else
                    {
                        throw;
                    }
                }
                var writerCheckFilename   = Path.Combine(dbPath, Checkpoint.Writer + ".chk");
                var chaserCheckFilename   = Path.Combine(dbPath, Checkpoint.Chaser + ".chk");
                var epochCheckFilename    = Path.Combine(dbPath, Checkpoint.Epoch + ".chk");
                var truncateCheckFilename = Path.Combine(dbPath, Checkpoint.Truncate + ".chk");
                if (Runtime.IsMono)
                {
                    writerChk   = new FileCheckpoint(writerCheckFilename, Checkpoint.Writer, cached: true);
                    chaserChk   = new FileCheckpoint(chaserCheckFilename, Checkpoint.Chaser, cached: true);
                    epochChk    = new FileCheckpoint(epochCheckFilename, Checkpoint.Epoch, cached: true, initValue: -1);
                    truncateChk = new FileCheckpoint(truncateCheckFilename, Checkpoint.Truncate, cached: true, initValue: -1);
                }
                else
                {
                    writerChk   = new MemoryMappedFileCheckpoint(writerCheckFilename, Checkpoint.Writer, cached: true);
                    chaserChk   = new MemoryMappedFileCheckpoint(chaserCheckFilename, Checkpoint.Chaser, cached: true);
                    epochChk    = new MemoryMappedFileCheckpoint(epochCheckFilename, Checkpoint.Epoch, cached: true, initValue: -1);
                    truncateChk = new MemoryMappedFileCheckpoint(truncateCheckFilename, Checkpoint.Truncate, cached: true, initValue: -1);
                }
            }
            var cache = cachedChunks >= 0
                                ? cachedChunks * (long)(TFConsts.ChunkSize + ChunkHeader.Size + ChunkFooter.Size)
                                : chunksCacheSize;
            var nodeConfig = new TFChunkDbConfig(dbPath,
                                                 new VersionedPatternFileNamingStrategy(dbPath, "chunk-"),
                                                 TFConsts.ChunkSize,
                                                 cache,
                                                 writerChk,
                                                 chaserChk,
                                                 epochChk,
                                                 truncateChk,
                                                 inMemDb);

            return(nodeConfig);
        }