You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@beam.apache.org by GitBox <gi...@apache.org> on 2020/05/14 22:19:33 UTC

[GitHub] [beam] robertwb commented on a change in pull request #11708: [BEAM-9577] Artifact v2 support for uber jars.

robertwb commented on a change in pull request #11708:
URL: https://github.com/apache/beam/pull/11708#discussion_r425462707



##########
File path: sdks/java/core/src/test/java/org/apache/beam/sdk/io/ClassLoaderFileSystemTest.java
##########
@@ -0,0 +1,57 @@
+/*
+ * 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.beam.sdk.io;
+
+import static java.nio.channels.Channels.newInputStream;
+import static org.junit.Assert.assertArrayEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.nio.channels.ReadableByteChannel;
+import org.apache.beam.sdk.options.PipelineOptionsFactory;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+@RunWith(JUnit4.class)
+public class ClassLoaderFileSystemTest {
+
+  private static final String SOME_CLASS =
+      "classpath://org/apache/beam/sdk/io/ClassLoaderFilesystem.class";
+
+  @Test
+  public void testOpen() throws IOException {
+    ClassLoaderFileSystem filesystem = new ClassLoaderFileSystem();
+    ReadableByteChannel channel = filesystem.open(filesystem.matchNewResource(SOME_CLASS, false));
+    checkIsClass(channel);
+  }
+
+  @Test
+  public void testRegistrar() throws IOException {
+    ReadableByteChannel channel = FileSystems.open(FileSystems.matchNewResource(SOME_CLASS, false));
+    checkIsClass(channel);
+  }
+
+  public void checkIsClass(ReadableByteChannel channel) throws IOException {
+    FileSystems.setDefaultPipelineOptions(PipelineOptionsFactory.create());
+    InputStream inputStream = newInputStream(channel);
+    byte[] magic = new byte[4];
+    inputStream.read(magic);
+    assertArrayEquals(magic, new byte[] {(byte) 0xCA, (byte) 0xFE, (byte) 0xBA, (byte) 0xBE});

Review comment:
       It's used on the Python side.




----------------------------------------------------------------
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:
users@infra.apache.org