Пример #1
0
        private IList <long>[] GenerateValuesInMultipleThreads(int poolSize, int threadCount, int valueCount)
        {
            const int blockSize = 10;

            var serviceProvider = SqlServerTestHelpers.Instance.CreateServiceProvider();
            var state           = new SqlServerSequenceValueGeneratorState("Foo", blockSize, poolSize);
            var executor        = new FakeSqlStatementExecutor(blockSize);
            var sqlGenerator    = new SqlServerUpdateSqlGenerator();

            var tests           = new Action[threadCount];
            var generatedValues = new List <long> [threadCount];

            for (var i = 0; i < tests.Length; i++)
            {
                var testNumber = i;
                generatedValues[testNumber] = new List <long>();
                tests[testNumber]           = () =>
                {
                    for (var j = 0; j < valueCount; j++)
                    {
                        var connection = CreateConnection(serviceProvider);
                        var generator  = new SqlServerSequenceValueGenerator <long>(executor, sqlGenerator, state, connection);

                        generatedValues[testNumber].Add(generator.Next());
                    }
                };
            }

            Parallel.Invoke(tests);

            return(generatedValues);
        }
        private async Task <IEnumerable <List <long> > > GenerateValuesInMultipleThreads(int threadCount, int valueCount)
        {
            const int blockSize = 10;

            var serviceProvider = SqlServerTestHelpers.Instance.CreateServiceProvider();

            var sequence = ((IMutableModel) new Model()).AddSequence("Foo");

            sequence.IncrementBy = blockSize;
            var state = new SqlServerSequenceValueGeneratorState(sequence);

            var executor     = new FakeRawSqlCommandBuilder(blockSize);
            var sqlGenerator = new SqlServerUpdateSqlGenerator(
                new UpdateSqlGeneratorDependencies(
                    new SqlServerSqlGenerationHelper(
                        new RelationalSqlGenerationHelperDependencies()),
                    new SqlServerTypeMappingSource(
                        TestServiceFactory.Instance.Create <TypeMappingSourceDependencies>(),
                        TestServiceFactory.Instance.Create <RelationalTypeMappingSourceDependencies>())));

            var logger = new FakeDiagnosticsLogger <DbLoggerCategory.Database.Command>();

            var tests           = new Func <Task> [threadCount];
            var generatedValues = new List <long> [threadCount];

            for (var i = 0; i < tests.Length; i++)
            {
                var testNumber = i;
                generatedValues[testNumber] = new List <long>();
                tests[testNumber]           = async() =>
                {
                    for (var j = 0; j < valueCount; j++)
                    {
                        var connection = CreateConnection(serviceProvider);
                        var generator  = new SqlServerSequenceHiLoValueGenerator <long>(executor, sqlGenerator, state, connection, logger);

                        var value = j % 2 == 0
                            ? await generator.NextAsync(null)
                            : generator.Next(null);

                        generatedValues[testNumber].Add(value);
                    }
                };
            }

            var tasks = tests.Select(Task.Run).ToArray();

            foreach (var t in tasks)
            {
                await t;
            }

            return(generatedValues);
        }
Пример #3
0
        private async Task <IEnumerable <List <long> > > GenerateValuesInMultipleThreads(int threadCount, int valueCount)
        {
            const int blockSize = 10;

            var serviceProvider = SqlServerTestHelpers.Instance.CreateServiceProvider();

            var sequence = Sequence.GetOrAddSequence(new Model(), RelationalFullAnnotationNames.Instance.SequencePrefix, "Foo");

            sequence.IncrementBy = blockSize;
            var state = new SqlServerSequenceValueGeneratorState(sequence);

            var executor     = new FakeRawSqlCommandBuilder(blockSize);
            var sqlGenerator = new SqlServerUpdateSqlGenerator(new SqlServerSqlGenerationHelper(), new SqlServerTypeMapper());

            var tests           = new Func <Task> [threadCount];
            var generatedValues = new List <long> [threadCount];

            for (var i = 0; i < tests.Length; i++)
            {
                var testNumber = i;
                generatedValues[testNumber] = new List <long>();
                tests[testNumber]           = async() =>
                {
                    for (var j = 0; j < valueCount; j++)
                    {
                        var connection = CreateConnection(serviceProvider);
                        var generator  = new SqlServerSequenceHiLoValueGenerator <long>(executor, sqlGenerator, state, connection);

                        var value = j % 2 == 0
                                ? await generator.NextAsync(null)
                                : generator.Next(null);

                        generatedValues[testNumber].Add(value);
                    }
                };
            }

            var tasks = tests.Select(Task.Run).ToArray();

            foreach (var t in tasks)
            {
                await t;
            }

            return(generatedValues);
        }
