diff --git a/server/src/main/java/org/elasticsearch/common/util/Maps.java b/server/src/main/java/org/elasticsearch/common/util/Maps.java index a7934c89ead88..02b3b596778ca 100644 --- a/server/src/main/java/org/elasticsearch/common/util/Maps.java +++ b/server/src/main/java/org/elasticsearch/common/util/Maps.java @@ -280,7 +280,7 @@ public static Map newMapWithExpectedSize(int expectedSize) { * @return a new pre-sized {@link HashMap} */ public static Map newHashMapWithExpectedSize(int expectedSize) { - return new HashMap<>(capacity(expectedSize)); + return HashMap.newHashMap(expectedSize); } /** @@ -292,7 +292,7 @@ public static Map newHashMapWithExpectedSize(int expectedSize) { * @return a new pre-sized {@link HashMap} */ public static Map newConcurrentHashMapWithExpectedSize(int expectedSize) { - return new ConcurrentHashMap<>(capacity(expectedSize)); + return new ConcurrentHashMap<>(expectedSize); } /** @@ -304,12 +304,7 @@ public static Map newConcurrentHashMapWithExpectedSize(int expected * @return a new pre-sized {@link LinkedHashMap} */ public static LinkedHashMap newLinkedHashMapWithExpectedSize(int expectedSize) { - return new LinkedHashMap<>(capacity(expectedSize)); - } - - static int capacity(int expectedSize) { - assert expectedSize >= 0; - return expectedSize < 2 ? expectedSize + 1 : (int) (expectedSize / 0.75 + 1.0); + return LinkedHashMap.newLinkedHashMap(expectedSize); } /** diff --git a/server/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java b/server/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java index 93e0ac6a9567c..5f397361f28c5 100644 --- a/server/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/ClusterStateTests.java @@ -293,25 +293,25 @@ public void testToXContentWithMultipleProjects() throws IOException { }, "projects": [ { - "id": "tb5W0bx765nDVIwqJPw92G", + "id": "3LftaL7hgfXAsF60Gm6jcD", "indices": { - "common-index": { - "9": { + "another-index": { + "5": { "retryable": false, - "description": "index metadata (api)", - "levels": [ "metadata_read", "metadata_write"] + "description": "index read-only (api)", + "levels": [ "write", "metadata_write"] } } } }, { - "id": "3LftaL7hgfXAsF60Gm6jcD", + "id": "tb5W0bx765nDVIwqJPw92G", "indices": { - "another-index": { - "5": { + "common-index": { + "9": { "retryable": false, - "description": "index read-only (api)", - "levels": [ "write", "metadata_write"] + "description": "index metadata (api)", + "levels": [ "metadata_read", "metadata_write"] } } } @@ -468,40 +468,7 @@ public void testToXContentWithMultipleProjects() throws IOException { "voting_config_exclusions": [] }, "projects": [ - { - "id": "tb5W0bx765nDVIwqJPw92G", - "templates": {}, - "indices": { - "common-index": { - "version": 2, - "mapping_version": 1, - "settings_version": 1, - "aliases_version": 1, - "routing_num_shards": 3, - "state": "open", - "settings": { - "index": { - "number_of_shards": "3", - "number_of_replicas": "1", - "uuid": "tE62Ga40yvlmOSujUvruVw", - "version": { "created": "%s" } - } - }, - "mappings": {}, - "aliases": [], - "primary_terms": { "0":0, "1":0, "2":0 }, - "in_sync_allocations": { "0":[], "1":[], "2":[] }, - "rollover_info": {}, - "mappings_updated_version": %s, - "system": false, - "timestamp_range": { "shards":[] }, - "event_ingested_range": { "shards": [] } - } - }, - "index-graveyard": { "tombstones": [] }, - "reserved_state": {} - }, - { + { "id": "3LftaL7hgfXAsF60Gm6jcD", "templates": {}, "indices": { @@ -559,12 +526,45 @@ public void testToXContentWithMultipleProjects() throws IOException { "index-graveyard": { "tombstones": [] }, "reserved_state": {} }, - { + { "id": "WHyuJ0uqBYOPgHX9kYUXlZ", "templates": {}, "indices": {}, "index-graveyard": { "tombstones": [] }, "reserved_state": {} + }, + { + "id": "tb5W0bx765nDVIwqJPw92G", + "templates": {}, + "indices": { + "common-index": { + "version": 2, + "mapping_version": 1, + "settings_version": 1, + "aliases_version": 1, + "routing_num_shards": 3, + "state": "open", + "settings": { + "index": { + "number_of_shards": "3", + "number_of_replicas": "1", + "uuid": "tE62Ga40yvlmOSujUvruVw", + "version": { "created": "%s" } + } + }, + "mappings": {}, + "aliases": [], + "primary_terms": { "0":0, "1":0, "2":0 }, + "in_sync_allocations": { "0":[], "1":[], "2":[] }, + "rollover_info": {}, + "mappings_updated_version": %s, + "system": false, + "timestamp_range": { "shards":[] }, + "event_ingested_range": { "shards": [] } + } + }, + "index-graveyard": { "tombstones": [] }, + "reserved_state": {} } ], "reserved_state": {} @@ -812,14 +812,14 @@ public void testToXContentWithMultipleProjects() throws IOException { Version.CURRENT, IndexVersions.MINIMUM_COMPATIBLE, IndexVersion.current(), - // project:tb5W0bx765nDVIwqJPw92G index:common-index - IndexVersion.current(), - IndexVersion.current(), // project:3LftaL7hgfXAsF60Gm6jcD index:another-index IndexVersion.current(), IndexVersion.current(), // project:3LftaL7hgfXAsF60Gm6jcD index:common-index IndexVersion.current(), + IndexVersion.current(), + // project:tb5W0bx765nDVIwqJPw92G index:common-index + IndexVersion.current(), IndexVersion.current() ); diff --git a/server/src/test/java/org/elasticsearch/common/util/MapsTests.java b/server/src/test/java/org/elasticsearch/common/util/MapsTests.java index e75293326da40..d097e63f49ce3 100644 --- a/server/src/test/java/org/elasticsearch/common/util/MapsTests.java +++ b/server/src/test/java/org/elasticsearch/common/util/MapsTests.java @@ -32,7 +32,6 @@ import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThan; import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.lessThanOrEqualTo; public class MapsTests extends ESTestCase { @@ -270,22 +269,6 @@ public void testFlatten() { } } - public void testCapacityIsEnoughForMapToNotBeResized() { - for (int i = 0; i < 1000; i++) { - int size = randomIntBetween(0, 1_000_000); - int capacity = Maps.capacity(size); - assertThat(size, lessThanOrEqualTo((int) (capacity * 0.75f))); - } - } - - public void testCapacityForMaxSize() { - assertEquals(Integer.MAX_VALUE, Maps.capacity(Integer.MAX_VALUE)); - } - - public void testCapacityForZeroSize() { - assertEquals(1, Maps.capacity(0)); - } - @SuppressWarnings("unchecked") private static Object deepGet(String path, Object obj) { Object cur = obj;