mirror of
https://github.com/OpenHFT/Chronicle-Map.git
synced 2021-09-13 01:26:12 +00:00
Standard code formatting
This commit is contained in:
@@ -32,6 +32,44 @@ public class ExitHookTest {
|
||||
@Rule
|
||||
public TemporaryFolder folder = new TemporaryFolder();
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
System.out.println("Other process started");
|
||||
File mapFile = new File(args[0]);
|
||||
ChronicleMap<Integer, Integer> map = createMap(mapFile);
|
||||
try (ExternalMapQueryContext<Integer, Integer, ?> c = map.queryContext(KEY)) {
|
||||
c.writeLock().lock();
|
||||
try {
|
||||
map.close();
|
||||
} finally {
|
||||
Thread.sleep(30_000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ChronicleMap<Integer, Integer> createMap(File mapFile) throws IOException {
|
||||
return ChronicleMap
|
||||
.of(Integer.class, Integer.class)
|
||||
.entries(1)
|
||||
.createPersistedTo(mapFile);
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/a/33171840/648955
|
||||
public static long getPidOfProcess(Process p) {
|
||||
long pid = -1;
|
||||
|
||||
try {
|
||||
if (p.getClass().getName().equals("java.lang.UNIXProcess")) {
|
||||
Field f = p.getClass().getDeclaredField("pid");
|
||||
f.setAccessible(true);
|
||||
pid = f.getLong(p);
|
||||
f.setAccessible(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
pid = -1;
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testExitHook() throws IOException, InterruptedException {
|
||||
if (!OS.isLinux() && !OS.isMacOSX())
|
||||
@@ -55,27 +93,6 @@ public class ExitHookTest {
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws IOException, InterruptedException {
|
||||
System.out.println("Other process started");
|
||||
File mapFile = new File(args[0]);
|
||||
ChronicleMap<Integer, Integer> map = createMap(mapFile);
|
||||
try (ExternalMapQueryContext<Integer, Integer, ?> c = map.queryContext(KEY)) {
|
||||
c.writeLock().lock();
|
||||
try {
|
||||
map.close();
|
||||
} finally {
|
||||
Thread.sleep(30_000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static ChronicleMap<Integer, Integer> createMap(File mapFile) throws IOException {
|
||||
return ChronicleMap
|
||||
.of(Integer.class, Integer.class)
|
||||
.entries(1)
|
||||
.createPersistedTo(mapFile);
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/a/7835467/648955
|
||||
private void interruptProcess(long pidOfProcess) throws IOException {
|
||||
Runtime.getRuntime().exec("kill -SIGINT " + pidOfProcess);
|
||||
@@ -96,21 +113,4 @@ public class ExitHookTest {
|
||||
builder.inheritIO();
|
||||
return builder.start();
|
||||
}
|
||||
|
||||
// http://stackoverflow.com/a/33171840/648955
|
||||
public static long getPidOfProcess(Process p) {
|
||||
long pid = -1;
|
||||
|
||||
try {
|
||||
if (p.getClass().getName().equals("java.lang.UNIXProcess")) {
|
||||
Field f = p.getClass().getDeclaredField("pid");
|
||||
f.setAccessible(true);
|
||||
pid = f.getLong(p);
|
||||
f.setAccessible(false);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
pid = -1;
|
||||
}
|
||||
return pid;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user