Пример #4
0
        private IEnumerable <List <long> > GenerateValuesInMultipleThreads(int threadCount, int valueCount)
        {
            const int blockSize = 10;

            var serviceProvider = SqlServerTestHelpers.Instance.CreateServiceProvider();

            var state = new SqlServerSequenceValueGeneratorState(
                new Sequence(
                    new Model(), RelationalAnnotationNames.Prefix, "Foo")
            {
                IncrementBy = blockSize
            });

            var executor     = new FakeSqlStatementExecutor(blockSize);
            var sqlGenerator = new SqlServerUpdateSqlGenerator(new SqlServerSqlGenerator());

            var tests           = new Action[threadCount];
            var generatedValues = new List <long> [threadCount];

            for (var i = 0; i < tests.Length; i++)
            {
                var testNumber = i;
                generatedValues[testNumber] = new List <long>();
                tests[testNumber]           = () =>
                {
                    for (var j = 0; j < valueCount; j++)
                    {
                        var connection = CreateConnection(serviceProvider);
                        var generator  = new SqlServerSequenceHiLoValueGenerator <long>(executor, sqlGenerator, state, connection);

                        generatedValues[testNumber].Add(generator.Next());
                    }
                };
            }

            Parallel.Invoke(tests);

            return(generatedValues);
        }
        private static IHistoryRepository CreateHistoryRepository()
        {
            var annotationsProvider = new SqlServerMetadataExtensionProvider();
            var updateSqlGenerator  = new SqlServerUpdateSqlGenerator();

            return(new SqlServerHistoryRepository(
                       Mock.Of <IRelationalDatabaseCreator>(),
                       Mock.Of <ISqlStatementExecutor>(),
                       Mock.Of <ISqlServerConnection>(),
                       new DbContextOptions <DbContext>(
                           new Dictionary <Type, IDbContextOptionsExtension>
            {
                { typeof(SqlServerOptionsExtension), new SqlServerOptionsExtension() }
            }),
                       new MigrationsModelDiffer(
                           annotationsProvider,
                           new SqlServerMigrationsAnnotationProvider()),
                       new SqlServerMigrationsSqlGenerator(
                           updateSqlGenerator,
                           new SqlServerTypeMapper(),
                           annotationsProvider),
                       annotationsProvider,
                       updateSqlGenerator));
        }
        private static IHistoryRepository CreateHistoryRepository()
        {
            var annotationsProvider = new SqlServerMetadataExtensionProvider();
            var updateSqlGenerator = new SqlServerUpdateSqlGenerator();

            return new SqlServerHistoryRepository(
                Mock.Of<IRelationalDatabaseCreator>(),
                Mock.Of<ISqlStatementExecutor>(),
                Mock.Of<ISqlServerConnection>(),
                new DbContextOptions<DbContext>(
                    new Dictionary<Type, IDbContextOptionsExtension>
                    {
                        { typeof(SqlServerOptionsExtension), new SqlServerOptionsExtension() }
                    }),
                new MigrationsModelDiffer(
                    annotationsProvider,
                    new SqlServerMigrationsAnnotationProvider()),
                new SqlServerMigrationsSqlGenerator(
                    updateSqlGenerator,
                    new SqlServerTypeMapper(),
                    annotationsProvider),
                annotationsProvider,
                updateSqlGenerator);
        }