Skip to content

Commit 608e064

Browse files
committed
Add test code to set refresh policy in deleteByQueryRequest method
Signed-off-by: 정준영/AI서비스개발팀/NE <abcdefssk1@gmail.com>
1 parent e562dfc commit 608e064

File tree

1 file changed

+41
-0
lines changed

1 file changed

+41
-0
lines changed

spring-data-opensearch/src/test/java/org/opensearch/data/client/orhlc/RequestFactoryTests.java

+41
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder;
3939
import org.opensearch.index.query.functionscore.FunctionScoreQueryBuilder.FilterFunctionBuilder;
4040
import org.opensearch.index.query.functionscore.GaussDecayFunctionBuilder;
41+
import org.opensearch.index.reindex.DeleteByQueryRequest;
4142
import org.opensearch.search.fetch.subphase.FetchSourceContext;
4243
import org.springframework.core.convert.support.GenericConversionService;
4344
import org.springframework.data.annotation.Id;
@@ -46,6 +47,7 @@
4647
import org.springframework.data.domain.Sort;
4748
import org.springframework.data.elasticsearch.annotations.Document;
4849
import org.springframework.data.elasticsearch.annotations.Field;
50+
import org.springframework.data.elasticsearch.core.RefreshPolicy;
4951
import org.springframework.data.elasticsearch.core.convert.MappingElasticsearchConverter;
5052
import org.springframework.data.elasticsearch.core.geo.GeoPoint;
5153
import org.springframework.data.elasticsearch.core.index.AliasAction;
@@ -1065,6 +1067,45 @@ void shouldUseIndexNameFromMethodIfNoneIsSetInQueryInBulkUpdate() {
10651067
assertThat(updateRequest.index()).isEqualTo(methodIndexName);
10661068
}
10671069

1070+
@Test
1071+
void shouldSetRefreshTrueIfRefreshPolicyIsImmediateInDeleteByQuery() {
1072+
String methodIndexName = "method-index-name";
1073+
Query searchQuery = new NativeSearchQueryBuilder()
1074+
.withQuery(matchAllQuery())
1075+
.build();
1076+
1077+
DeleteByQueryRequest deleteByQueryRequest = requestFactory.deleteByQueryRequest(searchQuery, null, Person.class,
1078+
IndexCoordinates.of(methodIndexName), RefreshPolicy.IMMEDIATE);
1079+
1080+
assertThat(deleteByQueryRequest.isRefresh()).isTrue();
1081+
}
1082+
1083+
@Test
1084+
void shouldSetRefreshFalseIfRefreshPolicyIsNoneInDeleteByQuery() {
1085+
String methodIndexName = "method-index-name";
1086+
Query searchQuery = new NativeSearchQueryBuilder()
1087+
.withQuery(matchAllQuery())
1088+
.build();
1089+
1090+
DeleteByQueryRequest deleteByQueryRequest = requestFactory.deleteByQueryRequest(searchQuery, null, Person.class,
1091+
IndexCoordinates.of(methodIndexName), RefreshPolicy.NONE);
1092+
1093+
assertThat(deleteByQueryRequest.isRefresh()).isFalse();
1094+
}
1095+
1096+
@Test
1097+
void shouldSetRefreshFalseIfRefreshPolicyIsWaitUntilInDeleteByQuery() {
1098+
String methodIndexName = "method-index-name";
1099+
Query searchQuery = new NativeSearchQueryBuilder()
1100+
.withQuery(matchAllQuery())
1101+
.build();
1102+
1103+
DeleteByQueryRequest deleteByQueryRequest = requestFactory.deleteByQueryRequest(searchQuery, null, Person.class,
1104+
IndexCoordinates.of(methodIndexName), RefreshPolicy.WAIT_UNTIL);
1105+
1106+
assertThat(deleteByQueryRequest.isRefresh()).isFalse();
1107+
}
1108+
10681109
// region entities
10691110
static class Person {
10701111
@Nullable

0 commit comments

Comments
 (0)