# Updating opensource project sources from 1-\>2 of Elasticsearch, integration tests issues :(

**URL:** <https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216>\
**Category:** Elasticsearch\
**Created:** [September 22, 2016, 8:34am UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216 "2016-09-22T08:34:01Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![11154](https://avatars.discourse-cdn.com/v4/letter/1/d6d6ee/32.png) [@11154](https://discuss.elastic.co/u/11154)\
**Post date:** [September 22, 2016, 8:34am UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/1 "2016-09-22T08:34:01Z")

</div>

Hi!  
I am upgrading opensource project code from 1.5.1 to 2.3.5 of Elasticsearch.  
I've faced with integration tests failing.  
I've tried to fix them some ways, and understood a lack of knowledge of elasticsearch kitchen.  
There is breaking changes between this versions, and they are huge between v1 and v2 of elasticsearch.  
I've used all my google-fu, but there is no useful page explaining actions to upgrade code of plugin tests from 1 to 2.  
There is some info about "we changed here this and this", but here is a HUGE lack of explanation with examples, what should be done to integration tests.

So, my question:  
ElasticsearchIntegrationTest was refactored to ESIntegTestCase.  
There is method org.elasticsearch.test.ESIntegTestCase#httpClient (which is protected, so can be used, maybe, in extending classes?).  
If I comment out my own httpClient() in my class and trying to use method ESIntegTestCase#httpClient, there is NullPointerException.  
Can't figure out how to fix this issue correctly. ☹

So, NPE:

```
 java.lang.NullPointerException
	at __randomizedtesting.SeedInfo.seed([F85BE188096FD4CF:E74E6E5A4454A696]:0)
	at org.elasticsearch.test.ESIntegTestCase.httpClient(ESIntegTestCase.java:2070) <==
	at com.asquera.elasticsearch.plugins.http.auth.integration.DefaultConfigurationIntegrationTest.testHealthCheck(DefaultConfigurationIntegrationTest.java:45)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:606)
	at com.carrotsearch.randomizedtesting.RandomizedRunner.invoke(RandomizedRunner.java:1764)

```

ESIntegTestCase#httpClient:

```
protected HttpRequestBuilder httpClient() {
    final NodesInfoResponse nodeInfos = client().admin().cluster().prepareNodesInfo().get();
    final NodeInfo[] nodes = nodeInfos.getNodes();
    assertTrue(nodes.length > 0);
    TransportAddress publishAddress = randomFrom(nodes).getHttp().address().publishAddress(); <== here it fails (line 2070).
    assertEquals(1, publishAddress.uniqueAddressTypeId());
    InetSocketAddress address = ((InetSocketTransportAddress) publishAddress).address();
    return new HttpRequestBuilder(HttpClients.createDefault()).host(NetworkAddress.formatAddress(address.getAddress())).port(address.getPort());
}

```

Debug says there is node returned from randomFrom(nodes), but it's http field is null.  
.getHttp() returns null, and next method called (.address()) against null value, causing NPE.

Maybe there is misconfigured something?  
How can I create HTTP-transport port correctly?

Here is also our own httpClient() code from "v1" of plugin:

```
  public static HttpRequestBuilder httpClient() {
    HttpServerTransport httpServerTransport = internalCluster().getDataNodeInstance(HttpServerTransport.class);
    InetSocketAddress address = ((InetSocketTransportAddress) httpServerTransport.boundAddress().publishAddress()).address();
    return new HttpRequestBuilder(HttpClients.createDefault()).host(address.getHostName()).port(address.getPort());
  }

```

Any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [September 22, 2016, 10:20am UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/2 "2016-09-22T10:20:20Z")

</div>

I bet http isn't enabled by default for those tests. It usually shouldn't be because `ESIntegTestCase` extensions usually just use the transport protocol. You might prefer extending your own test classes and just starting Elasticsearch before all your tests.

If you still want to use `ESIntegTestCase` you should be able to override `nodeSettings` and do something like

```auto
return Settings.builder().put(super.nodeSettings(ordinal)).put("http.enabled", true).build();

```

That should enable http.

---

<div class="post-metadata">

**Author:** ![11154](https://avatars.discourse-cdn.com/v4/letter/1/d6d6ee/32.png) [@11154](https://discuss.elastic.co/u/11154)\
**Post date:** [September 22, 2016, 12:20pm UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/3 "2016-09-22T12:20:30Z")

</div>

> [@nik9000](#):
>
> override nodeSettings

Still nothing, it not helped. http field still null.  
I will try to dig here, maybe something should be overridden too.

---

<div class="post-metadata">

**Author:** ![11154](https://avatars.discourse-cdn.com/v4/letter/1/d6d6ee/32.png) [@11154](https://discuss.elastic.co/u/11154)\
**Post date:** [September 22, 2016, 1:16pm UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/4 "2016-09-22T13:16:20Z")

</div>

Does someone know how to enable http for nodes, created in ESIntegTestCase?  
Maybe I am going wrong way trying to _still use ESIntegTestCase_? 🙂  
I've seen REST testing api, so maybe I should refactor this tests?

---

<div class="post-metadata">

**Author:** ![Pedro\_Calais\_Guerra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pedro_calais_guerra/32/14362_2.png) [@Pedro\_Calais\_Guerra](https://discuss.elastic.co/u/Pedro_Calais_Guerra)\
**Post date:** [January 6, 2017, 1:17pm UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/5 "2017-01-06T13:17:00Z")

</div>

Any progress on this, Антон Мацюк?

---

<div class="post-metadata">

**Author:** ![11154](https://avatars.discourse-cdn.com/v4/letter/1/d6d6ee/32.png) [@11154](https://discuss.elastic.co/u/11154)\
**Post date:** [January 6, 2017, 1:37pm UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/6 "2017-01-06T13:37:08Z")

</div>

Sorry, had no time for trying new template-based tests, maybe will do this in this month.

---

<div class="post-metadata">

**Author:** ![Pedro\_Calais\_Guerra](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/pedro_calais_guerra/32/14362_2.png) [@Pedro\_Calais\_Guerra](https://discuss.elastic.co/u/Pedro_Calais_Guerra)\
**Post date:** [January 6, 2017, 6:39pm UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/9 "2017-01-06T18:39:25Z")

</div>

After setting http.enabled in NodeSettings, what made it work for me  
was accessing httpClient( ) only inside a @Test, or lazily using it as a test class member variable.

class ElasticsearchUtilsIT extends ESIntegTestCase {  
httpClient()... // does not work

@Test  
public void test() {  
httpClient()... /// works.  
}

}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 10:04pm UTC](https://discuss.elastic.co/t/updating-opensource-project-sources-from-1-2-of-elasticsearch-integration-tests-issues/61216/10 "2017-07-05T22:04:26Z")

</div>


