Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<elasticsearch.version>1.2.2</elasticsearch.version>
<elasticsearch.version>2.4.0</elasticsearch.version>
<github.global.server>github</github.global.server>
</properties>

Expand Down Expand Up @@ -48,6 +48,12 @@
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
</dependency>
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>4.1.0</version>
<optional>true</optional>
</dependency>
</dependencies>

<scm>
Expand All @@ -68,8 +74,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/tlrx/elasticsearch/test/EsSetup.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

import com.github.tlrx.elasticsearch.test.provider.*;
import com.github.tlrx.elasticsearch.test.request.*;
import com.google.common.base.Preconditions;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Preconditions;
import org.elasticsearch.common.settings.Settings;

/**
Expand Down Expand Up @@ -319,7 +319,7 @@ public Boolean exists(String index, String type, String id) {
* @return the total number of documents
*/
public Long countAll() {
return doExecute(new Count());
return doExecute(new Count("_all"));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,6 @@
*/
boolean source() default true;

/**
* The source's "compress" value (default to true (since v0.90))
*/
boolean compress() default true;

/**
* Compress threshold value
*/
String compressThreshold() default "";

/**
* Time To Live "enabled" value (default to false)
*/
Expand All @@ -54,12 +44,6 @@
*/
boolean timestamp() default false;

/**
* The path used to extract the timestamp from the document
* (default to "", meaning the "_timestamp" field should be explicitly set when indexing)
*/
String timestampPath() default "";

/**
* The date format of the "_timestamp" field (default to "dateOptionalTime")
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@
*/
String analyzerName() default DEFAULT_ANALYZER;

/**
* The analyzer used to analyze the text contents when analyzed during indexing.
*/
String indexAnalyzerName() default DEFAULT_ANALYZER;

/**
* The analyzer used to analyze the field when part of a query string.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
package com.github.tlrx.elasticsearch.test.provider;

import com.github.tlrx.elasticsearch.test.EsSetupRuntimeException;
import org.elasticsearch.common.Preconditions;
import com.google.common.base.Preconditions;
import org.elasticsearch.common.io.Streams;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -56,17 +56,26 @@ public String toJson() {
@Override
public String toString() {
try {
if (klass != null) {
InputStream inputStream = klass.getResourceAsStream(path);
if (inputStream == null) {
throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class [" + klass.getName() + "]");
}
return Streams.copyToString(new InputStreamReader(inputStream, "UTF-8"));
} else {
return Streams.copyToStringFromClasspath(classLoader, path);
}
InputStream inputStream = openStream();
return Streams.copyToString(new InputStreamReader(inputStream, "UTF-8"));
} catch (IOException e) {
throw new EsSetupRuntimeException(e);
}
}

private InputStream openStream() throws IOException {
InputStream inputStream;
if (klass != null) {
inputStream = klass.getResourceAsStream(path);
if (inputStream == null) {
throw new FileNotFoundException("Resource [" + path + "] not found in classpath with class [" + klass.getName() + "]");
}
} else {
inputStream = classLoader.getResourceAsStream(path);
if (inputStream == null) {
throw new FileNotFoundException("Resource [" + path + "] not found in classpath with classloader [" + classLoader + "]");
}
}
return inputStream;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package com.github.tlrx.elasticsearch.test.provider;

import com.google.common.base.Preconditions;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.Preconditions;
import org.elasticsearch.common.unit.TimeValue;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,22 @@
package com.github.tlrx.elasticsearch.test.provider;


import com.github.tlrx.elasticsearch.test.EsSetupRuntimeException;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.io.FileSystemUtils;
import org.elasticsearch.common.network.NetworkUtils;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.node.Node;
import org.elasticsearch.node.NodeBuilder;

import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.nio.file.FileVisitResult;
import java.nio.file.FileVisitor;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.attribute.BasicFileAttributes;

/**
* LocalClientProvider instantiates a local node with in-memory index store type.
Expand Down Expand Up @@ -79,19 +85,51 @@ public void close() {
if ((node != null) && (!node.isClosed())) {
node.close();

FileSystemUtils.deleteRecursively(new File("./target/elasticsearch-test/"), true);
deleteRecursively(new File("./target/elasticsearch-test/"));
}
}

/**
* Recursively delete a directory.
* Links are not handled properly.
*/
public static void deleteRecursively(File dir) {
try {
Files.walkFileTree(dir.toPath(), new FileVisitor<Path>() {
@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
return FileVisitResult.TERMINATE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
Files.delete(dir);
return FileVisitResult.CONTINUE;
}
});
} catch (IOException e) {
}
}

