Skip to content

Fix ReactiveIndicesTemplate: Refresh not called on bound indices #2441 #2444

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 3, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ public Mono<Boolean> exists() {

@Override
public Mono<Void> refresh() {
return Mono.from(execute(ReactiveElasticsearchIndicesClient::refresh)).then();
RefreshRequest refreshRequest = requestConverter.indicesRefreshRequest(getIndexCoordinates());
return Mono.from(execute(client -> client.refresh(refreshRequest))).then();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* Copyright 2021-2023 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.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.data.elasticsearch.client.elc;

import co.elastic.clients.elasticsearch.indices.RefreshRequest;
import co.elastic.clients.json.JsonpMapper;
import co.elastic.clients.transport.ElasticsearchTransport;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.data.elasticsearch.core.convert.ElasticsearchConverter;
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;

import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.*;

/**
* @author Urs Keller
* @since 5.0
*/
@ExtendWith(MockitoExtension.class)
class ReactiveIndicesTemplateTest {
@Mock private ElasticsearchConverter elasticsearchConverter;
@Mock private ReactiveElasticsearchIndicesClient client;
@Mock private ElasticsearchTransport transport;
@Mock private JsonpMapper jsonpMapper;
@Captor ArgumentCaptor<RefreshRequest> refreshRequest;

@BeforeEach
void setup() {
doReturn(transport).when(client)._transport();
doReturn(jsonpMapper).when(transport).jsonpMapper();
}

/**
* Tests that refresh is called with the indices bound to the template
*/
@Test
void refresh() {
IndexCoordinates indexCoordinate = IndexCoordinates.of("i1", "i2");
ReactiveIndicesTemplate template = new ReactiveIndicesTemplate(client, elasticsearchConverter, indexCoordinate);
doReturn(Mono.empty()).when(client).refresh(any(RefreshRequest.class));

template.refresh().as(StepVerifier::create).verifyComplete();

verify(client).refresh(refreshRequest.capture());
assertEquals(List.of("i1", "i2"), refreshRequest.getValue().index());

verifyNoMoreInteractions(elasticsearchConverter, client, transport, jsonpMapper);
}
}