Exemplo n.º 1
0
        private void AssertSourceHasCountMoreThanOrEqualTo(int count = 0)
        {
            var countSql           = typeof(AnyTableB).GetCount();
            var sourceConnection   = SqlDStart.NewDb().ConnectedTo(WellKnown.Listeners.Free2Listener.DatabaseName, SqlDPragmaModel.Default);
            var sourceResultsCount = sourceConnection.ExecuteScalar <long>(countSql);

            Assert.That(sourceResultsCount, Is.GreaterThanOrEqualTo(count));
        }
Exemplo n.º 2
0
        private static async Task AssertTargetHasCountMoreThanOrEqualTo(int count = 0)
        {
            var countSql         = typeof(AnyTableB).GetCount();
            var targetConnection = SqlDStart.NewDb().ConnectedTo(WellKnown.Listeners.Free1Listener.DatabaseName, SqlDPragmaModel.Default);
            var targetResults    = await targetConnection.ExecuteScalarAsync <long>(countSql);

            Assert.That(targetResults, Is.GreaterThanOrEqualTo(count));
        }
Exemplo n.º 3
0
        public virtual async Task SetUp()
        {
            Connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);

            var createTable = typeof(AnyTableA).GetCreateTable();
            await Connection.ExecuteCommandAsync(createTable);

            createTable = typeof(AnyTableB).GetCreateTable();
            await Connection.ExecuteCommandAsync(createTable);

            Instance = await InsertAny <T>();
        }
Exemplo n.º 4
0
        public void ConfigureServices(IServiceCollection services)
        {
            var configuration = SqlDConfig.Get(typeof(Startup).Assembly);

            services.AddSingleton(configuration);
            services.AddSingleton(EndPoint.FromUri("http://localhost:5000"));
            services.AddSingleton(x => SqlDStart.NewDb().ConnectedTo("sql-d/ui", "sql-d.ui.db", SqlDPragmaModel.Default));

            services.AddControllersWithViews();

            services.AddOpenApiDocument(settings =>
            {
                settings.DocumentName = "v1";
                settings.Title        = "[ sql-d/ui ]";
                settings.Version      = "1.0.0";
            });
        }
Exemplo n.º 5
0
        public void ConfigureServices(IServiceCollection services)
        {
            var configuration = SqlDConfig.Get(StartAssembly);

            services.AddSingleton(configuration);
            services.AddSingleton(ListenerAddress);
            services.AddSingleton(x => SqlDStart.NewDb().ConnectedTo(DbConnectionName, DbConnectionDbName, PragmaOptions));

            services.AddCors();
            services.AddControllersWithViews().AddNewtonsoftJson();
            services.AddResponseCompression();

            services.AddOpenApiDocument(settings =>
            {
                settings.DocumentName = "v1";
                settings.Title        = "[ sql-d ]";
                settings.Version      = "1.0.0";
            });
        }
Exemplo n.º 6
0
        public void ShouldBeAbleToSustainMultithreadedReadWrites()
        {
            var numberOfIterations = 10000;

            var waitForReads1 = new ManualResetEvent(false);
            var waitForReads2 = new ManualResetEvent(false);
            var waitForReads3 = new ManualResetEvent(false);

            var waitForWrites1 = new ManualResetEvent(false);
            var waitForWrites2 = new ManualResetEvent(false);
            var waitForWrites3 = new ManualResetEvent(false);

            // Writes
            var insertInstance = GenFu.GenFu.New <AnyTableB>();

            var task1 = Task.Factory.StartNew(() =>
            {
                try
                {
                    var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);
                    for (var counter = 0; counter < numberOfIterations; counter++)
                    {
                        connection.Insert(insertInstance);
                        Console.Write("+");
                    }
                }
                finally
                {
                    waitForWrites1.Set();
                }
            });

            var task2 = Task.Factory.StartNew(() =>
            {
                try
                {
                    var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);
                    for (var counter = 0; counter < numberOfIterations; counter++)
                    {
                        connection.Insert(insertInstance);
                        Console.Write("+");
                    }
                }
                finally
                {
                    waitForWrites2.Set();
                }
            });

            var task3 = Task.Factory.StartNew(() =>
            {
                try
                {
                    var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);
                    for (var counter = 0; counter < numberOfIterations; counter++)
                    {
                        connection.Insert(insertInstance);
                        Console.Write("+");
                    }
                }
                finally
                {
                    waitForWrites3.Set();
                }
            });

            // Reads

            var task4 = Task.Factory.StartNew(() =>
            {
                try
                {
                    var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);
                    for (var counter = 0; counter < numberOfIterations; counter++)
                    {
                        var results = connection.Query <AnyTableB>("LIMIT 5");
                        Console.Write(".");
                    }
                }
                finally
                {
                    waitForReads1.Set();
                }
            });

            var task5 = Task.Factory.StartNew(() =>
            {
                try
                {
                    var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);
                    for (var counter = 0; counter < numberOfIterations; counter++)
                    {
                        var results = connection.Query <AnyTableB>("LIMIT 5");
                        Console.Write(".");
                    }
                }
                finally
                {
                    waitForReads2.Set();
                }
            });

            var task6 = Task.Factory.StartNew(() =>
            {
                try
                {
                    var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);
                    for (var counter = 0; counter < numberOfIterations; counter++)
                    {
                        connection.Query <AnyTableB>("LIMIT 5");
                        Console.Write(".");
                    }
                }
                finally
                {
                    waitForReads3.Set();
                }
            });

            waitForReads1.WaitOne();
            waitForReads2.WaitOne();
            waitForReads3.WaitOne();

            waitForWrites1.WaitOne();
            waitForWrites2.WaitOne();
            waitForWrites3.WaitOne();

            Assert.That(task1.IsFaulted, Is.False, $"{task1.Exception?.Message}");
            Assert.That(task2.IsFaulted, Is.False, $"{task2.Exception?.Message}");
            Assert.That(task3.IsFaulted, Is.False, $"{task3.Exception?.Message}");
            Assert.That(task4.IsFaulted, Is.False, $"{task4.Exception?.Message}");
            Assert.That(task5.IsFaulted, Is.False, $"{task5.Exception?.Message}");
            Assert.That(task6.IsFaulted, Is.False, $"{task6.Exception?.Message}");
        }
Exemplo n.º 7
0
        public void OneTimeTearDown()
        {
            var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);

            connection.DropTable <AnyTableB>();
        }
Exemplo n.º 8
0
        public void OneTimeSetUp()
        {
            var connection = SqlDStart.NewDb().ConnectedTo("sql-d.db", SqlDPragmaModel.Default);

            connection.CreateTable <AnyTableB>();
        }