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