public void RunTransaction_isolationLevel()
        {
            var db1 = RootServiceProvider.GetService <IShardingDbAccessor>();
            var db2 = RootServiceProvider.CreateScope().ServiceProvider.GetService <IShardingDbAccessor>();

            db1.Insert(_newData);

            var  updateData = _newData.DeepClone();
            Task db2Task    = new Task(() =>
            {
                updateData.UserName = Guid.NewGuid().ToString();
                db2.Update(updateData);
            });

            var res = db1.RunTransaction(() =>
            {
                //db1读=>db2写(阻塞)=>db1读=>db1提交
                var db1Data_1 = db1.GetIShardingQueryable <Base_UnitTest>().Where(x => x.Id == _newData.Id).FirstOrDefault();

                db2Task.Start();

                var db1Data_2 = db1.GetIShardingQueryable <Base_UnitTest>().Where(x => x.Id == _newData.Id).FirstOrDefault();
                Assert.AreEqual(db1Data_1.ToJson(), db1Data_2.ToJson());
            });

            db2Task.Wait();
            var db1Data_3 = db1.GetIShardingQueryable <Base_UnitTest>().Where(x => x.Id == _newData.Id).FirstOrDefault();

            Assert.AreEqual(updateData.ToJson(), db1Data_3.ToJson());
        }
Exemple #2
0
 protected override void Configure()
 {
     scope     = RootServiceProvider.CreateScope();
     jobServer = new BackgroundJobServer(
         new BackgroundJobServerOptions(),
         scope.ServiceProvider.GetRequiredService <JobStorage>());
 }
Exemple #3
0
 public void Dispose()
 {
     using (var scop = RootServiceProvider.CreateScope())
     {
         scop.ServiceProvider.GetService <IDbAccessor>().Dispose();
         scop.ServiceProvider.GetService <ICustomDbAccessor>().Dispose();
     }
 }
Exemple #4
0
        protected IntegratedTest()
        {
            var services     = new ServiceCollection();
            var bootstrapper = CreateBootstrapper(services);

            Bootstrapper        = bootstrapper;
            RootServiceProvider = CreateServiceProvider(bootstrapper);
            TestServiceScope    = RootServiceProvider.CreateScope();
            bootstrapper.SetServiceProvider(TestServiceScope.ServiceProvider);
            bootstrapper.Initialize();
        }
Exemple #5
0
        protected IntegratedTest()
        {
            var services = CreateServiceCollection();

            BeforeAddApplication(services);
            var application = services.AddApplication <TStartupModule>();

            Application = services.GetBuildService <IModuleApplication>();
            AfterAddApplication(services);
            RootServiceProvider = CreateServiceProvider(services);
            TestServiceScope    = RootServiceProvider.CreateScope();
            ((StartupModuleRunner)Application).Initialize(TestServiceScope.ServiceProvider);
        }
Exemple #6
0
        public void Tracking()
        {
            using var scop = RootServiceProvider.CreateScope();
            var db = scop.ServiceProvider.GetService <IDbAccessor>();

            db.Insert(_insertList);

            var data = db.GetIQueryable <Base_UnitTest>(true).FirstOrDefault();

            data.Age = 10000;
            db.SaveChanges();

            var newData = db.GetIQueryable <Base_UnitTest>(true).FirstOrDefault();

            Assert.AreEqual(data.ToJson(), newData.ToJson());
        }
Exemple #7
0
        protected AbpIntegratedTest()
        {
            var services = CreateServiceCollection();

            BeforeAddApplication(services);

            var application = services.AddApplication <TStartupModule>(SetAbpApplicationCreationOptions);

            Application = application;

            AfterAddApplication(services);

            RootServiceProvider = CreateServiceProvider(services);
            TestServiceScope    = RootServiceProvider.CreateScope();

            application.Initialize(TestServiceScope.ServiceProvider);
        }
Exemple #8
0
        protected IntegratedTest()
        {
            var services = CreateServiceCollection();

            BeforeAddBootstrapper(services);

            var bootstrapper = new InternalBootstrapper(typeof(TStartupModule), services, null, SetBootstrapperCreationOptions);

            Bootstrapper = bootstrapper;

            AfterAddBootstrapper(services);

            RootServiceProvider = CreateServiceProvider(services);
            TestServiceScope    = RootServiceProvider.CreateScope();
            bootstrapper.SetServiceProvider(TestServiceScope.ServiceProvider);
            bootstrapper.Initialize();
        }
    public virtual async Task InitializeAsync()
    {
        var services = await CreateServiceCollectionAsync();

        await BeforeAddApplicationAsync(services);

        var application = await services.AddApplicationAsync <TStartupModule>(await SetAbpApplicationCreationOptionsAsync());

        await AfterAddApplicationAsync(services);

        RootServiceProvider = await CreateServiceProviderAsync(services);

        TestServiceScope = RootServiceProvider.CreateScope();
        await application.InitializeAsync(TestServiceScope.ServiceProvider);

        ServiceProvider = application.ServiceProvider;
        Application     = application;

        await InitializeServicesAsync();
    }
Exemple #10
0
 protected BaseTest()
 {
     CurrentServiceScope    = RootServiceProvider.CreateScope();
     CurrentServiceProvider = CurrentServiceScope.ServiceProvider;
 }
Exemple #11
0
 public IServiceProvider CreateScopedServiceProvider()
 {
     return(RootServiceProvider.CreateScope().ServiceProvider);
 }
 protected BaseTest()
 {
     ServiceScope    = RootServiceProvider.CreateScope();
     ServiceProvider = ServiceScope.ServiceProvider;
 }