2
2
3
3
import java .io .File ;
4
4
import java .io .IOException ;
5
+ import java .nio .file .Files ;
5
6
6
7
import org .apache .commons .io .FileUtils ;
7
8
import org .slf4j .Logger ;
@@ -22,6 +23,8 @@ public class EtcdProcess {
22
23
private volatile Process etcdProcess ;
23
24
private volatile boolean stopped = false ;
24
25
private final UnexpectedProcessStopHandler processStopHandler ;
26
+ private File tempWalDir ;
27
+ private File tempDataDir ;
25
28
26
29
public EtcdProcess (BinaryManager binaryManager ,
27
30
UnexpectedProcessStopHandler processStopHandler ) {
@@ -30,15 +33,22 @@ public EtcdProcess(BinaryManager binaryManager,
30
33
}
31
34
32
35
public int startEtcd () {
33
- var etcdBinary = binaryManager .binaries ().getEtcd ();
34
- var port = Utils .findFreePort ();
35
- var peerPort = Utils .findFreePort ();
36
36
try {
37
+ var etcdBinary = binaryManager .binaries ().getEtcd ();
38
+ tempWalDir = Files .createTempDirectory ("etcdwal" ).toFile ();
39
+ tempDataDir = Files .createTempDirectory ("etcddata" ).toFile ();
40
+ log .trace ("Using temp wal dir: {} and temp data dir: {}" , tempWalDir .getPath (),
41
+ tempDataDir .getPath ());
42
+ var port = Utils .findFreePort ();
43
+ var peerPort = Utils .findFreePort ();
44
+
37
45
if (!etcdBinary .exists ()) {
38
46
throw new JenvtestException (
39
47
"Missing binary for etcd on path: " + etcdBinary .getAbsolutePath ());
40
48
}
41
49
etcdProcess = new ProcessBuilder (etcdBinary .getAbsolutePath (),
50
+ "-data-dir" , tempDataDir .getPath (),
51
+ "-wal-dir" , tempWalDir .getPath (),
42
52
"--listen-client-urls" , "http://0.0.0.0:" + port ,
43
53
"--advertise-client-urls" , "http://0.0.0.0:" + port ,
44
54
// the below added because of stability
@@ -65,7 +75,8 @@ public int startEtcd() {
65
75
66
76
public void cleanEtcdData () {
67
77
try {
68
- FileUtils .deleteDirectory (new File ("default.etcd" ));
78
+ FileUtils .deleteDirectory (tempDataDir );
79
+ FileUtils .deleteDirectory (tempWalDir );
69
80
} catch (IOException e ) {
70
81
throw new JenvtestException (e );
71
82
}
0 commit comments