You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ga...@apache.org on 2022/10/14 13:11:24 UTC
[jclouds] branch master updated: This fixes problem JCLOUDS 1615.
This is an automated email from the ASF dual-hosted git repository.
gaul pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jclouds.git
The following commit(s) were added to refs/heads/master by this push:
new b2a2025b32 This fixes problem JCLOUDS 1615.
b2a2025b32 is described below
commit b2a2025b32c7c3c0ca50cd7769353c59c6fabe8d
Author: Christian.Jung <Ch...@ptvgroup.com>
AuthorDate: Thu Sep 15 08:38:34 2022 +0200
This fixes problem JCLOUDS 1615.
---
.../azureblob/blobstore/AzureBlobStore.java | 8 +++-
.../azureblob/blobstore/AzureBlobStoreTest.java | 55 ++++++++++++++++++++++
2 files changed, 61 insertions(+), 2 deletions(-)
diff --git a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java
index a2bf864d61..b05b4895b0 100644
--- a/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java
+++ b/providers/azureblob/src/main/java/org/jclouds/azureblob/blobstore/AzureBlobStore.java
@@ -434,15 +434,19 @@ public class AzureBlobStore extends BaseBlobStore {
ImmutableList.Builder<String> blocks = ImmutableList.builder();
for (MultipartPart part : parts) {
- String blockId = BaseEncoding.base64().encode(Ints.toByteArray(part.partNumber()));
+ String blockId = makeBlockId(part.partNumber());
blocks.add(blockId);
}
return sync.putBlockList(mpu.containerName(), azureBlob, blocks.build());
}
+ static String makeBlockId(int partNumber) {
+ return BaseEncoding.base64Url().encode(Ints.toByteArray(partNumber));
+ }
+
@Override
public MultipartPart uploadMultipartPart(MultipartUpload mpu, int partNumber, Payload payload) {
- String blockId = BaseEncoding.base64().encode(Ints.toByteArray(partNumber));
+ String blockId = makeBlockId(partNumber);
sync.putBlock(mpu.containerName(), mpu.blobName(), blockId, payload);
String eTag = ""; // putBlock does not return ETag
Date lastModified = null; // putBlob does not return Last-Modified
diff --git a/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobStoreTest.java b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobStoreTest.java
new file mode 100644
index 0000000000..71830151cd
--- /dev/null
+++ b/providers/azureblob/src/test/java/org/jclouds/azureblob/blobstore/AzureBlobStoreTest.java
@@ -0,0 +1,55 @@
+/*
+ * 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.jclouds.azureblob.blobstore;
+
+import static org.testng.Assert.assertTrue;
+
+import org.testng.annotations.Test;
+
+import java.util.regex.Pattern;
+/**
+ * Tests behavior of {@code AzureBlobStore}
+ */
+// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire
+@Test(groups = "unit", testName = "AzureBlobStore")
+public class AzureBlobStoreTest {
+
+ private static final Pattern VALIDATION_PATTERN = Pattern.compile("[a-zA-Z0-9\\-_=]*");
+
+ public void testMakeBlockId() {
+ // how can i achieve something like a junit5 parametrized test in testng?
+ checkBlockIdForPartNumber(0);
+ checkBlockIdForPartNumber(1);
+ checkBlockIdForPartNumber(248);
+ checkBlockIdForPartNumber(504);
+ checkBlockIdForPartNumber(760);
+ checkBlockIdForPartNumber(1016);
+ checkBlockIdForPartNumber(1272);
+ checkBlockIdForPartNumber(4600);
+ checkBlockIdForPartNumber(6654);
+ checkBlockIdForPartNumber(867840);
+ checkBlockIdForPartNumber(868091);
+ checkBlockIdForPartNumber(868096);
+ checkBlockIdForPartNumber(-1);
+ checkBlockIdForPartNumber(-1023);
+ }
+
+ private void checkBlockIdForPartNumber(int partNumber) {
+ String blockId = AzureBlobStore.makeBlockId(partNumber);
+ assertTrue(VALIDATION_PATTERN.matcher(blockId).find());
+ }
+}