示例#1
0
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddControllers(config =>
            {
                config.RespectBrowserAcceptHeader = true;
                config.ReturnHttpNotAcceptable    = true;
            }).AddJsonOptions(options =>
            {
                options.JsonSerializerOptions.Converters.Add(new JsonPrimitiveConverter());
                options.JsonSerializerOptions.Converters.Add(new JsonKeyValueConverter());
                options.JsonSerializerOptions.Converters.Add(new JsonNodeConverter());
                options.JsonSerializerOptions.Converters.Add(new JsonNodeIdConverter());
                options.JsonSerializerOptions.Converters.Add(new JsonMapConverter());
            })
            .AddMvcOptions(c =>
            {
                c.OutputFormatters.Add(new NodeOutputFormatter());
            });



            var startIt = new GrpcFileStore(new Config(
                                                1,
                                                log => Console.WriteLine(log),
                                                new DirectoryInfo(Assembly.GetEntryAssembly().Location).Parent,
                                                AppMetrics.CreateDefaultBuilder().Build()));

            services.AddSingleton <ISessionProvider>(provider => startIt);
            services.AddResponseCompression();
        }
示例#2
0
        public async void CanShutdownAndRecover()
        {
            var         config       = TestConfig();
            var         firstWritten = false;
            var         cts          = new CancellationTokenSource();
            List <Node> nodes        = new();
            var         time         = Stopwatch.StartNew();

            config.Log("Starting");
            using (var g = new GrpcFileStore(config))
            {
                config.Log($"Started {time.ElapsedMilliseconds}ms");
                time.Restart();
                config.Log($"Loading ");
                using (var s = g.Session())
                {
                    var node = new Node
                    {
                        Id         = Utils.Id(new Uri($"ekati:foo/{10.ToString()}")),
                        Attributes = new Map {
                            Items = new List <KeyValue> {
                                Utils.Prop(DateTime.UtcNow.Ticks, FileTypes.TypeFile, Attr.Type)
                            }
                        }
                    };
                    await s.Upsert(node);

                    nodes.Add(node);
                }
                config.Log($"Done loading {time.ElapsedMilliseconds}ms");
                time.Restart();
                config.Log($"Shutting down");
            }
            config.Log($"Shut down {time.ElapsedMilliseconds}ms");

            time.Restart();
            cts.Cancel();
            config.Log("Reading");
            using (var g = new GrpcFileStore(config))
            {
                using (var s = g.Session())
                {
                    foreach (var vNode in nodes)
                    {
                        var node = await s.Read(vNode.Id);

                        Assert.NotNull(node);
                    }
                }
            }
            config.Log($"Done Reading {time.ElapsedMilliseconds}ms");
        }
示例#3
0
        private static async Task NoReferencesPlz(CancellationTokenSource cts, Config config)
        {
            using (var g = new GrpcFileStore(config))
            {
                var nowTicks = DateTime.Now.Ticks;
                using (var s = g.Session())
                {
                    await s.Upsert(new Node
                    {
                        Id = new NodeID {
                            Iri = "wat"
                        },
                        Attributes = new Map
                        {
                            Items = new[]
                            {
                                Utils.PropString("hi", "there", nowTicks),
                                Utils.PropString("hii", "theree", nowTicks),
                                Utils.PropString("hiii", "thereee", nowTicks),
                                Utils.PropString("hiiii", "thereeee", nowTicks),
                                Utils.PropData("someMap", new Map()
                                {
                                    Items = new[]
                                    {
                                        Utils.PropString("m1", "v1", nowTicks),
                                        Utils.PropString("m2", "v2", nowTicks),
                                        Utils.PropData("m3", new Ekati.Core.Array()
                                        {
                                            Items = new Primitive[]
                                            {
                                                3.123f,
                                                3,
                                                3L,
                                            }
                                        }, nowTicks),
                                    }
                                }, nowTicks)
                            }
                        }
                    });

                    var found = await s.Read(new[] { Utils.Id("wat") }).FirstOrDefaultAsync();

                    Assert.NotNull(found);
                    config.Log("Closing Session");
                }

                config.Log("Closing Database");
            }
        }
示例#4
0
文件: UnitTest1.cs 项目: Astn/ekati
        public async void CanSentAndGet()
        {
            var config       = TestConfig();
            var firstWritten = false;

            using var g = new GrpcFileStore(config);
            var nowTicks = DateTime.Now.Ticks;

            using (var s = g.Session())
            {
                await s.Upsert(new Node
                {
                    Id = new NodeID {
                        Iri = "wat"
                    },
                    Attributes = new Map
                    {
                        Items = new[]
                        {
                            Utils.PropString("hi", "there", nowTicks),
                            Utils.PropString("hii", "theree", nowTicks),
                            Utils.PropString("hiii", "thereee", nowTicks),
                            Utils.PropString("hiiii", "thereeee", nowTicks),
                            Utils.PropData("someMap", new Map()
                            {
                                Items = new []
                                {
                                    Utils.PropString("m1", "v1", nowTicks),
                                    Utils.PropString("m2", "v2", nowTicks),
                                    Utils.PropData("m3", new Ekati.Core.Array()
                                    {
                                        Items = new Primitive[]
                                        {
                                            3.123f,
                                            3,
                                            3L,
                                        }
                                    }, nowTicks),
                                }
                            }, nowTicks)
                        }
                    }
                });

                var found = await s.Read(new[] { Utils.Id("wat") }).FirstOrDefaultAsync();

                Assert.NotNull(found);
            }
        }
示例#5
0
        public async void CanShutdownAndRecoverWithLotsOfRandomData()
        {
            var         config       = TestConfig();
            var         firstWritten = false;
            var         cts          = new CancellationTokenSource();
            List <Node> nodes        = new();
            var         time         = Stopwatch.StartNew();

            config.Log("Loading");
            using (var g = new GrpcFileStore(config))
            {
                using (var s = g.Session())
                {
                    var data = Enumerable.Range(0, 10000).Select(i => Utils.Id(new Uri($"ekati:/testfiles/{i.ToString()}")))
                               .Select(id => new Node {
                        Id = id, Attributes = new Map {
                            Items = new List <KeyValue> {
                                Utils.Prop(DateTime.UtcNow.Ticks, FileTypes.TypeFile, Attr.Type)
                            }
                        }
                    });
                    foreach (var node1 in data)
                    {
                        await s.Upsert(node1);

                        nodes.Add(node1);
                    }
                }
            }

            config.Log($"Done loading {time.ElapsedMilliseconds}ms");
            time.Restart();
            cts.Cancel();
            config.Log("Reading");
            using (var g = new GrpcFileStore(config))
            {
                using (var s = g.Session())
                {
                    foreach (var vNode in nodes)
                    {
                        var node = await s.Read(vNode.Id);

                        Assert.NotNull(node);
                    }
                }
            }
            config.Log($"Done Reading {time.ElapsedMilliseconds}ms");
        }
示例#6
0
 public BrightStarDataProvider(GrpcFileStore fileStore)
 {
     _databaseSession = fileStore.Session();
 }