Skip to content

Commit

Permalink
Fix some JAK bugs (#97)
Browse files Browse the repository at this point in the history
  • Loading branch information
bmeike authored Nov 23, 2024
1 parent 057714e commit a385369
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
6 changes: 3 additions & 3 deletions jenkins/pipelines/java/webservice/win_tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ try
$temp = New-TemporaryFile
Write-Host "Windows Web Service: Build and start the Test Server"
Remove-Item -Recurse -Force -ErrorAction SilentlyContinue app\build server.log, app\server.url
$app = Start-Process .\gradlew.bat -ArgumentList "--no-daemon jettyStart -PcblVersion="${cblVersion}" -PassThru -WindowStyle Hidden -RedirectStandardInput $temp -RedirectStandardOutput server.log -RedirectStandardError server.err
$app = Start-Process .\gradlew.bat -ArgumentList "--no-daemon jettyStart -PcblVersion=${cblVersion}" -PassThru -WindowStyle Hidden -RedirectStandardInput $temp -RedirectStandardOutput server.log -RedirectStandardError server.err
Write-Host "Windows Web Service: Server started: $($app.ProcessName), $($app.Id)"
Pop-Location

Expand Down Expand Up @@ -94,14 +94,14 @@ finally
Pop-Location
Set-Location servers\jak\webservice

if ( $app -ne $null )
if ( $null -ne $app )
{
Write-Host "Windows Web Service: Stopping process $($app.ProcessName), $($app.Id)"
Stop-Process $app
}

Write-Host "Windows Web Service: Stopping the server"
& .\gradlew.bat --no-daemon appStop -PcblVersion="${cblVersion}
& .\gradlew.bat --no-daemon appStop -PcblVersion="${cblVersion}"

Write-Host "Windows Web Service: Exiting"
Exit $status
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.couchbase.lite.javadesktop.mobiletest;

import androidx.annotation.GuardedBy;

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
Expand All @@ -10,6 +12,7 @@
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.atomic.AtomicReference;

import edu.umd.cs.findbugs.annotations.Nullable;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import org.apache.commons.daemon.Daemon;
import org.apache.commons.daemon.DaemonContext;
Expand All @@ -26,7 +29,10 @@ public class TestServerApp implements Daemon {

private static final AtomicReference<TestServerApp> APP = new AtomicReference<>();
private static final AtomicReference<Server> SERVER = new AtomicReference<>();
private static final AtomicReference<CountDownLatch> STOP_LATCH = new AtomicReference<>();

@Nullable
@GuardedBy("TAG")
private static CountDownLatch stopLatch;

/**
* Main method runs as non-service mode for debugging use
Expand Down Expand Up @@ -82,8 +88,7 @@ private static void startApp() {
@SuppressFBWarnings("UW_UNCOND_WAIT")
private static void waitForStop() {
while ((SERVER.get()) != null) {
final CountDownLatch stopLatch = new CountDownLatch(1);
STOP_LATCH.set(stopLatch);
synchronized (TAG) { stopLatch = new CountDownLatch(1); }
try { stopLatch.await(); }
catch (InterruptedException ignore) { }
}
Expand Down Expand Up @@ -124,8 +129,9 @@ public void stop() {
final Server server = SERVER.getAndSet(null);
if (server != null) { server.stop(); }

final CountDownLatch stopLatch = STOP_LATCH.get();
if (stopLatch != null) { stopLatch.countDown(); }
synchronized (TAG) {
if (stopLatch != null) { stopLatch.countDown(); }
}

Log.p(TAG, "Java Desktop Test Server Stopped.");
}
Expand Down

0 comments on commit a385369

Please sign in to comment.