-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df3e004
commit 3d1bf8d
Showing
7 changed files
with
167 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/runner/java/dev/lukebemish/forkedtaskexecutor/runner/Task.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
package dev.lukebemish.forkedtaskexecutor.runner; | ||
|
||
public interface Task { | ||
byte[] run(byte[] input); | ||
byte[] run(byte[] input) throws Exception; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/test/java/dev/lukebemish/forkedtaskexecutor/test/EchoTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package dev.lukebemish.forkedtaskexecutor.test; | ||
|
||
import dev.lukebemish.forkedtaskexecutor.runner.Task; | ||
|
||
public class EchoTask implements Task { | ||
public EchoTask(String[] args) {} | ||
|
||
@Override | ||
public byte[] run(byte[] input) throws InterruptedException { | ||
Thread.sleep(200); | ||
return input; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/test/java/dev/lukebemish/forkedtaskexecutor/test/TestForkedExecutor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package dev.lukebemish.forkedtaskexecutor.test; | ||
|
||
import dev.lukebemish.forkedtaskexecutor.ForkedTaskExecutor; | ||
import dev.lukebemish.forkedtaskexecutor.ForkedTaskExecutorSpec; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.util.concurrent.Future; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class TestForkedExecutor { | ||
@Test | ||
void testMain() { | ||
var jvmExecutable = ProcessHandle.current() | ||
.info() | ||
.command() | ||
.orElse(null); | ||
assertNotNull(jvmExecutable, "JVM executable not found"); | ||
var spec = ForkedTaskExecutorSpec.builder() | ||
.taskClass(EchoTask.class.getName()) | ||
.javaExecutable(jvmExecutable) | ||
.addJvmOption("-classpath") | ||
.addJvmOption(System.getProperty("forkedtaskexecutor.test.daemonclasspath")) | ||
.build(); | ||
try (var executor = new ForkedTaskExecutor(spec)) { | ||
byte count = 10; | ||
@SuppressWarnings("unchecked") Future<byte[]>[] outputs = new Future[count]; | ||
for (byte i = 0; i < 10; i++) { | ||
outputs[i] = executor.submitAsync(new byte[] {i}); | ||
} | ||
for (byte i = 0; i < 10; i++) { | ||
try { | ||
byte[] output = outputs[i].get(); | ||
assertArrayEquals(new byte[] {i}, output); | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
} | ||
} | ||
} |