Converted some files back to java, made sure they work properly with java11 single file execution
This commit is contained in:
parent
29c81785de
commit
f6515341a5
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2020 dorkbox, llc
|
* Copyright 2022 dorkbox, llc
|
||||||
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
|
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
|
||||||
* Contains fragments of code from Apache Commons Exec, rights owned
|
* Contains fragments of code from Apache Commons Exec, rights owned
|
||||||
* by Apache Software Foundation (ASF).
|
* by Apache Software Foundation (ASF).
|
||||||
@ -20,8 +20,9 @@
|
|||||||
package dorkbox.executor.shutdown
|
package dorkbox.executor.shutdown
|
||||||
|
|
||||||
import dorkbox.executor.Executor
|
import dorkbox.executor.Executor
|
||||||
import org.junit.Assert
|
import dorkbox.executor.samples.TestSetup
|
||||||
import org.junit.Test
|
import org.junit.jupiter.api.Assertions
|
||||||
|
import org.junit.jupiter.api.Test
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -43,14 +44,18 @@ class ProcessExecutorShutdownHookTest {
|
|||||||
@Throws(Exception::class)
|
@Throws(Exception::class)
|
||||||
private fun testDestroyOnExit(loopStarterClassFile: Class<*>, fileIsAlwaysCreated: Boolean) {
|
private fun testDestroyOnExit(loopStarterClassFile: Class<*>, fileIsAlwaysCreated: Boolean) {
|
||||||
val file = WriterLoop.getFile()
|
val file = WriterLoop.getFile()
|
||||||
println(file)
|
println("Data loop file: $file")
|
||||||
|
|
||||||
if (file.exists()) file.delete()
|
if (file.exists()) file.delete()
|
||||||
|
|
||||||
Executor()
|
Executor()
|
||||||
.redirectOutputAsInfo()
|
.redirectOutputAsInfo()
|
||||||
|
.redirectErrorAsInfo()
|
||||||
|
.enableRead()
|
||||||
|
.defaultLogger()
|
||||||
.asJvmProcess()
|
.asJvmProcess()
|
||||||
.cloneClasspath()
|
.cloneClasspath()
|
||||||
.setMainClass(loopStarterClassFile.name)
|
.setMainClass(TestSetup.getFile(loopStarterClassFile))
|
||||||
.startBlocking()
|
.startBlocking()
|
||||||
|
|
||||||
// After WriterLoopStarter has finished we expect that WriterLoop is also finished - no-one is updating the file
|
// After WriterLoopStarter has finished we expect that WriterLoop is also finished - no-one is updating the file
|
||||||
@ -61,15 +66,15 @@ class ProcessExecutorShutdownHookTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val SLEEP_FOR_RECHECKING_FILE: Long = 4000
|
private const val SLEEP_FOR_RECHECKING_FILE: Long = 4000L
|
||||||
|
|
||||||
@Throws(InterruptedException::class)
|
@Throws(InterruptedException::class)
|
||||||
private fun checkFileStaysTheSame(file: File) {
|
private fun checkFileStaysTheSame(file: File) {
|
||||||
Assert.assertTrue(file.exists())
|
Assertions.assertTrue(file.exists())
|
||||||
val length = file.length()
|
val length = file.length()
|
||||||
|
|
||||||
Thread.sleep(SLEEP_FOR_RECHECKING_FILE)
|
Thread.sleep(SLEEP_FOR_RECHECKING_FILE)
|
||||||
Assert.assertEquals("File '$file' was still updated.", length, file.length())
|
Assertions.assertEquals(length, file.length(), "File '$file' was still updated.",)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2020 dorkbox, llc
|
* Copyright 2022 dorkbox, llc
|
||||||
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
|
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
|
||||||
* Contains fragments of code from Apache Commons Exec, rights owned
|
* Contains fragments of code from Apache Commons Exec, rights owned
|
||||||
* by Apache Software Foundation (ASF).
|
* by Apache Software Foundation (ASF).
|
||||||
@ -17,37 +17,40 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package dorkbox.executor.shutdown
|
package dorkbox.executor.shutdown;
|
||||||
|
|
||||||
import dorkbox.executor.Executor
|
|
||||||
import dorkbox.executor.samples.TestSetup
|
|
||||||
import kotlin.system.exitProcess
|
|
||||||
|
|
||||||
|
import dorkbox.executor.Executor;
|
||||||
|
import dorkbox.executor.samples.TestSetup;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts [WriterLoop] inside shutdown hook and destroys it.
|
* Starts [WriterLoop] inside shutdown hook and destroys it.
|
||||||
*/
|
*/
|
||||||
class WriterLoopStarterAfterExit : Runnable {
|
public
|
||||||
companion object {
|
class WriterLoopStarterAfterExit implements Runnable {
|
||||||
private const val SLEEP_AFTER_START: Long = 2000
|
private static Long SLEEP_AFTER_START = 2000L;
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
@JvmStatic
|
public static
|
||||||
fun main(args: Array<String>) {
|
void main(String[] args) {
|
||||||
Runtime.getRuntime().addShutdownHook(Thread(WriterLoopStarterAfterExit()))
|
System.out.println("Starting output: " + WriterLoop.getFile());
|
||||||
|
|
||||||
|
Runtime.getRuntime().addShutdownHook(new Thread(new WriterLoopStarterAfterExit()));
|
||||||
|
|
||||||
// Launch the process and also destroy it
|
// Launch the process and also destroy it
|
||||||
exitProcess(0)
|
System.exit(0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun run() {
|
@Override
|
||||||
|
public
|
||||||
|
void run() {
|
||||||
try {
|
try {
|
||||||
Executor("java", TestSetup.getFile(WriterLoop::class.java))
|
new Executor("java", TestSetup.INSTANCE.getFile(WriterLoop.class))
|
||||||
.destroyOnExit().startBlocking()
|
.destroyOnExit()
|
||||||
Thread.sleep(SLEEP_AFTER_START)
|
.startBlocking();
|
||||||
} catch (e: Exception) {
|
|
||||||
e.printStackTrace()
|
Thread.sleep(SLEEP_AFTER_START);
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2022 dorkbox, llc
|
||||||
|
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
|
||||||
|
* Contains fragments of code from Apache Commons Exec, rights owned
|
||||||
|
* by Apache Software Foundation (ASF).
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package dorkbox.executor.shutdown;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import dorkbox.executor.Executor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts [WriterLoop] and destroys it on JVM exit.
|
||||||
|
*/
|
||||||
|
public
|
||||||
|
class WriterLoopStarterBeforeExit {
|
||||||
|
public static
|
||||||
|
void main(String[] args) {
|
||||||
|
try {
|
||||||
|
System.out.println("Starting output: " + new File("writeLoop.data").getAbsoluteFile());
|
||||||
|
|
||||||
|
// silly workarounds, because executing java files from CLI, require SINGLE-FILE access!
|
||||||
|
String path = getFile(WriterLoopStarterBeforeExit.class)
|
||||||
|
.replace(WriterLoopStarterBeforeExit.class.getSimpleName(), "WriterLoop");
|
||||||
|
|
||||||
|
System.out.println("Starting output: " + path);
|
||||||
|
|
||||||
|
new Executor()
|
||||||
|
.redirectOutputAsInfo()
|
||||||
|
.redirectErrorAsInfo()
|
||||||
|
.asJvmProcess()
|
||||||
|
.cloneClasspath()
|
||||||
|
.setMainClass(path)
|
||||||
|
.startBlocking();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Launch the process and also destroy it
|
||||||
|
System.exit(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getFile(Class javaClass) throws IOException {
|
||||||
|
String properName;
|
||||||
|
|
||||||
|
if (Executor.Companion.getIS_OS_WINDOWS()) {
|
||||||
|
properName = javaClass.getName().replace('.', '\\');
|
||||||
|
} else {
|
||||||
|
properName = javaClass.getName().replace('.', '/');
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File("test", properName + ".java").getAbsoluteFile().getCanonicalFile();
|
||||||
|
return file.getPath();
|
||||||
|
}
|
||||||
|
}
|
@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright 2020 dorkbox, llc
|
|
||||||
* Copyright (C) 2014 ZeroTurnaround <support@zeroturnaround.com>
|
|
||||||
* Contains fragments of code from Apache Commons Exec, rights owned
|
|
||||||
* by Apache Software Foundation (ASF).
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package dorkbox.executor.shutdown
|
|
||||||
|
|
||||||
import dorkbox.executor.Executor
|
|
||||||
import dorkbox.executor.samples.TestSetup
|
|
||||||
import kotlinx.coroutines.delay
|
|
||||||
import kotlinx.coroutines.runBlocking
|
|
||||||
import kotlin.system.exitProcess
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Starts [WriterLoop] and destroys it on JVM exit.
|
|
||||||
*/
|
|
||||||
object WriterLoopStarterBeforeExit {
|
|
||||||
private const val SLEEP_AFTER_START: Long = 2000
|
|
||||||
|
|
||||||
@Throws(Exception::class)
|
|
||||||
@JvmStatic
|
|
||||||
fun main(args: Array<String>) {
|
|
||||||
Executor("java", TestSetup.getFile(WriterLoop::class.java))
|
|
||||||
.destroyOnExit().redirectOutputAsInfo().startAsync()
|
|
||||||
|
|
||||||
runBlocking {
|
|
||||||
delay(SLEEP_AFTER_START)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Cause the launched process to be destroyed
|
|
||||||
exitProcess(0)
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user