Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

package org.apache.zookeeper;

import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import java.io.File;
import java.time.LocalDateTime;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
Expand All @@ -33,10 +36,10 @@
* Basic utilities shared by all tests. Also logging of various events during
* the test execution (start/stop/success/failure/etc...)
*/
@SuppressWarnings("deprecation")
@RunWith(JUnit4ZKTestRunner.class)
public class ZKTestCase {

protected static final File testBaseDir = new File(System.getProperty("build.test.dir", "build"));
private static final Logger LOG = LoggerFactory.getLogger(ZKTestCase.class);

private String testName;
Expand All @@ -45,6 +48,22 @@ protected String getTestName() {
return testName;
}

@BeforeClass
public static void before() {
if (!testBaseDir.exists()) {
assertTrue(
"Cannot properly create test base directory " + testBaseDir.getAbsolutePath(),
testBaseDir.mkdirs());
} else if (!testBaseDir.isDirectory()) {
assertTrue(
"Cannot properly delete file with duplicate name of test base directory " + testBaseDir.getAbsolutePath(),
testBaseDir.delete());
assertTrue(
"Cannot properly create test base directory " + testBaseDir.getAbsolutePath(),
testBaseDir.mkdirs());
}
}

@Rule
public TestWatcher watchman = new TestWatcher() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public abstract class ClientBase extends ZKTestCase {
protected static final Logger LOG = LoggerFactory.getLogger(ClientBase.class);

public static int CONNECTION_TIMEOUT = 30000;
static final File BASETEST = new File(System.getProperty("build.test.dir", "build"));

protected String hostPort = "127.0.0.1:" + PortAssignment.unique();
protected int maxCnxns = 0;
Expand Down Expand Up @@ -344,11 +343,11 @@ static void verifyThreadTerminated(Thread thread, long millis) throws Interrupte
}

public static File createEmptyTestDir() throws IOException {
return createTmpDir(BASETEST, false);
return createTmpDir(testBaseDir, false);
}

public static File createTmpDir() throws IOException {
return createTmpDir(BASETEST, true);
return createTmpDir(testBaseDir, true);
}

static File createTmpDir(File parentDir, boolean createInitFile) throws IOException {
Expand Down Expand Up @@ -495,7 +494,7 @@ protected void setUpWithServerId(int serverId) throws Exception {

setUpAll();

tmpDir = createTmpDir(BASETEST, true);
tmpDir = createTmpDir(testBaseDir, true);

startServer(serverId);

Expand Down