Copilot commented on code in PR #10236: URL: https://github.com/apache/gravitino/pull/10236#discussion_r2888216471
########## maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/integration/test/RecordingJobSubmitterForIT.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.gravitino.maintenance.optimizer.integration.test; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import org.apache.gravitino.maintenance.optimizer.api.recommender.JobExecutionContext; +import org.apache.gravitino.maintenance.optimizer.api.recommender.JobSubmitter; +import org.apache.gravitino.maintenance.optimizer.common.OptimizerEnv; +import org.apache.gravitino.maintenance.optimizer.common.conf.OptimizerConfig; + +public class RecordingJobSubmitterForIT implements JobSubmitter { + public static final String NAME = "recording-job-submitter-it"; + public static final String SESSION_ID_KEY = + OptimizerConfig.JOB_SUBMITTER_CONFIG_PREFIX + "recording-session-id"; + + private static final Map<String, List<JobExecutionContext>> SUBMITTED_CONTEXTS_BY_SESSION = + new ConcurrentHashMap<>(); + + private String sessionId; + + public static void reset(String sessionId) { + SUBMITTED_CONTEXTS_BY_SESSION.put(sessionId, new CopyOnWriteArrayList<>()); + } + + public static List<JobExecutionContext> submittedContexts(String sessionId) { + return List.copyOf( + SUBMITTED_CONTEXTS_BY_SESSION.getOrDefault(sessionId, new CopyOnWriteArrayList<>())); Review Comment: submittedContexts() allocates a new CopyOnWriteArrayList as the default value on every call when the sessionId is missing. Using List.of() as the default (or checking containsKey first) would avoid unnecessary allocation in this test utility. ```suggestion List<JobExecutionContext> contexts = SUBMITTED_CONTEXTS_BY_SESSION.get(sessionId); if (contexts == null) { return List.of(); } return List.copyOf(contexts); ``` ########## maintenance/optimizer/src/test/java/org/apache/gravitino/maintenance/optimizer/integration/test/RecordingJobSubmitterForIT.java: ########## @@ -0,0 +1,79 @@ +/* + * 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.gravitino.maintenance.optimizer.integration.test; + +import java.util.List; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.CopyOnWriteArrayList; +import org.apache.gravitino.maintenance.optimizer.api.recommender.JobExecutionContext; +import org.apache.gravitino.maintenance.optimizer.api.recommender.JobSubmitter; +import org.apache.gravitino.maintenance.optimizer.common.OptimizerEnv; +import org.apache.gravitino.maintenance.optimizer.common.conf.OptimizerConfig; + +public class RecordingJobSubmitterForIT implements JobSubmitter { + public static final String NAME = "recording-job-submitter-it"; + public static final String SESSION_ID_KEY = + OptimizerConfig.JOB_SUBMITTER_CONFIG_PREFIX + "recording-session-id"; + + private static final Map<String, List<JobExecutionContext>> SUBMITTED_CONTEXTS_BY_SESSION = + new ConcurrentHashMap<>(); + + private String sessionId; + + public static void reset(String sessionId) { + SUBMITTED_CONTEXTS_BY_SESSION.put(sessionId, new CopyOnWriteArrayList<>()); + } + + public static List<JobExecutionContext> submittedContexts(String sessionId) { + return List.copyOf( + SUBMITTED_CONTEXTS_BY_SESSION.getOrDefault(sessionId, new CopyOnWriteArrayList<>())); + } + + public static void clear(String sessionId) { + SUBMITTED_CONTEXTS_BY_SESSION.remove(sessionId); + } + + @Override + public String submitJob(String jobTemplateName, JobExecutionContext jobExecutionContext) { + List<JobExecutionContext> submittedContexts = + SUBMITTED_CONTEXTS_BY_SESSION.computeIfAbsent( + sessionId, key -> new CopyOnWriteArrayList<>()); + submittedContexts.add(jobExecutionContext); + return "it-job-" + submittedContexts.size(); + } + + @Override + public String name() { + return NAME; + } + + @Override + public void initialize(OptimizerEnv optimizerEnv) { + this.sessionId = optimizerEnv.config().getAllConfig().get(SESSION_ID_KEY); + if (sessionId == null || sessionId.isEmpty()) { + throw new IllegalArgumentException( + "Missing test session id config for RecordingJobSubmitterForIT: " + SESSION_ID_KEY); + } Review Comment: RecordingJobSubmitterForIT reads the session id from optimizerEnv.config().getAllConfig() using the full prefixed key. Since OptimizerConfig already provides jobSubmitterConfigs() with the prefix stripped, it would be more robust/consistent to read from optimizerEnv.config().jobSubmitterConfigs() (and define SESSION_ID_KEY without the global prefix). This keeps test providers aligned with how real JobSubmitter implementations are expected to consume config. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
