uce commented on a change in pull request #7717: [FLINK-11533] [container] Add 
option parse JAR manifest for jobClassName
URL: https://github.com/apache/flink/pull/7717#discussion_r258530978
 
 

 ##########
 File path: 
flink-container/src/test/java/org/apache/flink/container/entrypoint/JarManifestParserTest.java
 ##########
 @@ -0,0 +1,146 @@
+/*
+ * 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.container.entrypoint;
+
+import org.apache.flink.client.program.PackagedProgram;
+
+import org.apache.flink.shaded.guava18.com.google.common.collect.ImmutableMap;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.util.Map;
+import java.util.Optional;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
+
+import static org.hamcrest.CoreMatchers.equalTo;
+import static org.hamcrest.core.Is.is;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for JAR file manifest parsing.
+ */
+public class JarManifestParserTest {
+
+       @Rule
+       public TemporaryFolder temporaryFolder = new TemporaryFolder();
+
+       @Test
+       public void testFindFirstWithEmptyJar() throws IOException {
+               File jarFile = createJarFileWithManifest(ImmutableMap.of());
+
+               Optional<String> entry = 
JarManifestParser.findFirstManifestAttribute(jarFile, "attribute-1", 
"attribute-2");
+
+               assertFalse(entry.isPresent());
+       }
+
+       @Test
+       public void testFindFirstWithMultipleAttributes() throws IOException {
+               File jarFile = 
createJarFileWithManifest(ImmutableMap.of("attribute-1", "value-1", 
"attribute-2", "value-2"));
+
+               Optional<String> entry = 
JarManifestParser.findFirstManifestAttribute(jarFile, "attribute-1", 
"attribute-2");
+
+               assertTrue(entry.isPresent());
+               assertThat(entry.get(), is(equalTo("value-1")));
+       }
+
+       @Test
+       public void testFindFirstWithMultipleAttributesRespectOrder() throws 
IOException {
+               File jarFile = 
createJarFileWithManifest(ImmutableMap.of("attribute-1", "value-1", 
"attribute-2", "value-2"));
+
+               Optional<String> entry = 
JarManifestParser.findFirstManifestAttribute(jarFile, "attribute-2", 
"attribute-1");
+
+               assertTrue(entry.isPresent());
+               assertThat(entry.get(), is(equalTo("value-2")));
+       }
+
+       @Test
+       public void testFindEntryClassNoEntry() throws IOException {
+               File jarFile = createJarFileWithManifest(ImmutableMap.of());
+
+               Optional<String> entry = 
JarManifestParser.findEntryClass(jarFile);
+
+               assertFalse(entry.isPresent());
+       }
+
+       @Test
+       public void testFindEntryClassAssemblerClass() throws IOException {
+               File jarFile = createJarFileWithManifest(ImmutableMap.of(
+                       PackagedProgram.MANIFEST_ATTRIBUTE_ASSEMBLER_CLASS, 
"AssemblerClass"));
+
+               Optional<String> entry = 
JarManifestParser.findEntryClass(jarFile);
+
+               assertTrue(entry.isPresent());
+               assertThat(entry.get(), is(equalTo("AssemblerClass")));
+       }
+
+       @Test
+       public void testFindEntryClassMainClass() throws IOException {
+               File jarFile = createJarFileWithManifest(ImmutableMap.of(
+                       PackagedProgram.MANIFEST_ATTRIBUTE_MAIN_CLASS, 
"MainClass"));
+
+               Optional<String> entry = 
JarManifestParser.findEntryClass(jarFile);
+
+               assertTrue(entry.isPresent());
+               assertThat(entry.get(), is(equalTo("MainClass")));
+       }
+
+       @Test
+       public void testFindEntryClassAssemblerClassAndMainClass() throws 
IOException {
+               // We want the assembler class entry to have precedence over 
main class
 
 Review comment:
   I agree, but I think we should follow the practice of `PackagedProgram`. 
This is only relevant for the corner of having both specified.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to