|
21 | 21 | import org.elasticsearch.action.bulk.BulkResponse;
|
22 | 22 | import org.elasticsearch.action.index.IndexRequestBuilder;
|
23 | 23 | import org.elasticsearch.action.index.IndexResponse;
|
| 24 | +import org.elasticsearch.cluster.metadata.MetaDataCreateIndexService; |
24 | 25 | import org.elasticsearch.index.VersionType;
|
| 26 | +import org.elasticsearch.indices.InvalidIndexNameException; |
25 | 27 | import org.elasticsearch.test.ElasticsearchIntegrationTest;
|
26 | 28 | import org.elasticsearch.test.junit.annotations.TestLogging;
|
27 | 29 | import org.junit.Test;
|
28 | 30 |
|
29 | 31 | import java.util.ArrayList;
|
30 | 32 | import java.util.List;
|
| 33 | +import java.util.Locale; |
31 | 34 | import java.util.Random;
|
32 | 35 | import java.util.concurrent.Callable;
|
33 | 36 | import java.util.concurrent.ExecutorService;
|
@@ -177,4 +180,39 @@ public void testCreateFlagWithBulk() {
|
177 | 180 | IndexResponse indexResponse = bulkResponse.getItems()[0].getResponse();
|
178 | 181 | assertTrue(indexResponse.isCreated());
|
179 | 182 | }
|
| 183 | + |
| 184 | + @Test |
| 185 | + public void testCreateIndexWithLongName() { |
| 186 | + int min = MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES + 1; |
| 187 | + int max = MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES * 2; |
| 188 | + try { |
| 189 | + createIndex(randomAsciiOfLengthBetween(min, max).toLowerCase(Locale.ROOT)); |
| 190 | + fail("exception should have been thrown on too-long index name"); |
| 191 | + } catch (InvalidIndexNameException e) { |
| 192 | + assertThat("exception contains message about index name too long: " + e.getMessage(), |
| 193 | + e.getMessage().contains("index name is too long,"), equalTo(true)); |
| 194 | + } |
| 195 | + |
| 196 | + try { |
| 197 | + client().prepareIndex(randomAsciiOfLengthBetween(min, max).toLowerCase(Locale.ROOT), "mytype").setSource("foo", "bar").get(); |
| 198 | + fail("exception should have been thrown on too-long index name"); |
| 199 | + } catch (InvalidIndexNameException e) { |
| 200 | + assertThat("exception contains message about index name too long: " + e.getMessage(), |
| 201 | + e.getMessage().contains("index name is too long,"), equalTo(true)); |
| 202 | + } |
| 203 | + |
| 204 | + try { |
| 205 | + // Catch chars that are more than a single byte |
| 206 | + client().prepareIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES -1).toLowerCase(Locale.ROOT) + |
| 207 | + "Ϟ".toLowerCase(Locale.ROOT), |
| 208 | + "mytype").setSource("foo", "bar").get(); |
| 209 | + fail("exception should have been thrown on too-long index name"); |
| 210 | + } catch (InvalidIndexNameException e) { |
| 211 | + assertThat("exception contains message about index name too long: " + e.getMessage(), |
| 212 | + e.getMessage().contains("index name is too long,"), equalTo(true)); |
| 213 | + } |
| 214 | + |
| 215 | + // we can create an index of max length |
| 216 | + createIndex(randomAsciiOfLength(MetaDataCreateIndexService.MAX_INDEX_NAME_BYTES).toLowerCase(Locale.ROOT)); |
| 217 | + } |
180 | 218 | }
|
0 commit comments