1919package net .openhft .affinity ;
2020
2121import net .openhft .affinity .testimpl .TestFileLockBasedLockChecker ;
22- import net .openhft .chronicle .testframework .process .ProcessRunner ;
22+ import net .openhft .chronicle .testframework .process .JavaProcessBuilder ;
2323import org .jetbrains .annotations .NotNull ;
2424import org .junit .Assume ;
2525import org .junit .Before ;
@@ -57,9 +57,9 @@ public void setUp() {
5757 @ Test
5858 public void shouldNotAcquireLockOnCoresLockedByOtherProcesses () throws IOException , InterruptedException {
5959 // run the separate affinity locker
60- final Process affinityLockerProcess = ProcessRunner . runClass (AffinityLockerProcess .class ,
61- new String []{ "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ()},
62- new String []{ "last" } );
60+ final Process affinityLockerProcess = JavaProcessBuilder . create (AffinityLockerProcess .class )
61+ . withJvmArguments ( "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ())
62+ . withProgramArguments ( "last" ). start ( );
6363 try {
6464 int lastCpuId = AffinityLock .PROCESSORS - 1 ;
6565
@@ -70,7 +70,7 @@ public void shouldNotAcquireLockOnCoresLockedByOtherProcesses() throws IOExcepti
7070 if (System .currentTimeMillis () > endTime ) {
7171 LOGGER .info ("Timed out waiting for the lock to be acquired: isAlive={}, exitCode={}" ,
7272 affinityLockerProcess .isAlive (), affinityLockerProcess .isAlive () ? "N/A" : affinityLockerProcess .exitValue ());
73- ProcessRunner .printProcessOutput ("AffinityLockerProcess" , affinityLockerProcess );
73+ JavaProcessBuilder .printProcessOutput ("AffinityLockerProcess" , affinityLockerProcess );
7474 fail ("Timed out waiting for the sub-process to acquire the lock" );
7575 }
7676 }
@@ -90,9 +90,9 @@ public void shouldAllocateCoresCorrectlyUnderContention() throws IOException, In
9090 List <Process > lockers = new ArrayList <>();
9191 LOGGER .info ("Running test with {} locker processes" , numberOfLockers );
9292 for (int i = 0 ; i < numberOfLockers ; i ++) {
93- lockers .add (ProcessRunner . runClass (RepeatedAffinityLocker .class ,
94- new String []{ "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ()},
95- new String []{ "last" , "30" , "2" } ));
93+ lockers .add (JavaProcessBuilder . create (RepeatedAffinityLocker .class )
94+ . withJvmArguments ( "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ())
95+ . withProgramArguments ( "last" , "30" , "2" ). start ( ));
9696 }
9797 for (int i = 0 ; i < numberOfLockers ; i ++) {
9898 final Process process = lockers .get (i );
@@ -105,11 +105,11 @@ public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOE
105105 final int numberOfLockers = Math .max (2 , Math .min (12 , Runtime .getRuntime ().availableProcessors ())) / 2 ;
106106 List <Process > lockers = new ArrayList <>();
107107 LOGGER .info ("Running test with {} locker processes" , numberOfLockers );
108- Process lockFileDropper = ProcessRunner . runClass (LockFileDropper .class );
108+ Process lockFileDropper = JavaProcessBuilder . create (LockFileDropper .class ). start ( );
109109 for (int i = 0 ; i < numberOfLockers ; i ++) {
110- lockers .add (ProcessRunner . runClass (RepeatedAffinityLocker .class ,
111- new String []{ "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ()},
112- new String []{ "last" , "30" , "2" } ));
110+ lockers .add (JavaProcessBuilder . create (RepeatedAffinityLocker .class )
111+ . withJvmArguments ( "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ())
112+ . withProgramArguments ( "last" , "30" , "2" ). start ( ));
113113 }
114114 for (int i = 0 ; i < numberOfLockers ; i ++) {
115115 final Process process = lockers .get (i );
@@ -121,9 +121,9 @@ public void shouldAllocateCoresCorrectlyUnderContentionWithFailures() throws IOE
121121
122122 @ Test
123123 public void shouldBeAbleToAcquireLockLeftByOtherProcess () throws IOException , InterruptedException {
124- final Process process = ProcessRunner . runClass (AffinityLockerThatDoesNotReleaseProcess .class ,
125- new String []{ "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ()},
126- new String []{ "last" } );
124+ final Process process = JavaProcessBuilder . create (AffinityLockerThatDoesNotReleaseProcess .class )
125+ . withJvmArguments ( "-Djava.io.tmpdir=" + folder .getRoot ().getAbsolutePath ())
126+ . withProgramArguments ( "last" ). start ( );
127127 waitForProcessToEnd (5 , "Locking process" , process );
128128 // We should be able to acquire the lock despite the other process not explicitly releasing it
129129 try (final AffinityLock acquired = AffinityLock .acquireLock ("last" )) {
@@ -137,11 +137,11 @@ private void waitForProcessToEnd(int timeToWaitSeconds, String processDescriptio
137137
138138 private void waitForProcessToEnd (int timeToWaitSeconds , String processDescription , Process process , boolean checkExitCode ) throws InterruptedException {
139139 if (!process .waitFor (timeToWaitSeconds , TimeUnit .SECONDS )) {
140- ProcessRunner .printProcessOutput (processDescription , process );
140+ JavaProcessBuilder .printProcessOutput (processDescription , process );
141141 fail (processDescription + " didn't end in time" );
142142 }
143143 if (checkExitCode && process .exitValue () != 0 ) {
144- ProcessRunner .printProcessOutput (processDescription , process );
144+ JavaProcessBuilder .printProcessOutput (processDescription , process );
145145 fail (processDescription + " failed, see output above (exit value " + process .exitValue () + ")" );
146146 }
147147 }
0 commit comments