Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/test/java/engineering/swat/watch/APIErrorsTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class APIErrorsTests {
class APIErrorsTests {

private TestDirectory testDir;

Expand Down
3 changes: 1 addition & 2 deletions src/test/java/engineering/swat/watch/DeleteLockTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ void setup() throws IOException {
}

@AfterEach
void cleanup() throws IOException {
void cleanup() {
if (testDir != null) {
testDir.close();
}
Expand All @@ -62,7 +62,6 @@ static void setupEverything() {
Awaitility.setDefaultTimeout(TestHelper.NORMAL_WAIT);
}


@FunctionalInterface
private interface Deleter {
void run(Path target) throws IOException;
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/engineering/swat/watch/RecursiveWatchTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;

Expand All @@ -56,18 +55,17 @@ void setup() throws IOException {
}

@AfterEach
void cleanup() throws IOException {
void cleanup() {
if (testDir != null) {
testDir.close();
}
}

@BeforeAll
static void setupEverything() throws IOException {
static void setupEverything() {
Awaitility.setDefaultTimeout(TestHelper.NORMAL_WAIT);
}


@Test
void newDirectoryWithFilesChangesDetected() throws IOException {
var target = new AtomicReference<Path>();
Expand Down Expand Up @@ -123,7 +121,7 @@ void correctRelativePathIsReported() throws IOException {
}

@Test
void deleteOfFileInDirectoryShouldBeVisible() throws IOException, InterruptedException {
void deleteOfFileInDirectoryShouldBeVisible() throws IOException {
var target = testDir.getTestFiles()
.stream()
.filter(p -> !p.getParent().equals(testDir.getTestDirectory()))
Expand Down
10 changes: 4 additions & 6 deletions src/test/java/engineering/swat/watch/SingleDirectoryTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

import java.io.IOException;
import java.nio.file.Files;
import java.time.Duration;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.awaitility.Awaitility;
Expand All @@ -42,7 +40,7 @@

import engineering.swat.watch.WatchEvent.Kind;

public class SingleDirectoryTests {
class SingleDirectoryTests {
private TestDirectory testDir;

@BeforeEach
Expand All @@ -51,7 +49,7 @@ void setup() throws IOException {
}

@AfterEach
void cleanup() throws IOException {
void cleanup() {
if (testDir != null) {
testDir.close();
}
Expand All @@ -63,7 +61,7 @@ static void setupEverything() {
}

@Test
void deleteOfFileInDirectoryShouldBeVisible() throws IOException, InterruptedException {
void deleteOfFileInDirectoryShouldBeVisible() throws IOException {
var target = testDir.getTestFiles().get(0);
var seenDelete = new AtomicBoolean(false);
var seenCreate = new AtomicBoolean(false);
Expand Down Expand Up @@ -91,7 +89,7 @@ void deleteOfFileInDirectoryShouldBeVisible() throws IOException, InterruptedExc
}

@Test
void alternativeAPITest() throws IOException, InterruptedException {
void alternativeAPITest() throws IOException {
var target = testDir.getTestFiles().get(0);
var seenDelete = new AtomicBoolean(false);
var seenCreate = new AtomicBoolean(false);
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/engineering/swat/watch/SingleFileTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class SingleFileTests {
class SingleFileTests {
private TestDirectory testDir;

@BeforeEach
Expand All @@ -49,7 +49,7 @@ void setup() throws IOException {
}

@AfterEach
void cleanup() throws IOException {
void cleanup() {
if (testDir != null) {
testDir.close();
}
Expand Down
9 changes: 3 additions & 6 deletions src/test/java/engineering/swat/watch/SmokeTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@

import java.io.IOException;
import java.nio.file.Files;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import org.awaitility.Awaitility;
Expand All @@ -51,7 +50,7 @@ void setup() throws IOException {
}

@AfterEach
void cleanup() throws IOException {
void cleanup() {
if (testDir != null) {
testDir.close();
}
Expand All @@ -63,7 +62,7 @@ static void setupEverything() {
}

@Test
void watchDirectory() throws IOException, InterruptedException {
void watchDirectory() throws IOException {
var changed = new AtomicBoolean(false);
var target = testDir.getTestFiles().get(0);
var watchConfig = Watcher.watch(testDir.getTestDirectory(), WatchScope.PATH_AND_CHILDREN)
Expand All @@ -77,7 +76,7 @@ void watchDirectory() throws IOException, InterruptedException {
}

@Test
void watchRecursiveDirectory() throws IOException, InterruptedException {
void watchRecursiveDirectory() throws IOException {
var changed = new AtomicBoolean(false);
var target = testDir.getTestFiles().stream()
.filter(p -> !p.getParent().equals(testDir.getTestDirectory()))
Expand Down Expand Up @@ -113,6 +112,4 @@ void watchSingleFile() throws IOException {
await("Single file change").untilTrue(changed);
}
}


}
2 changes: 1 addition & 1 deletion src/test/java/engineering/swat/watch/TestHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class TestHelper {
static {
var delayFactorConfig = System.getenv("DELAY_FACTOR");
int delayFactor = delayFactorConfig == null ? 1 : Integer.parseInt(delayFactorConfig);
var os = System.getProperty("os", "?").toLowerCase();
var os = System.getProperty("os.name", "?").toLowerCase();
if (os.contains("mac")) {
// OSX is SLOW on it's watches
delayFactor *= 2;
Expand Down
19 changes: 10 additions & 9 deletions src/test/java/engineering/swat/watch/TortureTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import java.util.Collections;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingDeque;
Expand All @@ -50,27 +49,32 @@

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;

import engineering.swat.watch.WatchEvent.Kind;

class TortureTests {

private final Logger logger = LogManager.getLogger();

private TestDirectory testDir;

@BeforeAll
static void setupEverything() {
Awaitility.setDefaultTimeout(TestHelper.LONG_WAIT.getSeconds(), TimeUnit.SECONDS);
}

@BeforeEach
void setup() throws IOException {
testDir = new TestDirectory();
}

@AfterEach
void cleanup() throws IOException {
void cleanup() {
if (testDir != null) {
testDir.close();
}
Expand All @@ -90,7 +94,7 @@ private final class IOGenerator {
}
}

private final static int BURST_SIZE = 1000;
private static final int BURST_SIZE = 1000;

private void startJob(final Path root, Random r, Executor exec) {
exec.execute(() -> {
Expand Down Expand Up @@ -239,7 +243,6 @@ void manyRegistrationsForSamePath() throws InterruptedException, IOException {
done.acquire(TORTURE_REGISTRATION_THREADS - 1);
assertTrue(seen.isEmpty(), "No events should have been sent");
var target = testDir.getTestDirectory().resolve("test124.txt");
//logger.info("Writing: {}", target);
Files.writeString(target, "Hello World");
var expected = Collections.singleton(target);
await("We should see only one event")
Expand Down Expand Up @@ -324,8 +327,6 @@ void manyRegisterAndUnregisterSameTime() throws InterruptedException, IOExceptio

}



@Test
//Deletes can race the filesystem, so you might miss a few files in a dir, if that dir is already deleted
@EnabledIfEnvironmentVariable(named="TORTURE_DELETE", matches="true")
Expand Down Expand Up @@ -363,7 +364,7 @@ void pressureOnFSShouldNotMissDeletes() throws InterruptedException, IOException
});

try (var activeWatch = watchConfig.start() ) {
logger.info("Deleting files now", THREADS);
logger.info("Deleting files now ({} threads)", THREADS);
testDir.deleteAllFiles();
logger.info("Waiting for the events processing to stabilize");
waitForStable(events, happened);
Expand Down
8 changes: 3 additions & 5 deletions src/test/java/engineering/swat/watch/impl/BundlingTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import engineering.swat.watch.impl.util.BundledSubscription;
import engineering.swat.watch.impl.util.ISubscribable;

public class BundlingTests {
class BundlingTests {

private final Logger logger = LogManager.getLogger();
private BundledSubscription<Long, Boolean> target;
Expand All @@ -77,8 +77,7 @@ void publish(Long x) {
s.accept(true);
}
}
};

}

@BeforeEach
void setup() {
Expand Down Expand Up @@ -134,7 +133,7 @@ void manySubscriptions() throws IOException {
}

@RepeatedTest(failureThreshold = 1, value=50)
void parallelSubscriptions() throws IOException, InterruptedException {
void parallelSubscriptions() throws InterruptedException {
var hits = new AtomicInteger();
var endPointReached = new Semaphore(0);
var waitingForClose = new Semaphore(0);
Expand Down Expand Up @@ -171,5 +170,4 @@ void parallelSubscriptions() throws IOException, InterruptedException {
.untilAtomic(hits, IsEqual.equalTo(active));
waitingForClose.release(active);
}

}
Loading