mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-03-09 14:34:43 +00:00
parent
f8f647dea9
commit
2b4f875731
123
pom.xml
123
pom.xml
@ -30,7 +30,13 @@
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<elasticsearch.version>0.90.3</elasticsearch.version>
|
||||
<elasticsearch.version>0.90.10</elasticsearch.version>
|
||||
<lucene.version>4.6.0</lucene.version>
|
||||
<tests.jvms>1</tests.jvms>
|
||||
<tests.shuffle>true</tests.shuffle>
|
||||
<tests.output>onerror</tests.output>
|
||||
<tests.client.ratio></tests.client.ratio>
|
||||
<es.logger.level>INFO</es.logger.level>
|
||||
</properties>
|
||||
|
||||
<repositories>
|
||||
@ -57,6 +63,13 @@
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.apache.lucene</groupId>
|
||||
<artifactId>lucene-test-framework</artifactId>
|
||||
<version>${lucene.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
@ -79,20 +92,11 @@
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.testng</groupId>
|
||||
<artifactId>testng</artifactId>
|
||||
<version>6.8</version>
|
||||
<groupId>org.elasticsearch</groupId>
|
||||
<artifactId>elasticsearch</artifactId>
|
||||
<version>${elasticsearch.version}</version>
|
||||
<type>test-jar</type>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
</exclusion>
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@ -116,15 +120,98 @@
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>com.carrotsearch.randomizedtesting</groupId>
|
||||
<artifactId>junit4-maven-plugin</artifactId>
|
||||
<version>2.0.12</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>tests</id>
|
||||
<phase>test</phase>
|
||||
<goals>
|
||||
<goal>junit4</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<heartbeat>20</heartbeat>
|
||||
<jvmOutputAction>pipe,warn</jvmOutputAction>
|
||||
<leaveTemporary>true</leaveTemporary>
|
||||
<listeners>
|
||||
<report-ant-xml mavenExtensions="true"
|
||||
dir="${project.build.directory}/surefire-reports"/>
|
||||
<report-text
|
||||
showThrowable="true"
|
||||
showStackTraces="true"
|
||||
showOutput="${tests.output}"
|
||||
showStatusOk="false"
|
||||
showStatusError="true"
|
||||
showStatusFailure="true"
|
||||
showStatusIgnored="true"
|
||||
showSuiteSummary="true"
|
||||
timestamps="false"/>
|
||||
<report-execution-times file="${basedir}/.local-execution-hints.log"/>
|
||||
</listeners>
|
||||
<assertions>
|
||||
<enable/>
|
||||
</assertions>
|
||||
<parallelism>${tests.jvms}</parallelism>
|
||||
<balancers>
|
||||
<execution-times>
|
||||
<fileset dir="${basedir}" includes=".local-execution-hints.log"/>
|
||||
</execution-times>
|
||||
</balancers>
|
||||
<includes>
|
||||
<include>**/*Tests.class</include>
|
||||
<include>**/*Test.class</include>
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.class</exclude>
|
||||
<exclude>**/*StressTest.class</exclude>
|
||||
</excludes>
|
||||
<jvmArgs>
|
||||
<param>-Xmx512m</param>
|
||||
<param>-XX:MaxDirectMemorySize=512m</param>
|
||||
<param>-Des.logger.prefix=</param>
|
||||
</jvmArgs>
|
||||
<shuffleOnSlave>${tests.shuffle}</shuffleOnSlave>
|
||||
<sysouts>${tests.verbose}</sysouts>
|
||||
<seed>${tests.seed}</seed>
|
||||
<haltOnFailure>${tests.failfast}</haltOnFailure>
|
||||
<systemProperties>
|
||||
<!-- RandomizedTesting library system properties -->
|
||||
<tests.iters>${tests.iters}</tests.iters>
|
||||
<tests.maxfailures>${tests.maxfailures}</tests.maxfailures>
|
||||
<tests.failfast>${tests.failfast}</tests.failfast>
|
||||
<tests.class>${tests.class}</tests.class>
|
||||
<tests.method>${tests.method}</tests.method>
|
||||
<tests.nightly>${tests.nightly}</tests.nightly>
|
||||
<tests.badapples>${tests.badapples}</tests.badapples>
|
||||
<tests.weekly>${tests.weekly}</tests.weekly>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.awaitsfix>${tests.awaitsfix}</tests.awaitsfix>
|
||||
<tests.slow>${tests.slow}</tests.slow>
|
||||
<tests.timeoutSuite>${tests.timeoutSuite}</tests.timeoutSuite>
|
||||
<tests.showSuccess>${tests.showSuccess}</tests.showSuccess>
|
||||
<tests.integration>${tests.integration}</tests.integration>
|
||||
<tests.cluster_seed>${tests.cluster_seed}</tests.cluster_seed>
|
||||
<tests.client.ratio>${tests.client.ratio}</tests.client.ratio>
|
||||
<es.node.local>${env.ES_TEST_LOCAL}</es.node.local>
|
||||
<es.node.mode>${es.node.mode}</es.node.mode>
|
||||
<es.logger.level>${es.logger.level}</es.logger.level>
|
||||
<java.awt.headless>true</java.awt.headless>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<!-- we skip surefire to work with randomized testing above -->
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>2.12.3</version>
|
||||
<version>2.15</version>
|
||||
<configuration>
|
||||
<includes>
|
||||
<include>**/*Tests.java</include>
|
||||
</includes>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-source-plugin</artifactId>
|
||||
|
@ -25,22 +25,21 @@ import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
|
||||
import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public class DateAttachmentMapperTests {
|
||||
public class DateAttachmentMapperTests extends ElasticsearchTestCase {
|
||||
|
||||
private DocumentMapperParser mapperParser;
|
||||
|
||||
@BeforeClass
|
||||
@Before
|
||||
public void setupMapperParser() {
|
||||
mapperParser = new DocumentMapperParser(new Index("test"), new AnalysisService(new Index("test")), null, null);
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
@ -28,14 +28,14 @@ import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
|
||||
import org.testng.annotations.Test;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
|
||||
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
@ -43,7 +43,7 @@ import static org.hamcrest.Matchers.*;
|
||||
* Note that we have converted /org/elasticsearch/index/mapper/xcontent/testContentLength.txt
|
||||
* to a /org/elasticsearch/index/mapper/xcontent/encrypted.pdf with password `12345678`.
|
||||
*/
|
||||
public class EncryptedDocMapperTest {
|
||||
public class EncryptedDocMapperTest extends ElasticsearchTestCase {
|
||||
|
||||
@Test
|
||||
public void testMultipleDocsEncryptedLast() throws IOException {
|
||||
@ -111,7 +111,7 @@ public class EncryptedDocMapperTest {
|
||||
assertThat(doc.getField(docMapper.mappers().smartName("file2.content_length").mapper().names().indexName()).numericValue().longValue(), is(344L));
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = MapperParsingException.class)
|
||||
@Test(expected = MapperParsingException.class)
|
||||
public void testMultipleDocsEncryptedNotIgnoringErrors() throws IOException {
|
||||
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"),
|
||||
ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(),
|
||||
|
@ -29,20 +29,20 @@ import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
|
||||
import org.testng.annotations.Test;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
|
||||
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
|
||||
/**
|
||||
* Test for https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/38
|
||||
*/
|
||||
public class MetadataMapperTest {
|
||||
public class MetadataMapperTest extends ElasticsearchTestCase {
|
||||
|
||||
protected void checkMeta(String filename, Settings settings, Long expectedDate, Long expectedLength) throws IOException {
|
||||
DocumentMapperParser mapperParser = new DocumentMapperParser(new Index("test"), settings, new AnalysisService(new Index("test")), null, null);
|
||||
@ -96,7 +96,7 @@ public class MetadataMapperTest {
|
||||
checkMeta("htmlWithoutDateMeta.html", ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(), null, 300L);
|
||||
}
|
||||
|
||||
@Test(expectedExceptions = MapperParsingException.class)
|
||||
@Test(expected = MapperParsingException.class)
|
||||
public void testWithEmptyDate() throws Exception {
|
||||
checkMeta("htmlWithEmptyDateMeta.html", ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build(), null, null);
|
||||
}
|
||||
|
@ -26,22 +26,21 @@ import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
|
||||
import org.elasticsearch.index.mapper.core.DateFieldMapper;
|
||||
import org.elasticsearch.index.mapper.core.StringFieldMapper;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public class MultifieldAttachmentMapperTests {
|
||||
public class MultifieldAttachmentMapperTests extends ElasticsearchTestCase {
|
||||
|
||||
private DocumentMapperParser mapperParser;
|
||||
|
||||
@BeforeClass
|
||||
@Before
|
||||
public void setupMapperParser() {
|
||||
mapperParser = new DocumentMapperParser(new Index("test"), new AnalysisService(new Index("test")), null, null);
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
@ -26,25 +26,24 @@ import org.elasticsearch.index.analysis.AnalysisService;
|
||||
import org.elasticsearch.index.mapper.DocumentMapper;
|
||||
import org.elasticsearch.index.mapper.DocumentMapperParser;
|
||||
import org.elasticsearch.index.mapper.attachment.AttachmentMapper;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.elasticsearch.test.ElasticsearchTestCase;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
|
||||
import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public class SimpleAttachmentMapperTests {
|
||||
public class SimpleAttachmentMapperTests extends ElasticsearchTestCase {
|
||||
|
||||
private DocumentMapperParser mapperParser;
|
||||
|
||||
@BeforeClass
|
||||
@Before
|
||||
public void setupMapperParser() {
|
||||
mapperParser = new DocumentMapperParser(new Index("test"), new AnalysisService(new Index("test")), null, null);
|
||||
mapperParser.putTypeParser(AttachmentMapper.CONTENT_TYPE, new AttachmentMapper.TypeParser());
|
||||
|
@ -19,20 +19,12 @@
|
||||
|
||||
package org.elasticsearch.plugin.mapper.attachments.test;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkUtils;
|
||||
import org.elasticsearch.common.settings.ImmutableSettings;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.testng.annotations.AfterClass;
|
||||
import org.testng.annotations.AfterMethod;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
import org.testng.annotations.Test;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.client.Requests.*;
|
||||
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
|
||||
@ -40,47 +32,25 @@ import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.fieldQuery;
|
||||
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
* Test case for issue https://github.com/elasticsearch/elasticsearch-mapper-attachments/issues/18
|
||||
*/
|
||||
@Test
|
||||
public class MultipleAttachmentIntegrationTests {
|
||||
public class MultipleAttachmentIntegrationTests extends ElasticsearchIntegrationTest {
|
||||
private boolean ignore_errors = true;
|
||||
|
||||
private final ESLogger logger = Loggers.getLogger(getClass());
|
||||
|
||||
private Node node;
|
||||
|
||||
@BeforeClass
|
||||
public void setupServer() {
|
||||
node = nodeBuilder().local(true).settings(settingsBuilder()
|
||||
.put("path.data", "target/data")
|
||||
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
|
||||
.put("gateway.type", "none")).node();
|
||||
@Before
|
||||
public void cleanTestIndex() throws Exception {
|
||||
wipeIndices("test");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void closeServer() {
|
||||
node.close();
|
||||
}
|
||||
|
||||
private void createIndex(Settings settings) {
|
||||
logger.info("creating index [test]");
|
||||
node.client().admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0).put(settings))).actionGet();
|
||||
logger.info("Running Cluster Health");
|
||||
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
|
||||
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void deleteIndex() {
|
||||
logger.info("deleting index [test]");
|
||||
node.client().admin().indices().delete(deleteIndexRequest("test")).actionGet();
|
||||
@Override
|
||||
public Settings indexSettings() {
|
||||
return settingsBuilder()
|
||||
.put("index.numberOfReplicas", 0)
|
||||
.put("index.mapping.attachment.ignore_errors", ignore_errors)
|
||||
.build();
|
||||
}
|
||||
|
||||
/**
|
||||
@ -88,38 +58,45 @@ public class MultipleAttachmentIntegrationTests {
|
||||
*/
|
||||
@Test
|
||||
public void testMultipleAttachmentsWithEncryptedDoc() throws Exception {
|
||||
createIndex(ImmutableSettings.builder().build());
|
||||
ignore_errors = true;
|
||||
logger.info("creating index [test]");
|
||||
createIndex("test");
|
||||
ensureGreen();
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
|
||||
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
|
||||
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");
|
||||
|
||||
node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
|
||||
node.client().index(indexRequest("test").type("person")
|
||||
.source(jsonBuilder().startObject().field("file1", html).field("file2", pdf).field("hello","world").endObject())).actionGet();
|
||||
node.client().admin().indices().refresh(refreshRequest()).actionGet();
|
||||
index("test", "person", jsonBuilder().startObject().field("file1", html).field("file2", pdf).field("hello","world").endObject());
|
||||
refresh();
|
||||
|
||||
CountResponse countResponse = node.client().count(countRequest("test").query(fieldQuery("file1", "World"))).actionGet();
|
||||
CountResponse countResponse = client().count(countRequest("test").query(fieldQuery("file1", "World"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
|
||||
countResponse = node.client().count(countRequest("test").query(fieldQuery("hello", "World"))).actionGet();
|
||||
countResponse = client().count(countRequest("test").query(fieldQuery("hello", "World"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
}
|
||||
|
||||
/**
|
||||
* When we don't want to ignore errors
|
||||
*/
|
||||
@Test(expectedExceptions = MapperParsingException.class)
|
||||
@Test(expected = MapperParsingException.class)
|
||||
public void testMultipleAttachmentsWithEncryptedDocNotIgnoringErrors() throws Exception {
|
||||
createIndex(ImmutableSettings.builder().put("index.mapping.attachment.ignore_errors", false).build());
|
||||
ignore_errors = false;
|
||||
|
||||
logger.info("creating index [test]");
|
||||
createIndex("test");
|
||||
ensureGreen();
|
||||
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/multipledocs/test-mapping.json");
|
||||
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/htmlWithValidDateMeta.html");
|
||||
byte[] pdf = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/encrypted.pdf");
|
||||
|
||||
node.client().admin().indices()
|
||||
client().admin().indices()
|
||||
.putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
|
||||
node.client().index(indexRequest("test").type("person")
|
||||
.source(jsonBuilder().startObject().field("file1", html).field("file2", pdf).field("hello","world").endObject())).actionGet();
|
||||
index("test", "person", jsonBuilder().startObject().field("file1", html).field("file2", pdf).field("hello","world").endObject());
|
||||
}
|
||||
}
|
||||
|
@ -19,15 +19,12 @@
|
||||
|
||||
package org.elasticsearch.plugin.mapper.attachments.test;
|
||||
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthResponse;
|
||||
import org.elasticsearch.action.admin.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.action.count.CountResponse;
|
||||
import org.elasticsearch.common.logging.ESLogger;
|
||||
import org.elasticsearch.common.logging.Loggers;
|
||||
import org.elasticsearch.common.network.NetworkUtils;
|
||||
import org.elasticsearch.common.settings.Settings;
|
||||
import org.elasticsearch.index.mapper.MapperParsingException;
|
||||
import org.elasticsearch.node.Node;
|
||||
import org.testng.annotations.*;
|
||||
import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.elasticsearch.client.Requests.*;
|
||||
import static org.elasticsearch.common.io.Streams.copyToBytesFromClasspath;
|
||||
@ -35,48 +32,26 @@ import static org.elasticsearch.common.io.Streams.copyToStringFromClasspath;
|
||||
import static org.elasticsearch.common.settings.ImmutableSettings.settingsBuilder;
|
||||
import static org.elasticsearch.common.xcontent.XContentFactory.jsonBuilder;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.fieldQuery;
|
||||
import static org.elasticsearch.node.NodeBuilder.nodeBuilder;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public class SimpleAttachmentIntegrationTests {
|
||||
public class SimpleAttachmentIntegrationTests extends ElasticsearchIntegrationTest {
|
||||
|
||||
private final ESLogger logger = Loggers.getLogger(getClass());
|
||||
|
||||
private Node node;
|
||||
|
||||
@BeforeClass
|
||||
public void setupServer() {
|
||||
node = nodeBuilder().local(true).settings(settingsBuilder()
|
||||
.put("path.data", "target/data")
|
||||
.put("cluster.name", "test-cluster-" + NetworkUtils.getLocalAddress())
|
||||
.put("gateway.type", "none")).node();
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public void closeServer() {
|
||||
node.close();
|
||||
}
|
||||
|
||||
@BeforeMethod
|
||||
public void createIndex() {
|
||||
@Before
|
||||
public void createEmptyIndex() throws Exception {
|
||||
logger.info("creating index [test]");
|
||||
node.client().admin().indices().create(createIndexRequest("test").settings(settingsBuilder().put("index.numberOfReplicas", 0))).actionGet();
|
||||
logger.info("Running Cluster Health");
|
||||
ClusterHealthResponse clusterHealth = node.client().admin().cluster().health(clusterHealthRequest().waitForGreenStatus()).actionGet();
|
||||
logger.info("Done Cluster Health, status " + clusterHealth.getStatus());
|
||||
assertThat(clusterHealth.isTimedOut(), equalTo(false));
|
||||
assertThat(clusterHealth.getStatus(), equalTo(ClusterHealthStatus.GREEN));
|
||||
wipeIndices("test");
|
||||
createIndex("test");
|
||||
ensureGreen();
|
||||
}
|
||||
|
||||
@AfterMethod
|
||||
public void deleteIndex() {
|
||||
logger.info("deleting index [test]");
|
||||
node.client().admin().indices().delete(deleteIndexRequest("test")).actionGet();
|
||||
@Override
|
||||
public Settings indexSettings() {
|
||||
return settingsBuilder()
|
||||
.put("index.numberOfReplicas", 0)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -84,16 +59,15 @@ public class SimpleAttachmentIntegrationTests {
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
|
||||
byte[] html = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testXHTML.html");
|
||||
|
||||
node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
|
||||
node.client().index(indexRequest("test").type("person")
|
||||
.source(jsonBuilder().startObject().field("file", html).endObject())).actionGet();
|
||||
node.client().admin().indices().refresh(refreshRequest()).actionGet();
|
||||
index("test", "person", jsonBuilder().startObject().field("file", html).endObject());
|
||||
refresh();
|
||||
|
||||
CountResponse countResponse = node.client().count(countRequest("test").query(fieldQuery("file.title", "test document"))).actionGet();
|
||||
CountResponse countResponse = client().count(countRequest("test").query(fieldQuery("file.title", "test document"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
|
||||
countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "tests the ability"))).actionGet();
|
||||
countResponse = client().count(countRequest("test").query(fieldQuery("file", "tests the ability"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
}
|
||||
|
||||
@ -103,16 +77,15 @@ public class SimpleAttachmentIntegrationTests {
|
||||
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testContentLength.txt");
|
||||
final int CONTENT_LENGTH_LIMIT = 20;
|
||||
|
||||
node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
|
||||
node.client().index(indexRequest("test").type("person")
|
||||
.source(jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject())).actionGet();
|
||||
node.client().admin().indices().refresh(refreshRequest()).actionGet();
|
||||
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
|
||||
refresh();
|
||||
|
||||
CountResponse countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "BeforeLimit"))).actionGet();
|
||||
CountResponse countResponse = client().count(countRequest("test").query(fieldQuery("file", "BeforeLimit"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
|
||||
countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "AfterLimit"))).actionGet();
|
||||
countResponse = client().count(countRequest("test").query(fieldQuery("file", "AfterLimit"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(0l));
|
||||
}
|
||||
|
||||
@ -122,16 +95,15 @@ public class SimpleAttachmentIntegrationTests {
|
||||
byte[] txt = copyToBytesFromClasspath("/org/elasticsearch/index/mapper/xcontent/testContentLength.txt");
|
||||
final int CONTENT_LENGTH_LIMIT = -1;
|
||||
|
||||
node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
|
||||
node.client().index(indexRequest("test").type("person")
|
||||
.source(jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject())).actionGet();
|
||||
node.client().admin().indices().refresh(refreshRequest()).actionGet();
|
||||
index("test", "person", jsonBuilder().startObject().field("file").startObject().field("content", txt).field("_indexed_chars", CONTENT_LENGTH_LIMIT).endObject());
|
||||
refresh();
|
||||
|
||||
CountResponse countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "Begin"))).actionGet();
|
||||
CountResponse countResponse = client().count(countRequest("test").query(fieldQuery("file", "Begin"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
|
||||
countResponse = node.client().count(countRequest("test").query(fieldQuery("file", "End"))).actionGet();
|
||||
countResponse = client().count(countRequest("test").query(fieldQuery("file", "End"))).actionGet();
|
||||
assertThat(countResponse.getCount(), equalTo(1l));
|
||||
}
|
||||
|
||||
@ -140,13 +112,12 @@ public class SimpleAttachmentIntegrationTests {
|
||||
* <br/>We throw a nicer exception when no content is provided
|
||||
* @throws Exception
|
||||
*/
|
||||
@Test(expectedExceptions = MapperParsingException.class)
|
||||
@Test(expected = MapperParsingException.class)
|
||||
public void testNoContent() throws Exception {
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
|
||||
String mapping = copyToStringFromClasspath("/org/elasticsearch/index/mapper/xcontent/test-mapping.json");
|
||||
|
||||
node.client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
client().admin().indices().putMapping(putMappingRequest("test").type("person").source(mapping)).actionGet();
|
||||
|
||||
node.client().index(indexRequest("test").type("person")
|
||||
.source(jsonBuilder().startObject().field("file").startObject().endObject())).actionGet();
|
||||
index("test", "person", jsonBuilder().startObject().field("file").startObject().endObject());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user