DATAES-211
changes in AliasRequest fix tests due to changes in mapping, geo point, alias etc
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -19,11 +19,10 @@ import static org.apache.commons.lang.RandomStringUtils.*;
|
||||
import static org.elasticsearch.index.query.QueryBuilders.*;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -40,7 +39,8 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration("classpath:elasticsearch-template-test.xml")
|
||||
public class AliasTests {
|
||||
|
||||
private static final String INDEX_NAME = "test-alias-index";
|
||||
private static final String INDEX_NAME_1 = "test-alias-index-1";
|
||||
private static final String INDEX_NAME_2 = "test-alias-index-2";
|
||||
private static final String TYPE_NAME = "test-alias-type";
|
||||
|
||||
@Autowired
|
||||
@@ -54,9 +54,13 @@ public class AliasTests {
|
||||
settings.put("index.number_of_shards", "2");
|
||||
settings.put("index.store.type", "fs");
|
||||
|
||||
elasticsearchTemplate.deleteIndex(INDEX_NAME);
|
||||
elasticsearchTemplate.createIndex(INDEX_NAME, settings);
|
||||
elasticsearchTemplate.refresh(INDEX_NAME, true);
|
||||
elasticsearchTemplate.deleteIndex(INDEX_NAME_1);
|
||||
elasticsearchTemplate.createIndex(INDEX_NAME_1, settings);
|
||||
elasticsearchTemplate.refresh(INDEX_NAME_1, true);
|
||||
|
||||
elasticsearchTemplate.deleteIndex(INDEX_NAME_2);
|
||||
elasticsearchTemplate.createIndex(INDEX_NAME_2, settings);
|
||||
elasticsearchTemplate.refresh(INDEX_NAME_2, true);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -64,34 +68,33 @@ public class AliasTests {
|
||||
// given
|
||||
String aliasName = "test-alias";
|
||||
AliasQuery aliasQuery = new AliasBuilder()
|
||||
.withIndexName(INDEX_NAME)
|
||||
.withIndexName(INDEX_NAME_1)
|
||||
.withAliasName(aliasName).build();
|
||||
// when
|
||||
elasticsearchTemplate.addAlias(aliasQuery);
|
||||
// then
|
||||
Set<String> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME);
|
||||
List<AliasMetaData> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME_1);
|
||||
assertThat(aliases, is(notNullValue()));
|
||||
assertThat(aliases.contains(aliasName), is(true));
|
||||
assertThat(aliases.get(0).alias(), is(aliasName));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveAlias() {
|
||||
// given
|
||||
String indexName = INDEX_NAME;
|
||||
String indexName = INDEX_NAME_1;
|
||||
String aliasName = "test-alias";
|
||||
AliasQuery aliasQuery = new AliasBuilder()
|
||||
.withIndexName(indexName)
|
||||
.withAliasName(aliasName).build();
|
||||
// when
|
||||
elasticsearchTemplate.addAlias(aliasQuery);
|
||||
Set<String> aliases = elasticsearchTemplate.queryForAlias(indexName);
|
||||
List<AliasMetaData> aliases = elasticsearchTemplate.queryForAlias(indexName);
|
||||
assertThat(aliases, is(notNullValue()));
|
||||
assertThat(aliases.contains(aliasName), is(true));
|
||||
assertThat(aliases.get(0).alias(), is(aliasName));
|
||||
// then
|
||||
elasticsearchTemplate.removeAlias(aliasQuery);
|
||||
aliases = elasticsearchTemplate.queryForAlias(indexName);
|
||||
assertThat(aliases, is(notNullValue()));
|
||||
assertThat(aliases.size(), is(0));
|
||||
assertThat(aliases, is(nullValue()));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -100,7 +103,7 @@ public class AliasTests {
|
||||
@Test
|
||||
public void shouldAddAliasWithGivenRoutingValue() {
|
||||
//given
|
||||
String indexName = INDEX_NAME;
|
||||
String indexName = INDEX_NAME_1;
|
||||
String alias = "test-alias";
|
||||
|
||||
AliasQuery aliasQuery = new AliasBuilder()
|
||||
@@ -124,15 +127,17 @@ public class AliasTests {
|
||||
.build();
|
||||
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
elasticsearchTemplate.refresh(INDEX_NAME, true);
|
||||
elasticsearchTemplate.refresh(INDEX_NAME_1, true);
|
||||
|
||||
SearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withIndices(alias).withTypes(TYPE_NAME).build();
|
||||
long count = elasticsearchTemplate.count(query);
|
||||
//then
|
||||
Set<String> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME);
|
||||
List<AliasMetaData> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME_1);
|
||||
assertThat(aliases, is(notNullValue()));
|
||||
assertThat(aliases.contains(alias), is(true));
|
||||
assertThat(aliases.get(0).alias(), is(alias));
|
||||
assertThat(aliases.get(0).searchRouting(), is("0"));
|
||||
assertThat(aliases.get(0).indexRouting(), is("0"));
|
||||
assertThat(count, is(1L));
|
||||
|
||||
//cleanup
|
||||
@@ -153,12 +158,12 @@ public class AliasTests {
|
||||
String alias2 = "test-alias-2";
|
||||
|
||||
AliasQuery aliasQuery1 = new AliasBuilder()
|
||||
.withIndexName(INDEX_NAME)
|
||||
.withIndexName(INDEX_NAME_1)
|
||||
.withAliasName(alias1)
|
||||
.withIndexRouting("0").build();
|
||||
|
||||
AliasQuery aliasQuery2 = new AliasBuilder()
|
||||
.withIndexName(INDEX_NAME)
|
||||
.withIndexName(INDEX_NAME_2)
|
||||
.withAliasName(alias2)
|
||||
.withSearchRouting("1").build();
|
||||
|
||||
@@ -179,15 +184,17 @@ public class AliasTests {
|
||||
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
|
||||
SearchQuery query = new NativeSearchQueryBuilder().withQuery(matchAllQuery())
|
||||
.withIndices(alias2).withTypes(TYPE_NAME).build();
|
||||
long count = elasticsearchTemplate.count(query, SampleEntity.class);
|
||||
|
||||
// then
|
||||
Set<String> aliases = elasticsearchTemplate.queryForAlias(INDEX_NAME);
|
||||
assertThat(aliases, is(notNullValue()));
|
||||
assertThat(aliases.contains(alias1), is(true));
|
||||
assertThat(aliases.contains(alias2), is(true));
|
||||
assertThat(count, is(0L));
|
||||
List<AliasMetaData> responseAlias1 = elasticsearchTemplate.queryForAlias(INDEX_NAME_1);
|
||||
assertThat(responseAlias1, is(notNullValue()));
|
||||
assertThat(responseAlias1.get(0).alias(), is(alias1));
|
||||
assertThat(responseAlias1.get(0).indexRouting(), is("0"));
|
||||
|
||||
List<AliasMetaData> responseAlias2 = elasticsearchTemplate.queryForAlias(INDEX_NAME_2);
|
||||
assertThat(responseAlias2, is(notNullValue()));
|
||||
assertThat(responseAlias2.get(0).alias(), is(alias2));
|
||||
assertThat(responseAlias2.get(0).searchRouting(), is("1"));
|
||||
|
||||
//cleanup
|
||||
elasticsearchTemplate.removeAlias(aliasQuery1);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2014-2015 the original author or authors.
|
||||
* Copyright 2014-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -338,6 +338,8 @@ public class ElasticsearchTemplateTests {
|
||||
IndexQuery indexQuery = getIndexQuery(sampleEntity);
|
||||
|
||||
elasticsearchTemplate.index(indexQuery);
|
||||
elasticsearchTemplate.refresh(SampleEntity.class, true);
|
||||
|
||||
// when
|
||||
DeleteQuery deleteQuery = new DeleteQuery();
|
||||
deleteQuery.setQuery(termQuery("id", documentId));
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -60,8 +60,8 @@ public class MappingBuilderTests {
|
||||
@Test
|
||||
public void testInfiniteLoopAvoidance() throws IOException {
|
||||
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" +
|
||||
"type\":\"string\",\"index\":\"not_analyzed\",\"search_analyzer\":\"standard\"," +
|
||||
"\"index_analyzer\":\"standard\"}}}}";
|
||||
"type\":\"string\",\"index\":\"not_analyzed\"," +
|
||||
"\"analyzer\":\"standard\"}}}}";
|
||||
|
||||
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleTransientEntity.class, "mapping", "id", null);
|
||||
assertThat(xContentBuilder.string(), is(expected));
|
||||
@@ -115,8 +115,8 @@ public class MappingBuilderTests {
|
||||
@Test
|
||||
public void shouldBuildMappingWithSuperclass() throws IOException {
|
||||
final String expected = "{\"mapping\":{\"properties\":{\"message\":{\"store\":true,\"" +
|
||||
"type\":\"string\",\"index\":\"not_analyzed\",\"search_analyzer\":\"standard\"," +
|
||||
"\"index_analyzer\":\"standard\"},\"createdDate\":{\"store\":false," +
|
||||
"type\":\"string\",\"index\":\"not_analyzed\",\"analyzer\":\"standard\"}" +
|
||||
",\"createdDate\":{\"store\":false," +
|
||||
"\"type\":\"date\",\"index\":\"not_analyzed\"}}}}";
|
||||
|
||||
XContentBuilder xContentBuilder = MappingBuilder.buildMapping(SampleInheritedEntity.class, "mapping", "id", null);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -146,7 +146,7 @@ public class ElasticsearchTemplateGeoTests {
|
||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery, LocationMarkerEntity.class);
|
||||
|
||||
//then
|
||||
assertThat(geoAuthorsForGeoCriteria.size(), is(3));
|
||||
assertThat(geoAuthorsForGeoCriteria.size(), is(2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -180,7 +180,7 @@ public class ElasticsearchTemplateGeoTests {
|
||||
//given
|
||||
loadAnnotationBaseEntities();
|
||||
CriteriaQuery geoLocationCriteriaQuery = new CriteriaQuery(
|
||||
new Criteria("locationAsArray").within("u1044", "1km"));
|
||||
new Criteria("locationAsArray").within("u1044", "3km"));
|
||||
//when
|
||||
List<LocationMarkerEntity> geoAuthorsForGeoCriteria = elasticsearchTemplate.queryForList(geoLocationCriteriaQuery, LocationMarkerEntity.class);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,6 @@ import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import org.apache.lucene.util.CollectionUtil;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
Reference in New Issue
Block a user