mirror of
https://github.com/danieldemus/openhab-core.git
synced 2025-01-25 19:55:48 +01:00
Fix AbstractScriptFileWatcher for windows (#3388)
Signed-off-by: Jan N. Klug <github@klug.nrw>
This commit is contained in:
parent
cd45dfe9f7
commit
c739c85208
@ -71,11 +71,14 @@ public abstract class AbstractScriptFileWatcher implements WatchService.WatchEve
|
|||||||
|
|
||||||
private static final Set<String> EXCLUDED_FILE_EXTENSIONS = Set.of("txt", "old", "example", "backup", "md", "swp",
|
private static final Set<String> EXCLUDED_FILE_EXTENSIONS = Set.of("txt", "old", "example", "backup", "md", "swp",
|
||||||
"tmp", "bak");
|
"tmp", "bak");
|
||||||
|
private static final String REGEX_SEPARATOR = "\\".equals(File.separator) ? "\\\\" : File.separator;
|
||||||
|
|
||||||
private static final List<Pattern> START_LEVEL_PATTERNS = List.of( //
|
private static final List<Pattern> START_LEVEL_PATTERNS = List.of( //
|
||||||
Pattern.compile(".*/sl(\\d{2})/[^/]+"), // script in immediate slXX directory
|
// script in immediate slXX directory
|
||||||
Pattern.compile(".*/[^/]+\\.sl(\\d{2})\\.[^/.]+") // script named <name>.slXX.<ext>
|
Pattern.compile(".*" + REGEX_SEPARATOR + "sl(\\d{2})" + REGEX_SEPARATOR + "[^" + REGEX_SEPARATOR + "]+"),
|
||||||
);
|
// script named <name>.slXX.<ext>
|
||||||
|
Pattern.compile(".*" + REGEX_SEPARATOR + "[^" + REGEX_SEPARATOR + "]+\\.sl(\\d{2})\\.[^" + REGEX_SEPARATOR
|
||||||
|
+ ".]+"));
|
||||||
|
|
||||||
private final Logger logger = LoggerFactory.getLogger(AbstractScriptFileWatcher.class);
|
private final Logger logger = LoggerFactory.getLogger(AbstractScriptFileWatcher.class);
|
||||||
|
|
||||||
|
@ -67,6 +67,7 @@ import org.opentest4j.AssertionFailedError;
|
|||||||
@ExtendWith(MockitoExtension.class)
|
@ExtendWith(MockitoExtension.class)
|
||||||
@MockitoSettings(strictness = Strictness.LENIENT)
|
@MockitoSettings(strictness = Strictness.LENIENT)
|
||||||
class AbstractScriptFileWatcherTest extends JavaTest {
|
class AbstractScriptFileWatcherTest extends JavaTest {
|
||||||
|
private static final int DEFAULT_TEST_TIMEOUT_MS = 10000;
|
||||||
|
|
||||||
private @NonNullByDefault({}) AbstractScriptFileWatcher scriptFileWatcher;
|
private @NonNullByDefault({}) AbstractScriptFileWatcher scriptFileWatcher;
|
||||||
|
|
||||||
@ -114,7 +115,7 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
scriptFileWatcher.processWatchEvent(CREATE, p);
|
scriptFileWatcher.processWatchEvent(CREATE, p);
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -132,9 +133,9 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js",
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
ScriptFileReference.getScriptIdentifier(p0));
|
ScriptFileReference.getScriptIdentifier(p0));
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js",
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
ScriptFileReference.getScriptIdentifier(p1));
|
ScriptFileReference.getScriptIdentifier(p1));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -154,7 +155,7 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js",
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
ScriptFileReference.getScriptIdentifier(p0));
|
ScriptFileReference.getScriptIdentifier(p0));
|
||||||
verify(scriptEngineManagerMock, never()).createScriptEngine("js", ScriptFileReference.getScriptIdentifier(p1));
|
verify(scriptEngineManagerMock, never()).createScriptEngine("js", ScriptFileReference.getScriptIdentifier(p1));
|
||||||
}
|
}
|
||||||
@ -182,7 +183,7 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -209,7 +210,7 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -243,14 +244,14 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p2.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p2.toString());
|
||||||
verify(scriptEngineManagerMock, never()).createScriptEngine(anyString(), eq(p1.toString()));
|
verify(scriptEngineManagerMock, never()).createScriptEngine(anyString(), eq(p1.toString()));
|
||||||
|
|
||||||
updateStartLevel(80);
|
updateStartLevel(80);
|
||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p1.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -277,14 +278,14 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
updateStartLevel(60);
|
updateStartLevel(60);
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p2.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p2.toString());
|
||||||
verify(scriptEngineManagerMock, never()).createScriptEngine(anyString(), eq(p1.toString()));
|
verify(scriptEngineManagerMock, never()).createScriptEngine(anyString(), eq(p1.toString()));
|
||||||
|
|
||||||
updateStartLevel(80);
|
updateStartLevel(80);
|
||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p1.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p1.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -311,7 +312,7 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
// verify script has now been processed
|
// verify script has now been processed
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -337,9 +338,12 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
||||||
|
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p64.toString());
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p65.toString());
|
p64.toString());
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p66.toString());
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
|
p65.toString());
|
||||||
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
|
p66.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -365,9 +369,12 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p30.toString());
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p40.toString());
|
p30.toString());
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p50.toString());
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
|
p40.toString());
|
||||||
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
|
p50.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -389,13 +396,15 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000).times(1)).createScriptEngine("js", p.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS).times(1)).createScriptEngine("js",
|
||||||
|
p.toString());
|
||||||
|
|
||||||
scriptFileWatcher.onDependencyChange(p.toString());
|
scriptFileWatcher.onDependencyChange(p.toString());
|
||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000).times(2)).createScriptEngine("js", p.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS).times(2)).createScriptEngine("js",
|
||||||
|
p.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -439,13 +448,15 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
scriptFileWatcher.processWatchEvent(CREATE, p);
|
scriptFileWatcher.processWatchEvent(CREATE, p);
|
||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", scriptIdentifier);
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
|
scriptIdentifier);
|
||||||
|
|
||||||
scriptFileWatcher.processWatchEvent(MODIFY, p);
|
scriptFileWatcher.processWatchEvent(MODIFY, p);
|
||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).removeEngine(scriptIdentifier);
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).removeEngine(scriptIdentifier);
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", scriptIdentifier);
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
|
scriptIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -466,8 +477,8 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p1.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p1.toString());
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p2.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p2.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -488,9 +499,9 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js",
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
ScriptFileReference.getScriptIdentifier(p1));
|
ScriptFileReference.getScriptIdentifier(p1));
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js",
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
ScriptFileReference.getScriptIdentifier(p2));
|
ScriptFileReference.getScriptIdentifier(p2));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -512,7 +523,7 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js",
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
ScriptFileReference.getScriptIdentifier(p1));
|
ScriptFileReference.getScriptIdentifier(p1));
|
||||||
verify(scriptEngineManagerMock, never()).createScriptEngine("js", ScriptFileReference.getScriptIdentifier(p2));
|
verify(scriptEngineManagerMock, never()).createScriptEngine("js", ScriptFileReference.getScriptIdentifier(p2));
|
||||||
}
|
}
|
||||||
@ -536,8 +547,10 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p10.toString());
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p20.toString());
|
p10.toString());
|
||||||
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
|
p20.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -560,10 +573,10 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
|
|
||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p1.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p1.toString());
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).createScriptEngine("js", p2.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js", p2.toString());
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).removeEngine(p1.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).removeEngine(p1.toString());
|
||||||
verify(scriptEngineManagerMock, timeout(10000)).removeEngine(p2.toString());
|
verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).removeEngine(p2.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -585,11 +598,12 @@ class AbstractScriptFileWatcherTest extends JavaTest {
|
|||||||
awaitEmptyQueue();
|
awaitEmptyQueue();
|
||||||
|
|
||||||
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
InOrder inOrder = inOrder(scriptEngineManagerMock);
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(1000)).createScriptEngine("js",
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS)).createScriptEngine("js",
|
||||||
ScriptFileReference.getScriptIdentifier(p));
|
ScriptFileReference.getScriptIdentifier(p));
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(1000))
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS))
|
||||||
.loadScript(eq(ScriptFileReference.getScriptIdentifier(p)), any());
|
.loadScript(eq(ScriptFileReference.getScriptIdentifier(p)), any());
|
||||||
inOrder.verify(scriptEngineManagerMock, timeout(1000)).removeEngine(ScriptFileReference.getScriptIdentifier(p));
|
inOrder.verify(scriptEngineManagerMock, timeout(DEFAULT_TEST_TIMEOUT_MS))
|
||||||
|
.removeEngine(ScriptFileReference.getScriptIdentifier(p));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user