示例#1
0
        public void SingleSchema_NoRelations()
        {
            var indexName        = _fixture.Create <string>();
            var objectData       = _fixture.Create <Person>();
            var objectId         = _fixture.Create <string>();
            var schemaDefinition = JsonSchema.FromType(typeof(Person)).ToJson();

            var schemaId           = _schemaRegistryService.AddSchema("test_schema", schemaDefinition, SchemaType.Types.Type.DocumentStorage).Result;
            var materializerFields = new Dictionary <string, object>();

            materializerFields.Add("firstName", new SimpleFiled
            {
                simple = new SimpleItem
                {
                    field_name = "firstName",
                    field_type = "string"
                }
            });
            _schemaRegistryService.AddViewToSchema(schemaId.Id_, "test_view", materializerFields, new List <Relation>(), $"{{ \"index_name\": \"{indexName}\" }}", MaterializerBackend.ElasticSearch);
            _kafkaProducer.Produce(new InsertObject
            {
                objectId = objectId,
                schemaId = schemaId.Id_,
                data     = objectData
            });
            var result = RetryHelper.TryFetch(() => ElasticsearchConnector.QueryAll <PersonView1>(new Uri(_options.CDL_ELASTICSEARCH_NODE), indexName), arr => arr.Count == 0).Result.ToArray();

            Assert.Single(result);
            Assert.Equal(objectData.FirstName, result[0].FirstName);
        }
        public async void MaterializerOnDemand()
        {
            var name       = _fixture.Create <string>();
            var objectId_a = Guid.NewGuid().ToString();
            var payload_a  = _fixture.Create <Person>();
            var viewName   = _fixture.Create <string>();
            var schema_a   = _schemaRegistryService.AddSchema(
                name,
                _fixture.Create <GeneralObject>().ToJSONString(),
                SchemaType.Types.Type.DocumentStorage).Result;
            var viewFields      = new Dictionary <string, object>();
            var relation        = _edgeRegistryService.AddRelation(schema_a.Id_, schema_a.Id_).Result;
            var relationForView = new List <Relation>();

            relationForView.Add(new Relation()
            {
                GlobalId  = relation.RelationId_,
                LocalId   = _fixture.Create <UInt32>(),
                SearchFor = new SearchFor()
                {
                    SearchFor_ = SearchFor.Types.Direction.Children,
                }
            });

            viewFields.Add("firstName", new SimpleFiled()
            {
                simple = new SimpleItem()
                {
                    field_name = "firstName",
                    field_type = "String"
                }
            });
            viewFields.Add("lastName", new SimpleFiled()
            {
                simple = new SimpleItem()
                {
                    field_name = "lastName",
                    field_type = "String"
                }
            });
            var view           = _schemaRegistryService.AddViewToSchema(schema_a.Id_, viewName, viewFields, new List <Relation>()).Result;
            var viewDetails    = _schemaRegistryService.GetView(view.Id_).Result;
            var schemaWithView = _schemaRegistryService.GetFullSchema(schema_a.Id_).Result;

            Assert.True(schemaWithView.Views.Count == 1);

            _kafkaProducer.Produce(new InsertObject()
            {
                schemaId = schema_a.Id_,
                objectId = objectId_a,
                data     = payload_a
            }).Wait();
            Thread.Sleep(1000);

            var res = _onDemandMaterializerService.Materialize(view.Id_, new List <string>()
            {
                schema_a.Id_
            });

            //should have only one row
            while (await res.ResponseStream.MoveNext())
            {
                Assert.True(res.ResponseStream.Current.Fields.Count == 2);
                Assert.Contains(payload_a.FirstName, res.ResponseStream.Current.Fields["firstName"]);
                Assert.Contains(payload_a.LastName, res.ResponseStream.Current.Fields["lastName"]);
            }
        }
        public void AddRelation()
        {
            var parentName   = _fixture.Create <string>();
            var childName    = _fixture.Create <string>();
            var parentSchema = _schemaRegistryService.AddSchema(
                parentName,
                _fixture.Create <Person>().ToJSONString(),
                SchemaType.Types.Type.DocumentStorage).Result;
            var childSchema = _schemaRegistryService.AddSchema(
                childName,
                _fixture.Create <Car>().ToJSONString(),
                SchemaType.Types.Type.DocumentStorage).Result;
            var results = _edgeRegistryService.AddRelation(childSchema.Id_, parentSchema.Id_).Result;

            Assert.True(results.HasRelationId_);
            Guid.Parse(results.RelationId_);
        }
        public void AddSchema(string schemaName)
        {
            var schema = _schemaRegistryService.AddSchema(
                schemaName,
                _fixture.Create <GeneralObject>().ToJSONString(),
                SchemaType.Types.Type.DocumentStorage).Result;

            Assert.NotNull(schema);
            Assert.IsType <string>(schema.Id_);
            Guid.Parse(schema.Id_);
        }