File tree Expand file tree Collapse file tree 3 files changed +29
-6
lines changed
test/java/io/vertx/tests/file Expand file tree Collapse file tree 3 files changed +29
-6
lines changed Original file line number Diff line number Diff line change @@ -45,8 +45,7 @@ static File setupCacheDir(String fileCacheDir) {
4545
4646 // the cacheDir will be suffixed a unique id to avoid eavesdropping from other processes/users
4747 // also this ensures that if process A deletes cacheDir, it won't affect process B
48- String cacheDirName = fileCacheDir + "-" + UUID .randomUUID ();
49- File cacheDir = new File (cacheDirName );
48+ File cacheDir = effectiveCacheDir (fileCacheDir );
5049 // Create the cache directory
5150 try {
5251 if (Utils .isWindows ()) {
@@ -63,6 +62,25 @@ static File setupCacheDir(String fileCacheDir) {
6362 return cacheDir ;
6463 }
6564
65+ private static File effectiveCacheDir (String fileCacheDir ) {
66+ for (int i = 0 ; i < 10 ; i ++) {
67+ try {
68+ // attempt to create a file using a really quick random value
69+ String cacheDirName = fileCacheDir + "-" + System .nanoTime ();
70+ File file = new File (cacheDirName );
71+ Files .createDirectories (file .toPath ());
72+ return file ;
73+ } catch (FileAlreadyExistsException ignore ) {
74+ } catch (IOException ignore ) {
75+ // hope that the fallback will work
76+ break ;
77+ }
78+ }
79+
80+ String cacheDirName = fileCacheDir + "-" + UUID .randomUUID ();
81+ return new File (cacheDirName );
82+ }
83+
6684 private Thread shutdownHook ;
6785 private File cacheDir ;
6886
Original file line number Diff line number Diff line change @@ -36,7 +36,12 @@ public DefaultDeploymentManager(VertxImpl vertx) {
3636 }
3737
3838 private String generateDeploymentID () {
39- return UUID .randomUUID ().toString ();
39+ if (vertx .isClustered () && vertx .haManager ()!=null ) {
40+ // in this case we need a globally unique id
41+ return UUID .randomUUID ().toString ();
42+ }
43+ // in the default case we want to generate the ID as fast as possible
44+ return Long .valueOf (System .nanoTime ()).toString ();
4045 }
4146
4247 public Future <Void > undeploy (String deploymentID ) {
Original file line number Diff line number Diff line change @@ -477,12 +477,12 @@ public void testGetTheCacheDirWithoutHacks() {
477477 if (cacheDir != null ) {
478478 assertTrue (cacheDir .startsWith (cacheBaseDir + "-" ));
479479 // strip the remaining
480- String uuid = cacheDir .substring (cacheBaseDir .length () + 1 );
480+ String val = cacheDir .substring (cacheBaseDir .length () + 1 );
481481 try {
482- UUID . fromString ( uuid );
482+ Long . parseLong ( val );
483483 // OK
484484 } catch (Exception e ) {
485- fail ("Expected a UUID " );
485+ fail ("Expected a Long " );
486486 }
487487 }
488488 }
You can’t perform that action at this time.
0 commit comments