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) {
45
45
46
46
// the cacheDir will be suffixed a unique id to avoid eavesdropping from other processes/users
47
47
// 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 );
50
49
// Create the cache directory
51
50
try {
52
51
if (Utils .isWindows ()) {
@@ -63,6 +62,25 @@ static File setupCacheDir(String fileCacheDir) {
63
62
return cacheDir ;
64
63
}
65
64
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
+
66
84
private Thread shutdownHook ;
67
85
private File cacheDir ;
68
86
Original file line number Diff line number Diff line change @@ -36,7 +36,12 @@ public DefaultDeploymentManager(VertxImpl vertx) {
36
36
}
37
37
38
38
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 ();
40
45
}
41
46
42
47
public Future <Void > undeploy (String deploymentID ) {
Original file line number Diff line number Diff line change @@ -477,12 +477,12 @@ public void testGetTheCacheDirWithoutHacks() {
477
477
if (cacheDir != null ) {
478
478
assertTrue (cacheDir .startsWith (cacheBaseDir + "-" ));
479
479
// strip the remaining
480
- String uuid = cacheDir .substring (cacheBaseDir .length () + 1 );
480
+ String val = cacheDir .substring (cacheBaseDir .length () + 1 );
481
481
try {
482
- UUID . fromString ( uuid );
482
+ Long . parseLong ( val );
483
483
// OK
484
484
} catch (Exception e ) {
485
- fail ("Expected a UUID " );
485
+ fail ("Expected a Long " );
486
486
}
487
487
}
488
488
}
You can’t perform that action at this time.
0 commit comments