Skip to content

Commit

Permalink
test: testAzblobLargeFile
Browse files Browse the repository at this point in the history
Signed-off-by: tison <[email protected]>
  • Loading branch information
tisonkun committed Dec 18, 2024
1 parent 66eff2d commit 11de935
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
public class BehaviorExtension implements BeforeAllCallback, AfterAllCallback, TestWatcher {
private String testName;

public String scheme;
public AsyncOperator asyncOperator;
public Operator operator;

Expand Down Expand Up @@ -67,6 +68,7 @@ public void beforeAll(ExtensionContext context) {
this.asyncOperator = op.layer(RetryLayer.builder().build());
this.operator = this.asyncOperator.blocking();

this.scheme = scheme;
this.testName = String.format("%s(%s)", context.getDisplayName(), scheme);
log.info(
"\n================================================================================"
Expand Down Expand Up @@ -94,6 +96,7 @@ public void afterAll(ExtensionContext context) {
operator = null;
}

this.scheme = null;
this.testName = null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ protected Operator op() {
return behaviorExtension.operator;
}

protected String scheme() {
return behaviorExtension.scheme;
}

/**
* Generates a byte array of random content.
*/
Expand All @@ -57,6 +61,16 @@ public static byte[] generateBytes() {
return content;
}

/**
* Generates a byte array of random content with a specific size.
*/
public static byte[] generateBytes(int size) {
final Random random = new Random();
final byte[] content = new byte[size];
random.nextBytes(content);
return content;
}

/**
* Calculate SHA256 digest of input bytes
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* 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.opendal.test.behavior;

import static org.junit.jupiter.api.Assumptions.assumeTrue;
import java.util.UUID;
import org.apache.opendal.OperatorOutputStream;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestInstance;

@TestInstance(TestInstance.Lifecycle.PER_CLASS)
public class RegressionTest extends BehaviorTestBase {
// @see https://github.com/apache/opendal/issues/5421
@Test
public void testAzblobLargeFile() throws Exception {
assumeTrue(scheme() != null && scheme().equalsIgnoreCase("azblob"));

final String path = UUID.randomUUID().toString();
final int size = 16384 * 10; // 10 x OperatorOutputStream.DEFAULT_MAX_BYTES (10 flushes per write)
final byte[] content = generateBytes(size);

try (OperatorOutputStream operatorOutputStream = op().createOutputStream(path)) {
for (int i = 0; i < 20000; i++) {
// More iterations in case BlockCountExceedsLimit doesn't pop up exactly after 100K blocks.
operatorOutputStream.write(content);
}
}
}
}

0 comments on commit 11de935

Please sign in to comment.