Skip to content
This repository has been archived by the owner on Dec 5, 2020. It is now read-only.

Commit

Permalink
fixed ES URL creation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Aug 15, 2017
1 parent ae5026b commit ca05df8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,11 @@ public EsHttpRequest(
String esEndpoint = esEdp.read();
if(esEndpoint == null || esEndpoint.isEmpty()) {
throw new IllegalStateException("ElasticSearch endpoint needs to be specified!");
}
if(!esEndpoint.endsWith("/")) {
esEndpoint += "/";
}
if(esEndpoint.endsWith("/")) {
esEndpoint += uri;
} else {
esEndpoint += "/" + uri;
}
this.request.setEndpoint(URI.create(esEndpoint));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,6 @@
*/
package com.amihaiemil.charles.aws;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;

import java.io.IOException;
import java.net.ServerSocket;
import java.util.ArrayList;
Expand All @@ -46,6 +42,8 @@
import com.jcabi.http.mock.MkGrizzlyContainer;
import com.jcabi.http.mock.MkQuery;

import static org.junit.Assert.*;

/**
* Unit tests for {@link AmazonEsRepository}
* @author Mihai Andronache ([email protected])
Expand Down Expand Up @@ -149,10 +147,10 @@ public void sendsExportRequestToAwsEs() throws Exception {
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/_bulk")
new EsEndPoint.Fake("http://localhost:" + port + "/es")
).export(pages);
MkQuery request = server.take();
assertTrue("/es/_bulk/".equals(request.uri().toString()));
assertEquals("/es/_bulk/",request.uri().toString());
assertTrue("POST".equals(request.method()));
} finally {
server.stop();
Expand Down Expand Up @@ -180,12 +178,12 @@ public void sendsExportRequestToAwsEsWithError() throws Exception {
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/_bulk/")
new EsEndPoint.Fake("http://localhost:" + port + "/es/")
).export(pages);
} catch (AmazonServiceException ase) {
assertTrue(ase.getErrorMessage().contains("Precondition Failed"));
MkQuery request = server.take();
assertTrue("/es/_bulk/".equals(request.uri().toString()));
assertEquals("/es/_bulk/", request.uri().toString());
assertTrue("POST".equals(request.method()));
}finally {
server.stop();
Expand All @@ -208,10 +206,10 @@ public void sendsDeleteRequestToAwsEs() throws Exception {
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/index.to.be.deleted/")
new EsEndPoint.Fake("http://localhost:" + port + "/es/")
).delete();
MkQuery request = server.take();
assertTrue("/es/index.to.be.deleted/".equals(request.uri().toString()));
assertEquals("/es/index.to.be.deleted/", request.uri().toString());
assertTrue("DELETE".equals(request.method()));
} finally {
server.stop();
Expand All @@ -234,11 +232,11 @@ public void tellsIfIndexExists() throws Exception {
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/present.index/")
new EsEndPoint.Fake("http://localhost:" + port + "/es")
).exists();
assertTrue(exists);
MkQuery request = server.take();
assertTrue("/es/present.index/".equals(request.uri().toString()));
assertEquals("/es/present.index/", request.uri().toString());
assertTrue("HEAD".equals(request.method()));
} finally {
server.stop();
Expand All @@ -261,11 +259,11 @@ public void tellsIfIndexDoesNotExist() throws Exception {
new AccessKeyId.Fake("access_key"),
new SecretKey.Fake("secret_key"),
new Region.Fake("ro"),
new EsEndPoint.Fake("http://localhost:" + port + "/es/missing.index/")
new EsEndPoint.Fake("http://localhost:" + port + "/es/")
).exists();
assertFalse(exists);
MkQuery request = server.take();
assertTrue("/es/missing.index/".equals(request.uri().toString()));
assertEquals("/es/missing.index/", request.uri().toString());
assertTrue("HEAD".equals(request.method()));
} finally {
server.stop();
Expand Down

0 comments on commit ca05df8

Please sign in to comment.