Exemplo n.º 1
0
        public void TestIndexTimeout()
        {
            var timeout = 1;
            var s = new ConnectionSettings(Test.Default.Host, Test.Default.Port, timeout)
                        .SetDefaultIndex(Test.Default.DefaultIndex)
                        .SetMaximumAsyncConnections(Test.Default.MaximumAsyncConnections)
                        .UsePrettyResponses();

            var client = new ElasticClient(s);

            var newProject = new ElasticSearchProject
            {
                Name = "COBOLES", //COBOL ES client ?
            };
            var t = client.IndexAsync<ElasticSearchProject>(newProject);
            t.Wait(1000);
            var cs = t.Result;
            Assert.False(cs.Success);
            Assert.NotNull(cs.Error);
            Assert.NotNull(cs.Error.OriginalException);
            Trace.WriteLine(cs.Error.OriginalException);
            Assert.IsNotNullOrEmpty(cs.Error.ExceptionMessage);
            Assert.IsTrue(cs.Error.OriginalException is WebException);
            var we = cs.Error.OriginalException as WebException;
            Assert.IsTrue(cs.Error.ExceptionMessage.Contains("The request was canceled"));
            Assert.IsTrue(we.Status == WebExceptionStatus.RequestCanceled);
            Assert.True(t.IsCompleted, "task did not complete");
            Assert.False(t.IsFaulted, "task was faulted, wich means the exception did not cleanly pass to ConnectionStatus");
        }
Exemplo n.º 2
0
        public void IndexThanDeleteDocumentById()
        {
            //arrange
            //create a new document to index
            ElasticSearchProject newDocument = new ElasticSearchProject
            {
                Country = "Mozambique",
                Followers = new List<Person>(),
                Id = DateTime.Now.Millisecond + 1500, //try to get this example out of the way of existing test data
                Name = "Test Document for 'IndexDocument' test"
            };

            //act
            //index the new item
            this.ConnectedClient.Index<ElasticSearchProject>(newDocument, new IndexParameters { Refresh = true });

            //assert
            //grab document back from the index and make sure it is the same document
            var foundDocument = this.ConnectedClient.Get<ElasticSearchProject>(newDocument.Id);

            //Assert.Equal(newDocument.Country, foundDocument.Country);
            Assert.AreEqual(newDocument.Followers.Count, foundDocument.Followers.Count);
            Assert.AreEqual(newDocument.Id, foundDocument.Id);
            Assert.AreEqual(newDocument.Name, foundDocument.Name);

            //act
            //now remove the item that was added
            this.ConnectedClient.DeleteById<ElasticSearchProject>(newDocument.Id, new DeleteParameters { Refresh = true });

            //assert
            //make sure getting by id returns nothing
            foundDocument = this.ConnectedClient.Get<ElasticSearchProject>(newDocument.Id);
            Assert.Null(foundDocument);
        }
Exemplo n.º 3
0
 public void TestIndex()
 {
     var newProject = new ElasticSearchProject
     {
         Name = "COBOLES", //COBOL ES client ?
     };
     var t = this.ConnectedClient.IndexAsync<ElasticSearchProject>(newProject);
     t.Wait();
     Assert.True(t.Result.Success);
     Assert.True(t.IsCompleted, "task did not complete");
     Assert.True(t.IsCompleted, "task did not complete");
 }