|
50 | 50 | import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; |
51 | 51 | import org.elasticsearch.action.admin.indices.rollover.RolloverRequest; |
52 | 52 | import org.elasticsearch.action.admin.indices.rollover.RolloverResponse; |
53 | | -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsRequest; |
54 | | -import org.elasticsearch.action.admin.indices.settings.put.UpdateSettingsResponse; |
55 | 53 | import org.elasticsearch.action.admin.indices.shrink.ResizeRequest; |
56 | 54 | import org.elasticsearch.action.admin.indices.shrink.ResizeResponse; |
57 | 55 | import org.elasticsearch.action.admin.indices.shrink.ResizeType; |
58 | 56 | import org.elasticsearch.action.index.IndexRequest; |
59 | 57 | import org.elasticsearch.action.support.IndicesOptions; |
60 | 58 | import org.elasticsearch.action.support.WriteRequest; |
61 | 59 | import org.elasticsearch.action.support.broadcast.BroadcastResponse; |
62 | | -import org.elasticsearch.cluster.metadata.IndexMetaData; |
63 | | -import org.elasticsearch.common.settings.Setting; |
64 | 60 | import org.elasticsearch.common.settings.Settings; |
65 | 61 | import org.elasticsearch.common.unit.ByteSizeUnit; |
66 | 62 | import org.elasticsearch.common.unit.ByteSizeValue; |
67 | 63 | import org.elasticsearch.common.unit.TimeValue; |
68 | 64 | import org.elasticsearch.common.xcontent.XContentBuilder; |
69 | 65 | import org.elasticsearch.common.xcontent.json.JsonXContent; |
70 | 66 | import org.elasticsearch.common.xcontent.support.XContentMapValues; |
71 | | -import org.elasticsearch.index.IndexSettings; |
72 | 67 | import org.elasticsearch.rest.RestStatus; |
73 | 68 |
|
74 | 69 | import java.io.IOException; |
|
78 | 73 | import static org.hamcrest.CoreMatchers.hasItem; |
79 | 74 | import static org.hamcrest.Matchers.equalTo; |
80 | 75 | import static org.hamcrest.Matchers.not; |
81 | | -import static org.hamcrest.Matchers.startsWith; |
82 | 76 |
|
83 | 77 | public class IndicesClientIT extends ESRestHighLevelClientTestCase { |
84 | 78 |
|
@@ -617,97 +611,4 @@ public void testRollover() throws IOException { |
617 | 611 | assertEquals("test_new", rolloverResponse.getNewIndex()); |
618 | 612 | } |
619 | 613 | } |
620 | | - |
621 | | - public void testIndexPutSettings() throws IOException { |
622 | | - |
623 | | - final Setting<Integer> dynamicSetting = IndexMetaData.INDEX_NUMBER_OF_REPLICAS_SETTING; |
624 | | - final String dynamicSettingKey = IndexMetaData.SETTING_NUMBER_OF_REPLICAS; |
625 | | - final int dynamicSettingValue = 0; |
626 | | - |
627 | | - final Setting<String> staticSetting = IndexSettings.INDEX_CHECK_ON_STARTUP; |
628 | | - final String staticSettingKey = IndexSettings.INDEX_CHECK_ON_STARTUP.getKey(); |
629 | | - final String staticSettingValue = "true"; |
630 | | - |
631 | | - final Setting<Integer> unmodifiableSetting = IndexMetaData.INDEX_NUMBER_OF_SHARDS_SETTING; |
632 | | - final String unmodifiableSettingKey = IndexMetaData.SETTING_NUMBER_OF_SHARDS; |
633 | | - final int unmodifiableSettingValue = 3; |
634 | | - |
635 | | - String index = "index"; |
636 | | - createIndex(index, Settings.EMPTY); |
637 | | - |
638 | | - assertThat(dynamicSetting.getDefault(Settings.EMPTY), not(dynamicSettingValue)); |
639 | | - UpdateSettingsRequest dynamicSettingRequest = new UpdateSettingsRequest(); |
640 | | - dynamicSettingRequest.settings(Settings.builder().put(dynamicSettingKey, dynamicSettingValue).build()); |
641 | | - UpdateSettingsResponse response = execute(dynamicSettingRequest, highLevelClient().indices()::putSettings, |
642 | | - highLevelClient().indices()::putSettingsAsync); |
643 | | - |
644 | | - assertTrue(response.isAcknowledged()); |
645 | | - Map<String, Object> indexSettingsAsMap = getIndexSettingsAsMap(index); |
646 | | - assertThat(indexSettingsAsMap.get(dynamicSettingKey), equalTo(String.valueOf(dynamicSettingValue))); |
647 | | - |
648 | | - assertThat(staticSetting.getDefault(Settings.EMPTY), not(staticSettingValue)); |
649 | | - UpdateSettingsRequest staticSettingRequest = new UpdateSettingsRequest(); |
650 | | - staticSettingRequest.settings(Settings.builder().put(staticSettingKey, staticSettingValue).build()); |
651 | | - ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(staticSettingRequest, |
652 | | - highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync)); |
653 | | - assertThat(exception.getMessage(), |
654 | | - startsWith("Elasticsearch exception [type=illegal_argument_exception, " |
655 | | - + "reason=Can't update non dynamic settings [[index.shard.check_on_startup]] for open indices [[index/")); |
656 | | - |
657 | | - indexSettingsAsMap = getIndexSettingsAsMap(index); |
658 | | - assertNull(indexSettingsAsMap.get(staticSettingKey)); |
659 | | - |
660 | | - closeIndex(index); |
661 | | - response = execute(staticSettingRequest, highLevelClient().indices()::putSettings, |
662 | | - highLevelClient().indices()::putSettingsAsync); |
663 | | - assertTrue(response.isAcknowledged()); |
664 | | - openIndex(index); |
665 | | - indexSettingsAsMap = getIndexSettingsAsMap(index); |
666 | | - assertThat(indexSettingsAsMap.get(staticSettingKey), equalTo(staticSettingValue)); |
667 | | - |
668 | | - assertThat(unmodifiableSetting.getDefault(Settings.EMPTY), not(unmodifiableSettingValue)); |
669 | | - UpdateSettingsRequest unmodifiableSettingRequest = new UpdateSettingsRequest(); |
670 | | - unmodifiableSettingRequest.settings(Settings.builder().put(unmodifiableSettingKey, unmodifiableSettingValue).build()); |
671 | | - exception = expectThrows(ElasticsearchException.class, () -> execute(unmodifiableSettingRequest, |
672 | | - highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync)); |
673 | | - assertThat(exception.getMessage(), startsWith( |
674 | | - "Elasticsearch exception [type=illegal_argument_exception, " |
675 | | - + "reason=Can't update non dynamic settings [[index.number_of_shards]] for open indices [[index/")); |
676 | | - closeIndex(index); |
677 | | - exception = expectThrows(ElasticsearchException.class, () -> execute(unmodifiableSettingRequest, |
678 | | - highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync)); |
679 | | - assertThat(exception.getMessage(), startsWith( |
680 | | - "Elasticsearch exception [type=illegal_argument_exception, " |
681 | | - + "reason=final index setting [index.number_of_shards], not updateable")); |
682 | | - } |
683 | | - |
684 | | - @SuppressWarnings("unchecked") |
685 | | - private Map<String, Object> getIndexSettingsAsMap(String index) throws IOException { |
686 | | - Map<String, Object> indexSettings = getIndexSettings(index); |
687 | | - return (Map<String, Object>)((Map<String, Object>) indexSettings.get(index)).get("settings"); |
688 | | - } |
689 | | - |
690 | | - public void testIndexPutSettingNonExistent() throws IOException { |
691 | | - |
692 | | - String index = "index"; |
693 | | - UpdateSettingsRequest indexUpdateSettingsRequest = new UpdateSettingsRequest(index); |
694 | | - String setting = "no_idea_what_you_are_talking_about"; |
695 | | - int value = 10; |
696 | | - indexUpdateSettingsRequest.settings(Settings.builder().put(setting, value).build()); |
697 | | - |
698 | | - ElasticsearchException exception = expectThrows(ElasticsearchException.class, () -> execute(indexUpdateSettingsRequest, |
699 | | - highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync)); |
700 | | - assertEquals(RestStatus.NOT_FOUND, exception.status()); |
701 | | - assertThat(exception.getMessage(), equalTo("Elasticsearch exception [type=index_not_found_exception, reason=no such index]")); |
702 | | - |
703 | | - createIndex(index, Settings.EMPTY); |
704 | | - exception = expectThrows(ElasticsearchException.class, () -> execute(indexUpdateSettingsRequest, |
705 | | - highLevelClient().indices()::putSettings, highLevelClient().indices()::putSettingsAsync)); |
706 | | - assertThat(exception.status(), equalTo(RestStatus.BAD_REQUEST)); |
707 | | - assertThat(exception.getMessage(), equalTo( |
708 | | - "Elasticsearch exception [type=illegal_argument_exception, " |
709 | | - + "reason=unknown setting [index.no_idea_what_you_are_talking_about] please check that any required plugins are installed, " |
710 | | - + "or check the breaking changes documentation for removed settings]")); |
711 | | - } |
712 | | - |
713 | 614 | } |
0 commit comments