Skip to content

Commit e4df537

Browse files
AntonLGVSsothawo
authored andcommitted
Added RefreshPolicy setter to the AbstractElasticsearchTemplate copy method.
Original Pull Request #1976 Closes #1978 (cherry picked from commit 8894dd3)
1 parent c1ab4d6 commit e4df537

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Diff for: src/main/java/org/springframework/data/elasticsearch/core/AbstractElasticsearchTemplate.java

+3
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@
7979
* @author Peter-Josef Meisch
8080
* @author Roman Puchkovskiy
8181
* @author Subhobrata Dey
82+
* @author Steven Pearce
83+
* @author Anton Naydenov
8284
*/
8385
public abstract class AbstractElasticsearchTemplate implements ElasticsearchOperations, ApplicationContextAware {
8486

@@ -116,6 +118,7 @@ private AbstractElasticsearchTemplate copy() {
116118
}
117119

118120
copy.setRoutingResolver(routingResolver);
121+
copy.setRefreshPolicy(refreshPolicy);
119122

120123
return copy;
121124
}

Diff for: src/test/java/org/springframework/data/elasticsearch/core/routing/ElasticsearchOperationsRoutingTests.java

+16
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
/**
4343
* @author Peter-Josef Meisch
44+
* @author Anton Naydenov
4445
*/
4546
@SuppressWarnings("ConstantConditions")
4647
@SpringIntegrationTest
@@ -118,6 +119,21 @@ void shouldStoreDataWithDifferentRoutingAndGetTheRoutingInTheSearchResult() {
118119
assertThat(searchHits.getSearchHit(0).getRouting()).isEqualTo(ID_2);
119120
}
120121

122+
@Test
123+
void shouldCreateACopyOfTheClientWithRefreshPolicy() {
124+
//given
125+
AbstractElasticsearchTemplate sourceTemplate = (AbstractElasticsearchTemplate) operations;
126+
SimpleElasticsearchMappingContext mappingContext = new SimpleElasticsearchMappingContext();
127+
DefaultRoutingResolver defaultRoutingResolver = new DefaultRoutingResolver(mappingContext);
128+
129+
//when
130+
ElasticsearchOperations operationsCopy = this.operations.withRouting(defaultRoutingResolver);
131+
AbstractElasticsearchTemplate copyTemplate = (AbstractElasticsearchTemplate) operationsCopy;
132+
133+
//then
134+
assertThat(sourceTemplate.getRefreshPolicy()).isEqualTo(copyTemplate.getRefreshPolicy());
135+
}
136+
121137
@Document(indexName = INDEX)
122138
@Setting(shards = 5)
123139
@Routing("routing")

0 commit comments

Comments
 (0)