Skip to content

Commit

Permalink
Fixed testRenameDirectoryAsExistingFile
Browse files Browse the repository at this point in the history
  • Loading branch information
bhattmanish98 committed Feb 1, 2025
1 parent f3acefb commit f00f5c9
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -558,6 +558,9 @@ public boolean rename(final Path src, final Path dst) throws IOException {
Path adjustedDst = dst;

if (dstFileStatus != null) {
if (!dstFileStatus.isDirectory()) {
return qualifiedSrcPath.equals(qualifiedDstPath);
}
adjustedDst = new Path(dst, sourceFileName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -345,16 +345,6 @@ public void deleteBlobDirParallelThreadToDeleteOnDifferentTracingContext()
fs.close();
}

/**
* Assumes that the AzureBlobFileSystem's client is an instance of `AbfsBlobClient`.
* This assumption is used to ensure that the test runs only if the correct client type is present.
*
* @throws IOException if the file system client cannot be retrieved
*/
private void assumeBlobClient() throws IOException {
Assume.assumeTrue(getFileSystem().getAbfsClient() instanceof AbfsBlobClient);
}

/**
* Tests deleting an implicit directory and its contents. The test verifies that after deletion,
* both the directory and its child file no longer exist.
Expand All @@ -364,7 +354,7 @@ private void assumeBlobClient() throws IOException {
@Test
public void testDeleteImplicitDir() throws Exception {
AzureBlobFileSystem fs = getFileSystem();
assumeBlobClient();
assumeBlobServiceType();
fs.mkdirs(new Path("/testDir/dir1"));
fs.create(new Path("/testDir/dir1/file1"));
AbfsBlobClient client = (AbfsBlobClient) fs.getAbfsClient();
Expand All @@ -389,7 +379,7 @@ public void testDeleteImplicitDir() throws Exception {
public void testDeleteImplicitDirWithSingleListResults() throws Exception {
AzureBlobFileSystem fs = (AzureBlobFileSystem) FileSystem.newInstance(
getRawConfiguration());
assumeBlobClient();
assumeBlobServiceType();
AbfsBlobClient client = (AbfsBlobClient) fs.getAbfsClient();
AbfsBlobClient spiedClient = Mockito.spy(client);
fs.getAbfsStore().setClient(spiedClient);
Expand Down Expand Up @@ -425,7 +415,7 @@ public void testDeleteImplicitDirWithSingleListResults() throws Exception {
@Test
public void testDeleteExplicitDirInImplicitParentDir() throws Exception {
AzureBlobFileSystem fs = getFileSystem();
assumeBlobClient();
assumeBlobServiceType();
AbfsBlobClient client = (AbfsBlobClient) fs.getAbfsClient();
fs.mkdirs(new Path("/testDir/dir1"));
fs.create(new Path("/testDir/dir1/file1"));
Expand Down Expand Up @@ -453,7 +443,7 @@ public void testDeleteExplicitDirInImplicitParentDir() throws Exception {
@Test
public void testDeleteParallelBlobFailure() throws Exception {
AzureBlobFileSystem fs = Mockito.spy(getFileSystem());
assumeBlobClient();
assumeBlobServiceType();
AbfsBlobClient client = Mockito.spy((AbfsBlobClient) fs.getAbfsClient());
AzureBlobFileSystemStore store = Mockito.spy(fs.getAbfsStore());
store.setClient(client);
Expand Down Expand Up @@ -497,7 +487,7 @@ public void testDeleteRootWithNonRecursion() throws Exception {
*/
@Test
public void testProducerStopOnDeleteFailure() throws Exception {
assumeBlobClient();
assumeBlobServiceType();
Configuration configuration = Mockito.spy(getRawConfiguration());
AzureBlobFileSystem fs = Mockito.spy(
(AzureBlobFileSystem) FileSystem.get(configuration));
Expand Down Expand Up @@ -575,7 +565,7 @@ public void testProducerStopOnDeleteFailure() throws Exception {
@Test
public void testDeleteEmitDeletionCountInClientRequestId() throws Exception {
AzureBlobFileSystem fs = Mockito.spy(getFileSystem());
assumeBlobClient();
assumeBlobServiceType();
AbfsBlobClient client = (AbfsBlobClient) fs.getAbfsClient();
AbfsBlobClient spiedClient = Mockito.spy(client);
AzureBlobFileSystemStore store = Mockito.spy(fs.getAbfsStore());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;

import org.apache.hadoop.fs.azurebfs.constants.AbfsServiceType;
import org.apache.hadoop.fs.azurebfs.contracts.exceptions.AbfsRestOperationException;
import org.apache.hadoop.fs.azurebfs.services.AbfsBlobClient;
import org.apache.hadoop.fs.FileStatus;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.PathIOException;
Expand Down Expand Up @@ -90,7 +90,7 @@ public void testRenameFileUsingUnicode() throws Exception {
assertIsFile(fs, filePath);

Path folderPath2 = new Path(destDir);
if (getFileSystem().getAbfsClient() instanceof AbfsBlobClient
if (getAbfsServiceType() == AbfsServiceType.BLOB
&& destDir.contains(COLON)) {
AbfsRestOperationException ex = intercept(
AbfsRestOperationException.class, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,10 @@ public void updatePosition(String position) {
this.position = position;
}

/**
* Sets the value of the number of blobs operated on
* @param operatedBlobCount number of blobs operated on
*/
public void setOperatedBlobCount(Integer operatedBlobCount) {
this.operatedBlobCount = operatedBlobCount;
}
Expand Down

0 comments on commit f00f5c9

Please sign in to comment.