Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,16 @@
import com.qcloud.cos.auth.COSCredentials;
import com.qcloud.cos.auth.COSCredentialsProvider;
import org.apache.hadoop.conf.Configuration;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.fail;

public class TestCosCredentials {
private static final Logger LOG =
Expand Down Expand Up @@ -76,7 +76,7 @@ private void validateCredentials(URI uri, Configuration configuration)
COSCredentialsProvider credentialsProvider =
CosNUtils.createCosCredentialsProviderSet(uri, configuration);
COSCredentials cosCredentials = credentialsProvider.getCredentials();
assertNotNull("The cos credentials obtained is null.", cosCredentials);
assertNotNull(cosCredentials, "The cos credentials obtained is null.");
if (configuration.get(
CosNConfigKeys.COSN_CREDENTIALS_PROVIDER).compareToIgnoreCase(
"org.apache.hadoop.fs.cosn.EnvironmentVariableCredentialsProvider")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.contract.ContractTestUtils;
import org.apache.hadoop.io.IOUtils;
import org.junit.*;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.junit.Assert.assertTrue;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.io.IOException;
import java.util.Random;
Expand All @@ -43,15 +46,15 @@ public class TestCosNInputStream {

private Path testRootDir;

@Before
@BeforeEach
public void setUp() throws IOException {
Configuration configuration = new Configuration();
this.fs = CosNTestUtils.createTestFileSystem(configuration);
this.testRootDir = CosNTestUtils.createTestPath(new Path("/test"));
LOG.info("test root dir: " + this.testRootDir);
}

@After
@AfterEach
public void tearDown() throws IOException {
if (null != this.fs) {
this.fs.delete(this.testRootDir, true);
Expand All @@ -76,9 +79,9 @@ public void testSeek() throws Exception {
for (int i = 0; i != seekTimes; i++) {
long pos = fileSize / (seekTimes - i) - 1;
inputStream.seek(pos);
assertTrue("expected position at: " +
pos + ", but got: " + inputStream.getPos(),
inputStream.getPos() == pos);
assertTrue(inputStream.getPos() == pos,
"expected position at: " +
pos + ", but got: " + inputStream.getPos());
LOG.info("completed seeking at pos: " + inputStream.getPos());
}
LOG.info("begin to random position seeking test...");
Expand All @@ -87,9 +90,9 @@ public void testSeek() throws Exception {
long pos = Math.abs(random.nextLong()) % fileSize;
LOG.info("seeking for pos: " + pos);
inputStream.seek(pos);
assertTrue("expected position at: " +
pos + ", but got: " + inputStream.getPos(),
inputStream.getPos() == pos);
assertTrue(inputStream.getPos() == pos,
"expected position at: " +
pos + ", but got: " + inputStream.getPos());
LOG.info("completed seeking at pos: " + inputStream.getPos());
}
}
Expand All @@ -110,16 +113,16 @@ public void testGetPos() throws Exception {
Random random = new Random();
long pos = Math.abs(random.nextLong()) % fileSize;
inputStream.seek(pos);
assertTrue("expected position at: " +
pos + ", but got: " + inputStream.getPos(),
inputStream.getPos() == pos);
assertTrue(inputStream.getPos() == pos,
"expected position at: " +
pos + ", but got: " + inputStream.getPos());
LOG.info("completed get pos tests.");
}

/**
* Method: seekToNewSource(long targetPos).
*/
@Ignore("Not ready yet")
@Disabled("Not ready yet")
public void testSeekToNewSource() throws Exception {
LOG.info("Currently it is not supported to " +
"seek the offset in a new source.");
Expand Down Expand Up @@ -154,8 +157,9 @@ public void testRead() throws Exception {

if (bytesRead % (1 * Unit.MB) == 0) {
int available = inputStream.available();
assertTrue("expected remaining: " + (fileSize - bytesRead) +
" but got: " + available, (fileSize - bytesRead) == available);
assertTrue((fileSize - bytesRead) == available,
"expected remaining: " + (fileSize - bytesRead) +
" but got: " + available);
LOG.info("Bytes read: " +
Math.round((double) bytesRead / Unit.MB) + "MB");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@
import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.contract.ContractTestUtils;
import org.junit.Rule;
import org.junit.Test;
import org.junit.Before;
import org.junit.After;
import org.junit.rules.Timeout;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;

import java.io.IOException;

Expand All @@ -34,14 +33,12 @@
* <p>
* If the test.fs.cosn.name property is not set, all test case will fail.
*/
@Timeout(3600)
public class TestCosNOutputStream {
private FileSystem fs;
private Path testRootDir;

@Rule
public Timeout timeout = new Timeout(3600 * 1000);

@Before
@BeforeEach
public void setUp() throws Exception {
Configuration configuration = new Configuration();
configuration.setInt(
Expand All @@ -53,7 +50,7 @@ public void setUp() throws Exception {
this.testRootDir = new Path("/test");
}

@After
@AfterEach
public void tearDown() throws Exception {
}

Expand Down