-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid UUID.randomUUID() in file system related startup code #5450
Open
geoand
wants to merge
1
commit into
eclipse-vertx:master
Choose a base branch
from
geoand:remove-uuid
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
vertx-core/src/test/java/io/vertx/tests/file/cachedir/ExactDirDoesNotExistTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package io.vertx.tests.file.cachedir; | ||
|
||
import io.vertx.core.VertxOptions; | ||
import io.vertx.core.file.FileSystemOptions; | ||
import io.vertx.core.internal.VertxInternal; | ||
import io.vertx.core.spi.file.FileResolver; | ||
import io.vertx.test.core.VertxTestBase; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ExactDirDoesNotExistTest extends VertxTestBase { | ||
|
||
private final Path cacheBaseDir; | ||
|
||
public ExactDirDoesNotExistTest() throws IOException { | ||
cacheBaseDir = Files.createTempDirectory("cache-does-not-exist"); | ||
Files.deleteIfExists(cacheBaseDir); | ||
Assert.assertFalse(Files.exists(cacheBaseDir)); | ||
} | ||
|
||
@Override | ||
protected VertxOptions getOptions() { | ||
return new VertxOptions(super.getOptions()) | ||
.setFileSystemOptions(new FileSystemOptions().setFileCachingEnabled(true).setExactFileCacheDir(cacheBaseDir.toAbsolutePath().toString())); | ||
} | ||
|
||
@Test | ||
public void test() throws IOException { | ||
try (FileResolver fileResolver = ((VertxInternal) vertx).fileResolver()) { | ||
File file = fileResolver.resolveFile("conf.json"); | ||
Assert.assertEquals(cacheBaseDir.resolve("conf.json").toFile(), file); | ||
} | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
vertx-core/src/test/java/io/vertx/tests/file/cachedir/ExactDirExistsButIsFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package io.vertx.tests.file.cachedir; | ||
|
||
import io.vertx.core.Vertx; | ||
import io.vertx.core.VertxOptions; | ||
import io.vertx.core.file.FileSystemOptions; | ||
import io.vertx.core.internal.VertxInternal; | ||
import io.vertx.core.spi.file.FileResolver; | ||
import io.vertx.test.core.VertxTestBase; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ExactDirExistsButIsFileTest { | ||
|
||
private final Path cacheBaseDir; | ||
|
||
public ExactDirExistsButIsFileTest() throws IOException { | ||
cacheBaseDir = Files.createTempDirectory("cache-exists-but-is-file"); | ||
Files.deleteIfExists(cacheBaseDir); | ||
Files.createFile(cacheBaseDir); | ||
Assert.assertTrue(Files.exists(cacheBaseDir)); | ||
Assert.assertFalse(Files.isDirectory(cacheBaseDir)); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Assert.assertThrows(IllegalStateException.class, () -> { | ||
Vertx.builder().with(new VertxOptions().setFileSystemOptions(new FileSystemOptions().setFileCachingEnabled(true).setExactFileCacheDir(cacheBaseDir.toAbsolutePath().toString()))).build(); | ||
}); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
vertx-core/src/test/java/io/vertx/tests/file/cachedir/ExactDirExistsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package io.vertx.tests.file.cachedir; | ||
|
||
import io.vertx.core.VertxOptions; | ||
import io.vertx.core.file.FileSystemOptions; | ||
import io.vertx.core.internal.VertxInternal; | ||
import io.vertx.core.spi.file.FileResolver; | ||
import io.vertx.test.core.VertxTestBase; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ExactDirExistsTest extends VertxTestBase { | ||
|
||
private final Path cacheBaseDir; | ||
|
||
public ExactDirExistsTest() throws IOException { | ||
cacheBaseDir = Paths.get(System.getProperty("java.io.tmpdir", "."), "cache-exists"); | ||
Files.deleteIfExists(cacheBaseDir); | ||
Files.createDirectories(cacheBaseDir); | ||
Assert.assertTrue(Files.exists(cacheBaseDir)); | ||
Assert.assertTrue(Files.isDirectory(cacheBaseDir)); | ||
} | ||
|
||
@Override | ||
protected VertxOptions getOptions() { | ||
return new VertxOptions(super.getOptions()) | ||
.setFileSystemOptions(new FileSystemOptions().setFileCachingEnabled(true).setExactFileCacheDir(cacheBaseDir.toAbsolutePath().toString())); | ||
} | ||
|
||
@Test | ||
public void test() throws IOException { | ||
try (FileResolver fileResolver = ((VertxInternal) vertx).fileResolver()) { | ||
File file = fileResolver.resolveFile("conf.json"); | ||
Assert.assertEquals(cacheBaseDir.resolve("conf.json").toFile(), file); | ||
} | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
vertx-core/src/test/java/io/vertx/tests/file/cachedir/ExactDirParentIsAFileTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package io.vertx.tests.file.cachedir; | ||
|
||
import io.vertx.core.Vertx; | ||
import io.vertx.core.VertxOptions; | ||
import io.vertx.core.file.FileSystemOptions; | ||
import io.vertx.core.internal.VertxInternal; | ||
import io.vertx.core.spi.file.FileResolver; | ||
import io.vertx.test.core.VertxTestBase; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.file.FileSystemException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.Paths; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
public class ExactDirParentIsAFileTest { | ||
|
||
private final Path cacheBaseDir; | ||
|
||
public ExactDirParentIsAFileTest() throws IOException { | ||
Path cacheBaseDirParent = Paths.get(System.getProperty("java.io.tmpdir", "."), "cache-parent"); | ||
Files.deleteIfExists(cacheBaseDirParent); | ||
Files.createFile(cacheBaseDirParent); | ||
Assert.assertTrue(Files.exists(cacheBaseDirParent)); | ||
Assert.assertFalse(Files.isDirectory(cacheBaseDirParent)); | ||
this.cacheBaseDir = cacheBaseDirParent.resolve("actual-cache"); | ||
Assert.assertFalse(Files.exists(cacheBaseDir)); | ||
} | ||
|
||
@Test | ||
public void test() { | ||
Assert.assertThrows(IllegalStateException.class, () -> { | ||
Vertx.builder().with(new VertxOptions().setFileSystemOptions(new FileSystemOptions().setFileCachingEnabled(true).setExactFileCacheDir(cacheBaseDir.toAbsolutePath().toString()))).build(); | ||
}); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't this change, break the comment above? when
isEffectiveValue
is true, 2 vert.x instances will interfere with each other's cache. While this is probably ok for the same application, if 2 applications differ, then it could cause invalid states.One example is (regardless if the 2 applications are the same or not) The moment the 1st terminates, it deletes the cache and would also mean it was deleted for the second, causing inconsistencies and errors.