galenwarren commented on a change in pull request #15599:
URL: https://github.com/apache/flink/pull/15599#discussion_r783115158



##########
File path: 
flink-filesystems/flink-gs-fs-hadoop/src/test/java/org/apache/flink/fs/gs/storage/MockBlobStorage.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.fs.gs.storage;
+
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.fs.gs.utils.BlobUtils;
+import org.apache.flink.fs.gs.utils.ChecksumUtils;
+
+import com.google.cloud.storage.StorageException;
+
+import javax.annotation.Nullable;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/** Mock blob storage implementation, using in-memory structures. */
+public class MockBlobStorage implements GSBlobStorage {
+
+    /** Mock blob value with metadata. */
+    public static class BlobValue {
+
+        public final byte[] content;
+
+        public BlobValue(byte[] content) {
+            this.content = content;
+        }
+    }
+
+    /** The mock blob metadata. */
+    static class BlobMetadata implements GSBlobStorage.BlobMetadata {
+
+        private final BlobValue blobValue;
+
+        private final String forcedChecksum;
+
+        BlobMetadata(BlobValue blobValue, String forcedChecksum) {
+            this.blobValue = blobValue;
+            this.forcedChecksum = forcedChecksum;
+        }
+
+        @Override
+        public String getChecksum() {
+            if (forcedChecksum != null) {
+                return forcedChecksum;
+            } else {
+                int checksum = 
ChecksumUtils.CRC_HASH_FUNCTION.hashBytes(blobValue.content).asInt();
+                return ChecksumUtils.convertChecksumToString(checksum);
+            }
+        }
+    }
+
+    /** The mock write channel, which writes to the memory-based storage. */
+    public class WriteChannel implements GSBlobStorage.WriteChannel {
+
+        private final GSBlobIdentifier blobIdentifier;
+
+        @Nullable public final MemorySize chunkSize;

Review comment:
       Done in 
[5821321](https://github.com/apache/flink/pull/15599/commits/5821321ce92a5d827b53ef882d6214dd6ed9bad5).

##########
File path: 
flink-filesystems/flink-gs-fs-hadoop/src/test/java/org/apache/flink/fs/gs/storage/MockBlobStorage.java
##########
@@ -0,0 +1,205 @@
+/*
+ * 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.fs.gs.storage;
+
+import org.apache.flink.configuration.MemorySize;
+import org.apache.flink.fs.gs.utils.BlobUtils;
+import org.apache.flink.fs.gs.utils.ChecksumUtils;
+
+import com.google.cloud.storage.StorageException;
+
+import javax.annotation.Nullable;
+
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.nio.channels.ClosedChannelException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
+
+/** Mock blob storage implementation, using in-memory structures. */
+public class MockBlobStorage implements GSBlobStorage {
+
+    /** Mock blob value with metadata. */
+    public static class BlobValue {
+
+        public final byte[] content;
+
+        public BlobValue(byte[] content) {
+            this.content = content;
+        }
+    }
+
+    /** The mock blob metadata. */
+    static class BlobMetadata implements GSBlobStorage.BlobMetadata {
+
+        private final BlobValue blobValue;
+
+        private final String forcedChecksum;
+
+        BlobMetadata(BlobValue blobValue, String forcedChecksum) {
+            this.blobValue = blobValue;
+            this.forcedChecksum = forcedChecksum;
+        }
+
+        @Override
+        public String getChecksum() {
+            if (forcedChecksum != null) {
+                return forcedChecksum;
+            } else {
+                int checksum = 
ChecksumUtils.CRC_HASH_FUNCTION.hashBytes(blobValue.content).asInt();
+                return ChecksumUtils.convertChecksumToString(checksum);
+            }
+        }
+    }
+
+    /** The mock write channel, which writes to the memory-based storage. */
+    public class WriteChannel implements GSBlobStorage.WriteChannel {
+
+        private final GSBlobIdentifier blobIdentifier;
+
+        @Nullable public final MemorySize chunkSize;
+
+        private final ByteArrayOutputStream stream;
+
+        private boolean closed;
+
+        WriteChannel(GSBlobIdentifier blobIdentifier, @Nullable MemorySize 
chunkSize) {
+            this.blobIdentifier = blobIdentifier;
+            this.stream = new ByteArrayOutputStream();
+            this.closed = false;
+            this.chunkSize = chunkSize;
+        }
+
+        @Override
+        public int write(byte[] content, int start, int length) throws 
IOException {
+            if (closed) {
+                throw new ClosedChannelException();
+            }
+
+            int writeCount = Math.min(length, maxWriteCount);
+            stream.write(content, start, writeCount);
+            return writeCount;
+        }
+
+        @Override
+        public void close() throws IOException {
+            if (!closed) {
+                stream.close();
+                blobs.put(blobIdentifier, new BlobValue(stream.toByteArray()));
+                closed = true;
+            }
+        }
+    }
+
+    /** The blobs in the mock storage. */
+    public final Map<GSBlobIdentifier, BlobValue> blobs;
+
+    /** Set this to force a checksum value to be returned. */
+    public String forcedChecksum;

Review comment:
       Done in 
[5821321](https://github.com/apache/flink/pull/15599/commits/5821321ce92a5d827b53ef882d6214dd6ed9bad5).




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to