protected Settings buildNodeSettings() {
// Build settings
ImmutableSettings.Builder builder = ImmutableSettings.settingsBuilder()

Settings.Builder builder = Settings.builder()
.put("node.name", "node-test-" + System.currentTimeMillis())
.put("node.data", true)
.put("cluster.name", "cluster-test-" + NetworkUtils.getLocalAddress().getHostName())
.put("index.store.type", "memory")
.put("index.store.fs.memory.enabled", "true")
.put("gateway.type", "none")
.put("cluster.name", "cluster-test-" + getLocalHostName())
.put("path.home", "./target/elasticsearch-test")
.put("path.data", "./target/elasticsearch-test/data")
.put("path.work", "./target/elasticsearch-test/work")
.put("path.logs", "./target/elasticsearch-test/logs")
Expand All @@ -106,4 +144,15 @@ protected Settings buildNodeSettings() {

return builder.build();
}

/**
* Get local hostname
*/
public static String getLocalHostName() {
try {
return InetAddress.getLocalHost().getHostName();
} catch (UnknownHostException e) {
return "unknown";
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.action.bulk.BulkResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;

import java.util.ArrayList;
Expand Down Expand Up @@ -54,7 +53,7 @@ public CreateIndex withSettings(Settings settings) {
}

public CreateIndex withSettings(String source) {
Settings settings = ImmutableSettings.settingsBuilder()
Settings settings = Settings.builder()
.loadFromSource(source)
.build();
withSettings(settings);
Expand Down Expand Up @@ -104,7 +103,7 @@ public Void execute(final Client client) throws ElasticsearchException {
bulkRequestBuilder = client.prepareBulk();
for (JSONProvider jsonProvider : bulks) {
byte[] content = jsonProvider.toJson().getBytes("UTF-8");
bulkRequestBuilder.add(content, 0, content.length, true);
bulkRequestBuilder.add(content, 0, content.length);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.put.PutIndexTemplateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.settings.ImmutableSettings;
import org.elasticsearch.common.settings.Settings;

import java.util.Map;
Expand Down Expand Up @@ -54,7 +53,7 @@ public CreateTemplate withSettings(Settings settings) {
}

public CreateTemplate withSettings(String source) {
Settings settings = ImmutableSettings.settingsBuilder()
Settings settings = Settings.builder()
.loadFromSource(source)
.build();
withSettings(settings);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.github.tlrx.elasticsearch.test.request;

import com.github.tlrx.elasticsearch.test.EsSetupRuntimeException;
import com.google.common.collect.Lists;
import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.action.admin.cluster.state.ClusterStateAction;
import org.elasticsearch.action.admin.cluster.state.ClusterStateRequestBuilder;
Expand All @@ -27,7 +28,6 @@
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateRequest;
import org.elasticsearch.action.admin.indices.template.delete.DeleteIndexTemplateResponse;
import org.elasticsearch.client.Client;
import org.elasticsearch.common.collect.Lists;

import java.util.Arrays;
import java.util.Collection;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void handleBefore(Annotation annotation, Object instance, Map<String, Obj

// Execute the BulkRequest
BulkResponse response = client.prepareBulk()
.add(buffer, 0, buffer.length, true, elasticsearchBulkRequest.defaultIndexName(), elasticsearchBulkRequest.defaultTypeName())
.add(buffer, 0, buffer.length, elasticsearchBulkRequest.defaultIndexName(), elasticsearchBulkRequest.defaultTypeName())
.setRefresh(true)
.execute()
.actionGet();
Expand Down
Loading