public async Task Manage_OneTrans_BeginInvoke()
        {
            await GeneratePerfRangesForRealm(async (cache, size) =>
            {
                var toWrite = PerfHelper.GenerateRandomDatabaseContents(size);

                var st = new Stopwatch();
                st.Start();

                await Task.Run(() =>
                {
                    using (var realmThread = new RealmThread(cache.Config))
                    {
                        realmThread.BeginTransaction();
                        realmThread.BeginInvoke((threadSafeRealm) =>
                        {
                            foreach (var kvp in toWrite)
                            {
                                var obj   = new KeyValueRecord();
                                obj.Key   = kvp.Key;
                                obj.Value = kvp.Value;
                                threadSafeRealm.Add(obj);
                            }
                        });
                        realmThread.CommitTransaction();
                    }
                });

                st.Stop();
                return(st.ElapsedMilliseconds);
            });
        }
Example #2
0
        public void ThreadInvoke_InTransaction_AutoCommit()
        {
            string path;

            using (Utility.WithEmptyDirectory(out path))
                using (var fixture = CreateRealmsInstance(path))
                {
                    using (var realmThread = new RealmThread(fixture.Config, true))
                    {
                        realmThread.BeginTransaction();
                        var keyValueRecord = new KeyValueRecord();                 // a captured variable
                        realmThread.Invoke(r =>
                        {
                            var obj = new KeyValueRecord();
                            obj.Key = "key";
                            r.Add(obj);
                            keyValueRecord.Key = obj.Key;
                        });
                        Console.WriteLine($"{keyValueRecord.Key}:{keyValueRecord.Value}");
                        Assert.Equal("key", keyValueRecord.Key);
                    }
                    fixture.Refresh();
                    Assert.NotNull(fixture.Find <KeyValueRecord>("key"));
                }
        }
Example #3
0
        public void ThreadInvoke_InTransaction()
        {
            string path;

            using (Utility.WithEmptyDirectory(out path))
                using (var fixture = CreateRealmsInstance(path))
                    using (var t = new RealmThread(fixture.Config))
                    {
                        Assert.False(t.InTransaction);
                        t.BeginTransaction();
                        Assert.True(t.InTransaction);
                    }
        }
Example #4
0
        public void ThreadInvoke_InTransaction_AutoRollback()
        {
            string path;

            using (Utility.WithEmptyDirectory(out path))
                using (var fixture = CreateRealmsInstance(path))
                {
                    using (var t = new RealmThread(fixture.Config, false))
                    {
                        t.BeginTransaction();
                        t.Invoke(r =>
                        {
                            var obj = r.CreateObject <KeyValueRecord>();
                            obj.Key = "key";
                        });
                    }
                    fixture.Refresh();
                    Assert.Null(fixture.ObjectForPrimaryKey <KeyValueRecord>("key"));
                }
        }
Example #5
0
        public void ThreadInvoke_Transaction_Begin_RollBack()
        {
            string path;

            using (Utility.WithEmptyDirectory(out path))
                using (var fixture = CreateRealmsInstance(path))
                    using (var t = new RealmThread(fixture.Config))
                    {
                        t.BeginTransaction();
                        t.Invoke(r =>
                        {
                            var obj = r.CreateObject <KeyValueRecord>();
                            obj.Key = "key";
                        });
                        fixture.Refresh();
                        Assert.Null(fixture.ObjectForPrimaryKey <KeyValueRecord>("key"));        // Should not be available yet
                        t.RollbackTransaction();
                        fixture.Refresh();
                        Assert.Null(fixture.ObjectForPrimaryKey <KeyValueRecord>("key"));        // Should not be available
                    }
        }
Example #6
0
        public void ThreadInvoke_Transaction_Begin_Commit()
        {
            string path;

            using (Utility.WithEmptyDirectory(out path))
                using (var fixture = CreateRealmsInstance(path))
                    using (var t = new RealmThread(fixture.Config))
                    {
                        t.BeginTransaction();
                        t.Invoke(r =>
                        {
                            var obj = new KeyValueRecord();
                            obj.Key = "key";
                            r.Add(obj);
                        });
                        fixture.Refresh();
                        Assert.Null(fixture.Find <KeyValueRecord>("key"));        // Should not be available yet
                        t.CommitTransaction();
                        fixture.Refresh();
                        Assert.NotNull(fixture.Find <KeyValueRecord>("key"));        // Should now be available
                    }
        }