Inheritance: ICheckpoint
 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);
 }
 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();
 }
 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 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();
 }
 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;
 }
 public void name_is_set()
 {
     var checksum = new FileCheckpoint("filename", "test");
     Assert.AreEqual("test", checksum.Name);
     checksum.Close();
 }
Esempio n. 7
0
        private static TFChunkDbConfig CreateDbConfig(int chunkSize, int cachedChunks, string dbPath, long chunksCacheSize, bool inMemDb, ILogger log)
        {
            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-"),
                    chunkSize,
                    cache,
                    writerChk,
                    chaserChk,
                    epochChk,
                    truncateChk,
                    inMemDb);

            return nodeConfig;
        }