Skip to content

Commit f8276de

Browse files
committed
Update simple test to check if JNI+Rust works
1 parent 0b4b615 commit f8276de

File tree

2 files changed

+83
-52
lines changed

2 files changed

+83
-52
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
* BSD 2-Clause License
3+
*
4+
* Copyright (c) 2023, Swat.engineering
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this
10+
* list of conditions and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
package engineering.swat.watch.impl.mac;
28+
29+
import static org.awaitility.Awaitility.await;
30+
31+
import java.io.IOException;
32+
import java.nio.file.Files;
33+
import java.nio.file.WatchEvent.Kind;
34+
import java.util.concurrent.atomic.AtomicBoolean;
35+
36+
import org.awaitility.Awaitility;
37+
import org.checkerframework.checker.nullness.qual.Nullable;
38+
import org.junit.jupiter.api.AfterEach;
39+
import org.junit.jupiter.api.BeforeAll;
40+
import org.junit.jupiter.api.BeforeEach;
41+
import org.junit.jupiter.api.Test;
42+
43+
import engineering.swat.watch.TestDirectory;
44+
import engineering.swat.watch.TestHelper;
45+
46+
public class NativeEventStreamTests {
47+
48+
private TestDirectory testDir;
49+
50+
@BeforeEach
51+
void setup() throws IOException {
52+
testDir = new TestDirectory();
53+
}
54+
55+
@AfterEach
56+
void cleanup() {
57+
if (testDir != null) {
58+
testDir.close();
59+
}
60+
}
61+
62+
@BeforeAll
63+
static void setupEverything() {
64+
Awaitility.setDefaultTimeout(TestHelper.NORMAL_WAIT);
65+
}
66+
67+
@Test
68+
void signalsAreSent() throws IOException, InterruptedException {
69+
var signaled = new AtomicBoolean(false);
70+
try (var stream = new NativeEventStream(testDir.getTestDirectory(),
71+
new NativeEventHandler() {
72+
@Override
73+
public <T> void handle(Kind<T> kind, @Nullable T context) {
74+
signaled.set(true);
75+
}
76+
}
77+
)) {
78+
stream.open();
79+
Files.write(testDir.getTestFiles().get(0), "Hello".getBytes());
80+
await("Signal received").untilTrue(signaled);
81+
}
82+
}
83+
}

src/test/java/engineering/swat/watch/impl/mac/jni/Basic.java

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)