public void Read_records_match_written_records()
        {
            const int totalCount     = 10000;
            const int partitionCount = 3;

            using (var journal = CreateJournal())
            {
                GenerateRecords(journal, totalCount, partitionCount);
            }

            using (var j = OpenJournal(EFileAccess.Read))
            {
                var  q         = j.OpenReadTx();
                long count     = 0;
                var  expected  = new PocoQuote();
                var  increment = GetTimestampIncrement(totalCount, partitionCount);

                foreach (PocoQuote quote in q.All())
                {
                    GenerateQuoteValues(expected, increment, count);
                    AssertEqual(quote, expected);
                    count++;
                }

                Assert.That(count, Is.EqualTo(totalCount));
            }
        }
 private void AssertEqual(PocoQuote quote, PocoQuote expected)
 {
     Assert.That(quote.Timestamp, Is.EqualTo(expected.Timestamp));
     Assert.That(quote.Sym, Is.EqualTo(expected.Sym));
     Assert.That(quote.Mode, Is.EqualTo(expected.Mode));
     Assert.That(quote.Ex, Is.EqualTo(expected.Ex));
     Assert.That(quote.BidSize, Is.EqualTo(expected.BidSize));
     Assert.That(quote.Bid, Is.EqualTo(expected.Bid));
     Assert.That(quote.AskSize, Is.EqualTo(expected.AskSize));
     Assert.That(quote.Ask, Is.EqualTo(expected.Ask));
 }
 public static void GenerateQuoteValues(PocoQuote trade, long incrementMs, long i)
 {
     trade.Timestamp = START_TIMESTAMP + incrementMs * i;
     trade.Bid       = i * 2.04;
     trade.Bid       = i;
     trade.BidSize   = (int)i;
     trade.Ask       = i * 50.09014;
     trade.AskSize   = (int)(i % int.MaxValue);
     trade.Ex        = "LXE";
     trade.Mode      = "Fast trading";
     trade.Sym       = SYMBOLS[i % SYMBOLS.Length];
 }
Exemple #4
0
        public void ReadWrite()
        {
            // Clean..
            Utils.ClearJournal <PocoQuote>("c:\\temp\\quote");

            // Create.
            var journal = new JournalBuilder()
                          .WithRecordCountHint(1000000)
                          .WithPartitionBy(EPartitionType.Day)
                          .WithLocation("c:\\temp\\quote")
                          .WithSymbolColumn("Sym", 20, 5, 5)
                          .WithSymbolColumn("Ex", 20, 20, 20)
                          .WithSymbolColumn("Mode", 20, 20, 20)
                          .WithTimestampColumn("Timestamp")
                          .WithAccess(EFileAccess.ReadWrite)
                          .ToJournal <PocoQuote>();

            // Append.
            var start = DateTime.Now.Date.AddMonths(-1);

            using (var wr = journal.OpenWriteTx())
            {
                var quote = new PocoQuote();
                for (int i = 0; i < 1000000; i++)
                {
                    quote.Timestamp = start.AddSeconds(i);
                    quote.Bid       = i * 2.04;
                    quote.Bid       = i;
                    quote.BidSize   = i;
                    quote.Ask       = i * 50.09014;
                    quote.AskSize   = i;
                    quote.Ex        = "LXE";
                    quote.Mode      = "Fast trading";
                    quote.Sym       = "SYM" + i % 20;
                    wr.Append(quote);
                }
                wr.Commit();
            }

            // Query.
            // Read all where Sym = "SYM11".
            using (var rdr = journal.OpenReadTx())
            {
                Console.WriteLine(rdr.Items.Where(i => i.Sym == "SYM0").Count());
            }
        }
        public static TimeSpan GenerateRecords(IJournal <PocoQuote> journal, int count, int partitionCount)
        {
            var increment = GetTimestampIncrement(count, partitionCount);
            var stopwatch = new Stopwatch();

            using (var wr = journal.OpenWriteTx())
            {
                stopwatch.Start();
                var quote = new PocoQuote();
                for (int i = 0; i < count; i++)
                {
                    GenerateQuoteValues(quote, increment, i);
                    wr.Append(quote);
                }
                wr.Commit();
            }
            stopwatch.Stop();
            return(stopwatch.Elapsed);
        }