-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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
Fix a mappings update test #33146
Fix a mappings update test #33146
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,12 +16,15 @@ | |
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.cluster.metadata; | ||
|
||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingClusterStateUpdateRequest; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.ClusterStateTaskExecutor; | ||
import org.elasticsearch.cluster.service.ClusterService; | ||
import org.elasticsearch.common.compress.CompressedXContent; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.IndexService; | ||
import org.elasticsearch.plugins.Plugin; | ||
import org.elasticsearch.test.ESSingleNodeTestCase; | ||
|
@@ -31,6 +34,7 @@ | |
import java.util.Collections; | ||
|
||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.not; | ||
|
||
public class MetaDataMappingServiceTests extends ESSingleNodeTestCase { | ||
|
||
|
@@ -47,8 +51,18 @@ public void testMappingClusterStateUpdateDoesntChangeExistingIndices() throws Ex | |
final ClusterService clusterService = getInstanceFromNode(ClusterService.class); | ||
// TODO - it will be nice to get a random mapping generator | ||
final PutMappingClusterStateUpdateRequest request = new PutMappingClusterStateUpdateRequest().type("type"); | ||
request.source("{ \"properties\" { \"field\": { \"type\": \"text\" }}}"); | ||
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)); | ||
request.indices(new Index[] {indexService.index()}); | ||
request.source("{ \"properties\": { \"field\": { \"type\": \"text\" }}}"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line adds a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💥 |
||
final ClusterStateTaskExecutor.ClusterTasksResult<PutMappingClusterStateUpdateRequest> result = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is unchanged except now we capture the result of the cluster state update task. |
||
mappingService.putMappingExecutor.execute(clusterService.state(), Collections.singletonList(request)); | ||
// the task completed successfully | ||
assertThat(result.executionResults.size(), equalTo(1)); | ||
assertTrue(result.executionResults.values().iterator().next().isSuccess()); | ||
// the task really was a mapping update | ||
assertThat( | ||
indexService.mapperService().documentMapper("type").mappingSource(), | ||
not(equalTo(result.resultingState.metaData().index("test").mapping("type").source()))); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The above lines assert that the cluster state update task completed successfully and that if the result cluster state were committed then the mapping for the type would change. |
||
// since we never committed the cluster state update, the in-memory state is unchanged | ||
assertThat(indexService.mapperService().documentMapper("type").mappingSource(), equalTo(currentMapping)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We finally end with the existing assertion that the in-memory state of the mapping was not changed as a result of processing the mapping update. This is expected since the mapping update (the resulting cluster state) was never committed. |
||
} | ||
|
||
|
@@ -69,4 +83,5 @@ public void testClusterStateIsNotChangedWithIdenticalMappings() throws Exception | |
|
||
assertSame(result, result2); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line prevents a null pointer exception when handling the request.