Skip to content

Commit

Permalink
GEODE-9526: Fix path computation in DiskStore test (#6777)
Browse files Browse the repository at this point in the history
PROBLEM

`DiskStoreCommandsDUnitTest.verifyDiskStoreInServer(...)` incorrectly
assumes thatif a file path does not start with a file separator, it must
be relative. It attempts to convert such a path to absolute by
prepending the current directory onto it:

```
String absoluteDiskDirectoryName = diskDirectoryName.startsWith(File.separator)
        ? diskDirectoryName
        : CURRENT_DIRECTORY + File.separator + diskDirectoryName;
```

On Windows, an absolute file path can begin with a letter, e.g.
`C:\Users\geode\AppData\Local\Temp\junit783716437098694709\DISKSTORE`.
The test incorrectly interprets a path like this as relative, and
prepends the current directory onto it, producing an invalid path. It
then uses this incorrect path in an assertion, causing the test to fail
when it should pass.

SOLUTION

Use Java's `Path` implementation for the OS to compute the absolute form of the given file path.
  • Loading branch information
demery-pivotal authored Aug 20, 2021
1 parent 2752849 commit 0d1954b
Showing 1 changed file with 1 addition and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
package org.apache.geode.management.internal.cli.commands;

import static org.apache.geode.cache.Region.SEPARATOR;
import static org.apache.geode.internal.lang.SystemUtils.CURRENT_DIRECTORY;
import static org.assertj.core.api.Assertions.assertThat;

import java.io.File;
Expand Down Expand Up @@ -583,8 +582,7 @@ private void verifyDiskStoreInServer(String diskStoreName, String diskDirectoryN
File[] diskDirs = diskStore.getDiskDirs();
assertThat(diskDirs.length).isEqualTo(1);
File diskDir = diskDirs[0];
String absoluteDiskDirectoryName = diskDirectoryName.startsWith(File.separator)
? diskDirectoryName : CURRENT_DIRECTORY + File.separator + diskDirectoryName;
String absoluteDiskDirectoryName = Paths.get(diskDirectoryName).toAbsolutePath().toString();
assertThat(diskDir.getAbsolutePath()).isEqualTo(absoluteDiskDirectoryName);
}

Expand Down

0 comments on commit 0d1954b

Please sign in to comment.