示例#1
0
        static void EngineCompareCheck()
        {
            EngineBase e1 =
                new InMemoryEngine();

            EngineBase e2 =
                new InRedisEngine();

            bool stop = false;

            int thread_count = 20;

            List <Thread> threads = new List <Thread>();

            for (int i = 0; i < thread_count; i++)
            {
                Thread t = new Thread(() =>
                {
                    while (stop == false)
                    {
                        Thread.Sleep(0);
                        e1.CreateOrders(1);
                        e2.CreateOrders(1);
                    }
                });

                threads.Add(t);
                t.Start();
            }

            TimeSpan duration = TimeSpan.FromSeconds(10);

            Thread.Sleep(duration);
            stop = true;
            foreach (Thread t in threads)
            {
                t.Join();
            }

            Console.WriteLine($"engine #1:   {e1.StatisticResult} ({e1.GetType().Name})");
            Console.WriteLine($"engine #2:   {e2.StatisticResult} ({e2.GetType().Name})");
            Console.WriteLine($"compare:     {e1.StatisticResult == e2.StatisticResult} (diff: {(e1.StatisticResult - e2.StatisticResult) * 100.0 / e1.StatisticResult:0.00}%)");
            Console.WriteLine($"performance: {e1.StatisticResult / duration.TotalMilliseconds} orders/msec");
        }
        private ISession GetSession() {
            var engine = new InMemoryEngine() { Configuration = new TestConfiguration() };
            var session = new Session(engine, new Mock<ISessionState>().Object);
            
            var authors = new List<User> { new User { Username = "******" }, new User { Username = "******" }, new User { Username = "******" } };
            session.Insert(authors);
            
            var blogs = new List<Blog> { new Blog { Owner = authors[0], Title = "Bob's Blog" } };
            session.Insert(blogs);

            var posts = new List<Post> {
                                           new Post { Author = authors[0], Blog = blogs[0], Title = "My First Post" },
                                           new Post { Author = authors[0], Blog = blogs[0], Title = "My Second Post" }
                                       };
            session.Insert(posts);

            var comments = new List<Comment> {
                                                 new Comment { User = authors[1], Post = posts[0], Content = "This is marks comment on the first post" },
                                                 new Comment {
                                                                 User = authors[1],
                                                                 Post = posts[1],
                                                                 Content = "This is marks comment on the second post"
                                                             },
                                                 new Comment {
                                                                 User = authors[2],
                                                                 Post = posts[0],
                                                                 Content = "This is james' comment on the first post"
                                                             },
                                                 new Comment {
                                                                 User = authors[2],
                                                                 Post = posts[1],
                                                                 Content = "This is james' comment on the second post"
                                                             },
                                                 new Comment { User = authors[0], Post = posts[0], Content = "This is bob's comment on the first post" },
                                                 new Comment {
                                                                 User = authors[0],
                                                                 Post = posts[1],
                                                                 Content = "This is bob's comment on the second post"
                                                             },
                                             };
            session.Insert(comments);
            return session;
        }
示例#3
0
        private ISession GetSession()
        {
            var engine = new InMemoryEngine()
            {
                Configuration = new TestConfiguration()
            };
            var session = new Session(engine, new Mock <ISessionState>().Object);

            var authors = new List <User> {
                new User {
                    Username = "******"
                }, new User {
                    Username = "******"
                }, new User {
                    Username = "******"
                }
            };

            session.Insert(authors);

            var blogs = new List <Blog> {
                new Blog {
                    Owner = authors[0], Title = "Bob's Blog"
                }
            };

            session.Insert(blogs);

            var posts = new List <Post> {
                new Post {
                    Author = authors[0], Blog = blogs[0], Title = "My First Post"
                },
                new Post {
                    Author = authors[0], Blog = blogs[0], Title = "My Second Post"
                }
            };

            session.Insert(posts);

            var comments = new List <Comment> {
                new Comment {
                    User = authors[1], Post = posts[0], Content = "This is marks comment on the first post"
                },
                new Comment {
                    User    = authors[1],
                    Post    = posts[1],
                    Content = "This is marks comment on the second post"
                },
                new Comment {
                    User    = authors[2],
                    Post    = posts[0],
                    Content = "This is james' comment on the first post"
                },
                new Comment {
                    User    = authors[2],
                    Post    = posts[1],
                    Content = "This is james' comment on the second post"
                },
                new Comment {
                    User = authors[0], Post = posts[0], Content = "This is bob's comment on the first post"
                },
                new Comment {
                    User    = authors[0],
                    Post    = posts[1],
                    Content = "This is bob's comment on the second post"
                },
            };

            session.Insert(comments);
            return(session);
        }
示例#4
0
 public InMemoryDatabase(IConfiguration configuration)
 {
     this.configuration = configuration;
     this.engine        = new InMemoryEngine(configuration);
 }