예제 #1
0
        async Task <Realms.Realm> GenerateRealmDB(string path)
        {
            path = path ?? IntegrationTestHelper.GetIntegrationTestRootDirectory();

            var giantDbSize = PerfHelper.GetPerfRanges().Last();
            var config      = new RealmConfiguration(Path.Combine(path, "realm.db"))
            {
                ObjectClasses = new Type[] { typeof(KeyValueRecord) },
                ReadOnly      = false
            };
            var cache = Realms.Realm.GetInstance(config);

            var keys = cache.All <KeyValueRecord>().Count();

            if (keys == giantDbSize)
            {
                return(cache);
            }

            await cache.WriteAsync(r =>
            {
                r.RemoveAll();
            });

            await GenerateRealmDB(cache, giantDbSize);

            return(cache);
        }
예제 #2
0
        protected async Task GeneratePerfRangesForRealm(Func <Realms.Realm, int, Task <long> > block)
        {
            results = new Dictionary <int, long>();
            dbName  = default(string);

            var dirPath = default(string);

            using (Utility.WithEmptyDirectory(out dirPath))
                using (var cache = RealmThread.GetInstance(Path.Combine(dirPath, "realm.db")))
                {
                    using (var realmThread = new RealmThread(cache.Config))
                    {
                        realmThread.Invoke((obj) =>
                        {
                            obj.Write(() => { obj.RemoveAll(); });
                        });
                    }
                    dbName = "Realm";

                    foreach (var size in PerfHelper.GetPerfRanges())
                    {
                        results[size] = await block(cache, size);
                    }
                }
        }
예제 #3
0
        public async Task GeneratePerfRangesForBlock2(Func <Realms.Realm, int, List <string>, Task <long> > block)
        {
            results = new Dictionary <int, long>();
            dbName  = default(string);

            var dirPath = default(string);

            using (Utility.WithEmptyDirectory(out dirPath))
                using (var cache = await GenerateRealmDB(dirPath))
                {
                    List <string> keys = null;
                    using (var realmThread = new RealmThread(cache.Config))
                    {
                        realmThread.Invoke((r) =>
                        {
                            r.Write(() => {
                                keys = r.All <KeyValueRecord>().ToList().Select(x => x.Key).ToList();
                            });
                        });
                    }
                    dbName = dbName ?? cache.GetType().Name;

                    foreach (var size in PerfHelper.GetPerfRanges())
                    {
                        results[size] = await block(cache, size, keys.ToList());
                    }
                }
        }
예제 #4
0
        async Task <Realms.Realm> GenerateRealmDB(string path)
        {
            path = path ?? IntegrationTestHelper.GetIntegrationTestRootDirectory();

            var giantDbSize = PerfHelper.GetPerfRanges().Last();

            var config = new RealmConfiguration(Path.Combine(path, "perf.realm"))
            {
                ObjectClasses = new Type[] { typeof(KeyValueRecord) },
                IsReadOnly    = false
            };

            var cache = RealmThread.GetInstance(config);

            var keys = cache.All <KeyValueRecord>().Count();

            if (keys == giantDbSize)
            {
                return(cache);
            }

            using (var realmThread = new RealmThread(cache.Config))
            {
                realmThread.Invoke((obj) =>
                {
                    obj.Write(() => { obj.RemoveAll(); });
                });
            }

            await GenerateRealmDB(cache, giantDbSize);

            return(cache);
        }
예제 #5
0
        protected async Task GeneratePerfRangesForRealm(Func <Realms.Realm, int, Task <long> > block)
        {
            results = new Dictionary <int, long>();
            dbName  = default(string);
            var dirPath = default(string);

            using (Utility.WithEmptyDirectory(out dirPath))
                using (var cache = RealmThread.GetInstance(Path.Combine(dirPath, "perf.realm")))
                {
                    dbName = "Realm";

                    foreach (var size in PerfHelper.GetPerfRanges())
                    {
                        results[size] = await block(cache, size);
                    }
                }
        }
예제 #6
0
        public async Task GeneratePerfRangesForBlock2(Func <Realms.Realm, int, List <string>, Task <long> > block)
        {
            results = new Dictionary <int, long>();
            dbName  = default(string);

            var dirPath = default(string);

            using (Utility.WithEmptyDirectory(out dirPath))
                using (var cache = await GenerateRealmDB(dirPath))
                {
                    List <string> keys = null;
                    await cache.WriteAsync(r =>             // This is just a cheap way to avoid "Realm accessed from incorrect thread"
                    {
                        keys = r.All <KeyValueRecord>().ToList().Select(x => x.Key).ToList();
                    });

                    dbName = dbName ?? cache.GetType().Name;

                    foreach (var size in PerfHelper.GetPerfRanges())
                    {
                        results[size] = await block(cache, size, keys.ToList());
                    }
                }
        }