Пример #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 void CheckViewAddedToSchema()
        {
            var name     = _fixture.Create <string>();
            var viewName = _fixture.Create <string>();
            var schema   = _schemaRegistryService.AddSchema(
                name,
                _fixture.Create <Person>().ToJSONString(),
                SchemaType.Types.Type.DocumentStorage).Result;
            var viewFields = new Dictionary <string, object>();

            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.Id_, viewName, viewFields, new List <Relation>()).Result;
            var viewDetails = _schemaRegistryService.GetView(view.Id_).Result;

            Assert.NotNull(view.Id_);
            Assert.IsType <string>(view.Id_);
            Assert.NotNull(viewDetails);
            Assert.IsType <FullView>(viewDetails);
            var viewUUID = Guid.Parse(view.Id_);

            var schemaWithView = _schemaRegistryService.GetFullSchema(schema.Id_).Result;

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

            var viewObject = schemaWithView.Views[0];

            Assert.Equal(viewName, viewObject.Name);
            Assert.IsType <string>(viewObject.Id);
            Assert.NotEqual("{\"Name\": \"Name\" }", viewObject.MaterializerOptions);
            Assert.NotNull(viewDetails);
            Assert.IsType <FullView>(viewDetails);
        }
        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"]);
            }
        }