Esempio n. 1
0
        public async Task <IndexDocumentResponse> IndexDocumentAsync(IndexDocumentRequest request)
        {
            string url      = request.GetUrl(_clusterUrl);
            var    response = await SendAsync(url, HttpMethod.Put, request.GetBody());

            return(new IndexDocumentResponse(response));
        }
 public void PASS_IndexDocument_Id()
 {
     tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
     IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document, _Id);
     IndexResponse response = tweetRepo.Index(request);
     Assert.IsNotNull(response);
     Assert.AreEqual(_Id, response.DocumentId);
 }
 public void PASS_IndexDocument_TimeOut_1m()
 {
     tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
     IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document)
     {
         OperationTimeOut = new TimeSpan(0, 1, 0)
     };
     IndexResponse response = tweetRepo.Index(request);
     Assert.IsNotNull(response);
 }
        public void Init()
        {
            tweetRepo = new DocumentRepository<Tweet>(clusterUri, new HttpLayer());
            IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, new Tweet() { Author = "tester", Text = "my test tweet" }, _Id)
            {
                Refresh = true
            };

            tweetRepo.Index(request);
            Thread.Sleep(1000);
        }
 public void FAIL_CreateRequest_Document()
 {
     try
     {
         IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _Type, null);
         Assert.Fail();
     }
     catch (ArgumentNullException ex)
     {
         Assert.AreEqual("document", ex.ParamName);
     }
 }
        public void FAIL_IndexDocument_TimeOut_1ms()
        {
            tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
            IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document)
            {
                OperationTimeOut = new TimeSpan(0, 0, 0, 0, 1)
            };

            try
            {
                IndexResponse response = tweetRepo.Index(request);
            }
            catch (Exception ex)
            {
                //TODO: learn more about this response.
                Assert.Fail();
            }
        }
 public void PASS_IndexDocument_Parent_Fail()
 {
     tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
     IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document, _Id)
     {
         ParentId = "2525"
     };
     try
     {
         IndexResponse response = tweetRepo.Index(request);
         Assert.Fail();
     }
     catch (ElasticRequestException ex)
     {
         Assert.AreEqual(HttpStatusCode.BadRequest, ex.Response.StatusCode);
     }   
 }
 public void PASS_IndexDocument_Consistency_Quorum()
 {
     tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
     IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document, _Id)
     {
         WriteConsistency = WriteConsistencyEnum.QuorumOfShards
     };
     IndexResponse response = tweetRepo.Index(request);
     Assert.IsNotNull(response);
     Assert.AreEqual(_Id, response.DocumentId);
 }
        public void FAIL_IndexDocument_Consistency_All_Timeout()
        {
            tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
            IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document, _Id)
            {
                WriteConsistency = WriteConsistencyEnum.AllShards,
                OperationTimeOut = new TimeSpan(0, 0, 5)
            };

            try
            {
                IndexResponse response = tweetRepo.Index(request);
                Assert.Fail();
            }
            catch (ElasticRequestException ex)
            {
                Assert.AreEqual(HttpStatusCode.ServiceUnavailable, ex.Response.StatusCode);
            }
        }
 public void PASS_IndexDocument_CreateOnly()
 {
     tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
     IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document)
     {
         UseCreateOperationType = true
     };
     IndexResponse response = tweetRepo.Index(request);
     Assert.IsNotNull(response);
 }
 public void PASS_IndexDocument_TimeToLive()
 {
     tweetRepo = new DocumentRepository<Tweet>(_ClusterUri, new HttpLayer());
     IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _DocumentType, _Document, _Id)
     {
         TimeToLive = new Time.TimeValue(new TimeSpan(0, 10, 0))
     };
     IndexResponse response = tweetRepo.Index(request);
     Assert.IsNotNull(response);
     Assert.AreEqual(_Id, response.DocumentId);
 }
 public void PASS_CreateRequest_Id()
 {
     IndexDocumentRequest<Tweet> request = new IndexDocumentRequest<Tweet>(_Index, _Type, _Document, _Id);
     Assert.IsNotNull(request);
 }