Exemplo n.º 1
0
        public void ShouldDeleteOutDatedPartitionVersionWhenNotInUse()
        {
            int days   = 40;
            var server = new AsyncJournalServer(TimeSpan.FromSeconds(1));

            using (IJournal <PocoType> journal = WriteJournal(EPartitionType.Month, TimeSpan.FromDays(1), days, server))
            {
                using (var rtx = journal.OpenReadTx())
                {
                    var newVersion       = new PartitionDate(START_DATE, 1, EPartitionType.Month).Name;
                    var newPartitionPath = Path.Combine(_directoryPath, newVersion);
                    Directory.CreateDirectory(newPartitionPath);

                    using (var rtx2 = journal.OpenReadTx())
                    {
                        var len = rtx.All().Length.Value;
                    }
                }

                // Act.
                server.DoEvents();

                // Verify.
                var oldVersion       = new PartitionDate(START_DATE, 0, EPartitionType.Month).Name;
                var oldPartitionPath = Path.Combine(_directoryPath, oldVersion);
                Assert.That(Directory.Exists(oldPartitionPath), Is.EqualTo(false));
            }
        }
Exemplo n.º 2
0
        public long ShouldUseNewPartitionOnRecreate(bool clearPartition1, int days)
        {
            var server = new AsyncJournalServer(TimeSpan.FromSeconds(1));

            using (IJournal <PocoType> journal = WriteJournal(EPartitionType.Month, TimeSpan.FromDays(1), days, server))
            {
                using (var rtx = journal.OpenReadTx())
                {
                    var newVersion       = new PartitionDate(START_DATE, 1, EPartitionType.Month).Name;
                    var newPartitionPath = Path.Combine(_directoryPath, newVersion);
                    Directory.CreateDirectory(newPartitionPath);

                    using (var rtx2 = journal.OpenReadTx())
                    {
                        var len = rtx2.All().Length.Value;
                    }
                }

                // Act.
                server.DoEvents();


                // Verify.
                using (var rtx = journal.OpenReadTx())
                {
                    return(rtx.All().Length.Value);
                }
            }
        }
Exemplo n.º 3
0
        public IJournalCore ToJournal()
        {
            var meta        = CreateJournalMetadata(_config);
            var fileFactory = new CompositeFileFactory(_config.FileFlags);

            if (_server != null)
            {
                var partMan = new PartitionManager(meta, _access, fileFactory, _server);
                return(new JournalCore(meta, partMan));
            }
            else
            {
                var server  = new AsyncJournalServer(_serverTasksLatency);
                var partMan = new PartitionManager(meta, _access, fileFactory, server);
                partMan.OnDisposed += server.Dispose;
                return(new JournalCore(meta, partMan));
            }
        }
Exemplo n.º 4
0
        public IJournal <T> ToJournal <T>()
        {
            _config = UpdateConfiguration(_config);
            var serializerFactory =
                JournalSerializerRegistry.Instance.GetSerializer(_config.SerializerName ??
                                                                 MetadataConstants.DEFAULT_SERIALIZER_NAME);
            var meta = new JournalMetadata(_config, serializerFactory, typeof(T));

            var fileFactory = new CompositeFileFactory(_config.FileFlags);

            if (_server != null)
            {
                var partMan = new PartitionManager(meta, _access, fileFactory, _server);
                return(new Journal <T>(meta, partMan, _server));
            }
            else
            {
                var server  = new AsyncJournalServer(_serverTasksLatency);
                var partMan = new PartitionManager(meta, _access, fileFactory, server);
                partMan.OnDisposed += server.Dispose;
                return(new Journal <T>(meta, partMan, _server));
            }
        }
Exemplo n.º 5
0
        private IJournal <PocoType> WriteJournal(EPartitionType type, TimeSpan increment, int days, AsyncJournalServer server = null)
        {
            Utils.ClearJournal <PocoType>(FOLDER_PATH);
            IJournal <PocoType> qj = OpenJournal(EFileAccess.ReadWrite, type, server);

            AppendRecords(qj, START_DATE, increment, days);
            return(qj);
        }
Exemplo n.º 6
0
 private static IJournal <PocoType> OpenJournal(EFileAccess access, EPartitionType type, AsyncJournalServer server)
 {
     _directoryPath = Path.Combine(Utils.FindJournalsPath(), FOLDER_PATH);
     return(new JournalBuilder()
            .WithRecordCountHint((int)1E6)
            .WithPartitionBy(type)
            .WithLocation(_directoryPath)
            .WithSymbolColumn("Sym", 20, 5, 5)
            .WithTimestampColumn("Timestamp")
            .WithAccess(access)
            .WithSerializerFactoryName(MetadataConstants.POCO_SERIALIZER_NAME)
            .WithJournalServer(server)
            .ToJournal <PocoType>());
 }