GJL commented on a change in pull request #11752:
URL: https://github.com/apache/flink/pull/11752#discussion_r422926775



##########
File path: 
flink-runtime/src/test/java/org/apache/flink/runtime/rest/handler/job/SubtaskAllExecutionAttemptsDetailsHandlerTest.java
##########
@@ -0,0 +1,176 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.flink.runtime.rest.handler.job;
+
+import org.apache.flink.api.common.JobID;
+import org.apache.flink.api.common.time.Time;
+import org.apache.flink.configuration.Configuration;
+import org.apache.flink.configuration.MetricOptions;
+import org.apache.flink.runtime.accumulators.StringifiedAccumulatorResult;
+import org.apache.flink.runtime.clusterframework.types.AllocationID;
+import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
+import org.apache.flink.runtime.execution.ExecutionState;
+import org.apache.flink.runtime.executiongraph.AccessExecutionVertex;
+import org.apache.flink.runtime.executiongraph.ArchivedExecution;
+import org.apache.flink.runtime.executiongraph.ArchivedExecutionJobVertex;
+import org.apache.flink.runtime.executiongraph.ArchivedExecutionVertex;
+import org.apache.flink.runtime.executiongraph.ExecutionAttemptID;
+import org.apache.flink.runtime.executiongraph.IOMetrics;
+import org.apache.flink.runtime.jobgraph.JobVertexID;
+import org.apache.flink.runtime.rest.handler.HandlerRequest;
+import org.apache.flink.runtime.rest.handler.HandlerRequestException;
+import org.apache.flink.runtime.rest.handler.RestHandlerConfiguration;
+import org.apache.flink.runtime.rest.handler.legacy.ExecutionGraphCache;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcher;
+import org.apache.flink.runtime.rest.handler.legacy.metrics.MetricFetcherImpl;
+import org.apache.flink.runtime.rest.messages.EmptyRequestBody;
+import org.apache.flink.runtime.rest.messages.JobIDPathParameter;
+import org.apache.flink.runtime.rest.messages.JobVertexIdPathParameter;
+import org.apache.flink.runtime.rest.messages.SubtaskIndexPathParameter;
+import 
org.apache.flink.runtime.rest.messages.job.SubtaskAllExecutionAttemptDetailsHeaders;
+import 
org.apache.flink.runtime.rest.messages.job.SubtaskAllExecutionAttemptsDetailsInfo;
+import org.apache.flink.runtime.rest.messages.job.SubtaskMessageParameters;
+import org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation;
+import org.apache.flink.runtime.taskmanager.TaskManagerLocation;
+import org.apache.flink.runtime.testingUtils.TestingUtils;
+import org.apache.flink.runtime.util.EvictingBoundedList;
+import org.apache.flink.util.TestLogger;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import java.util.Collections;
+import java.util.HashMap;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests of {@link SubtaskAllExecutionAttemptsDetailsHandler}.
+ */
+public class SubtaskAllExecutionAttemptsDetailsHandlerTest extends TestLogger {
+
+       private static HandlerRequest<EmptyRequestBody, 
SubtaskMessageParameters> testRequest;
+       private static SubtaskAllExecutionAttemptsDetailsHandler handler;
+       private static MetricFetcher metricFetcher;
+       private static final JobID JOBID = new JobID();
+       private static final JobVertexID JOB_VERTEXID = new JobVertexID();
+       private static final int SUBTASK_INDEX = 0;
+
+       @BeforeClass
+       public static void setUpClass() throws HandlerRequestException {
+               HashMap<String, String> receivedPathParameters = new 
HashMap<>(3);

Review comment:
       `new HashMap<>(3);` is wrong. The reason is that a HashMap's effective 
capacity is reduced by the load factor (default: 0.75), i.e., in your code, the 
items would still get rehashed. You can assure yourself by looking in the 
source code of `HashMap`.
   
   `HashMap#threshold`:
   ```
      /**
        * The next size value at which to resize (capacity * load factor).
        *
        * @serial
        */
       int threshold;
   ```
   
   `HashMap#putval()`:
   ```
           if (++size > threshold)
               resize();
   ```
   
   Also see 
https://stackoverflow.com/questions/564899/choosing-the-initial-capacity-of-a-hashset-with-an-expected-number-of-unique-val
   
   Also please revise the [Flink code 
style](https://flink.apache.org/contributing/code-style-and-quality-java.html#collections):
   > Set the initial capacity for a collection only if there is a good proven 
reason for that, otherwise do not clutter the code. In case of Maps it can be 
even deluding because the Map’s load factor effectively reduces the capacity.
   
   
   
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to