Elasticsearch 5 ESIntegTestCase simple testcase problem

Hello

I have the following simple test case and I am trying to figure out why the document count does not work?

I can see in the logs the following.

[2017-01-23T22:59:03,039][DEBUG][p.ServiceIntTest ] [-1] docs indexed. waiting for [1]
[2017-01-23T22:59:04,039][DEBUG][p.ServiceIntTest ] [-1] docs indexed. waiting for [1]

Am I missing the point of what waitForDocs(1); is used for?

Thanks
Paul

sample code

package pdw;


import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;

import java.text.ParseException;
import java.util.Date;

import org.elasticsearch.action.index.IndexResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.test.ESIntegTestCase;
import org.elasticsearch.test.ESIntegTestCase.ClusterScope;
import org.elasticsearch.test.ESIntegTestCase.Scope;
import org.elasticsearch.test.junit.annotations.TestLogging;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;


@TestLogging("_root:DEBUG")
@ClusterScope(scope = Scope.SUITE)
@RunWith(com.carrotsearch.randomizedtesting.RandomizedRunner.class)
public class ServiceIntTest extends ESIntegTestCase {

	private Client client;
	
	@Override
	protected Settings nodeSettings(int nodeOrdinal) {
		return Settings.builder().put(super.nodeSettings(nodeOrdinal)).build();
	}

	@Before
	public void setUp() throws Exception {
		super.setUp();
		client = ESIntegTestCase.client();
		setUpTestData(client);
	}
	
	private void setUpTestData(Client client) throws Exception {

		createIndex("twitter");
		refresh("twitter");
		IndexResponse response = client.prepareIndex("twitter", "tweet", "1")
		        .setSource(jsonBuilder()
		                    .startObject()
		                        .field("user", "kimchy")
		                        .field("postDate", new Date())
		                        .field("message", "trying out Elasticsearch")
		                    .endObject()
		                  )
		        .get();	
				
		refresh("twitter");
		waitForDocs(1);
		ensureGreen();
	}

	@Test
	public void testDocsCount() throws ParseException {
		Assert.assertTrue(true);
	}
}

I've not used waitForDocs. refresh is synchronous though.

Thanks @nik9000 I settled on using the elasticsearch-maven-plugin.

Based on some of your comments on other Threads it seems testing against a "real" node is the preferred way to go.

Everything works like I expect it to now. I'd recommend the plugin, it works great.

Thanks for the feedback.

Paul

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.