Skip to content

Instantly share code, notes, and snippets.

@rjernst
Created October 10, 2014 19:53
Show Gist options
  • Save rjernst/050ff7a73608de007ece to your computer and use it in GitHub Desktop.
Save rjernst/050ff7a73608de007ece to your computer and use it in GitHub Desktop.
public void test() throws Exception {
File dataDir = newTempDir();
File oldIndex = new File(getClass().getResource("index-0.20.zip").toURI());
TestUtil.unzip(oldIndex, dataDir);
NodeBuilder nodeBuilder = NodeBuilder.nodeBuilder();
nodeBuilder.clusterName("oldindexcluster");
Settings settings = ImmutableSettings.builder()
.put("path.data", dataDir.getPath())
.put("node.mode", "network")
.put(InternalNode.HTTP_ENABLED, true)
.build();
Node node = nodeBuilder.settings(settings).node();
try {
node.start();
NodeInfo info = nodeInfo(node.client());
info.getHttp().address().boundAddress();
TransportAddress publishAddress = info.getTransport().address().publishAddress();
assertEquals(1, publishAddress.uniqueAddressTypeId());
InetSocketAddress address = ((InetSocketTransportAddress) publishAddress).address();
HttpRequestBuilder httpClient = new HttpRequestBuilder(HttpClients.createDefault()).host(address.getHostName()).port(address.getPort());
HttpResponse rsp = httpClient.method("GET").path("/_upgrade").addParam("pretty", "true").execute();
System.out.println("RESPONSE: \n" + rsp.getBody());
} finally {
node.stop();
}
}
static NodeInfo nodeInfo(final Client client) {
final NodesInfoResponse nodeInfos = client.admin().cluster().prepareNodesInfo().get();
final NodeInfo[] nodes = nodeInfos.getNodes();
assertEquals(1, nodes.length);
return nodes[0];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment