Skip to content

Commit

Permalink
CBL-6343, CBL-6342: Get Java test running on Jenkins (#78)
Browse files Browse the repository at this point in the history
* CBL-6281: Remote logging sketched in
  • Loading branch information
bmeike authored Oct 31, 2024
1 parent 08a41cb commit d3c4bbb
Show file tree
Hide file tree
Showing 18 changed files with 256 additions and 146 deletions.
33 changes: 32 additions & 1 deletion environment/LogSlurp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,37 @@ Note that the log is still retrievable after this call is made.
CBL-Log-ID: <id from startNewLog>
```

## Use in the E2E Test environment

The expected use case for the log slurper looks like this:

- The Python test client creates a new (probably random) session id.
- The test client calls the slurper `/startNewLog` endpoint supplying the session id. If the call is successful, the slurper is now awating logs for the new session
- The test client creates a unique 'tag' for each device involved in the test session. This tag will, essentially, name the device, during the logging session
- The test client notifies each device of the session id and the tag by which the device will identify itself. For the TestServers, this is a call to /newSession

```
{
"id": <session id>
"logging": {
"url": <logslurper hostname:port> // note that this is NOT a url
"tag": <device tag> // as described above: the "name" of the device, for this session
}
}
```

- Test devices open a websocket connection to the slurper:

```
GET ws://<slurper hostname:port>/openLogStream
CBL-Log-ID: <sessionId>
CBL-Log-Tag: <tag>
```

- If this call succeeds, test devices can log by sending simple text messages down the websocket connection
- At some point, presumeably the end of a test session, the python test client calls `/finishLog`
- In response to the call to `/finishLog`, the slurper will close all websocket connections for that session, and will refuse any new ones

## Building

There is a [Dockerfile](./LogSlurp/Dockerfile) that can be used to build an image for this server to be deployed as a service. The resulting image will be bound to port 8180 (which can be forwarded to any host port with docker commands).
Expand All @@ -74,4 +105,4 @@ hello<br />
quit<br />
<br />
==== Retrieved ====<br />
ClientLogger: 2024-08-12 23:33:34,147 hello
ClientLogger: 2024-08-12 23:33:34,147 hello
4 changes: 2 additions & 2 deletions jenkins/pipelines/android/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pipeline {
agent none
parameters {
choice(name: 'CBL_EDITION', choices: ['enterprise', 'community'], description: 'Couchbase Lite Edition')
string(name: 'CBL_VERSION', defaultValue: '3.2.0', description: 'Couchbase Lite Version')
string(name: 'CBL_VERSION', defaultValue: '', description: 'Couchbase Lite Version')
string(name: 'CBL_BUILD', defaultValue: '', description: 'Couchbase Lite Build Number')
string(name: 'SGW_URL', defaultValue: '', description: "The url of Sync Gateway to download")
}
Expand All @@ -24,7 +24,7 @@ pipeline {
echo "Run Android Tests"
sh """
#export ANDROID_SERIAL=14151JEC204776
jenkins/pipelines/android/android_tests.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD}
jenkins/pipelines/android/android_tests.sh "${params.CBL_VERSION}" "${params.CBL_BUILD}" "${params.SGW_URL}"
"""
}
post {
Expand Down
19 changes: 8 additions & 11 deletions jenkins/pipelines/android/android_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,20 @@ BUILD_TOOLS_VERSION='34.0.0'
SDK_MGR="${ANDROID_HOME}/cmdline-tools/latest/bin/sdkmanager --channel=1"

function usage() {
echo "Usage: $0 <edition> <version> <build num>"
echo "Usage: $0 <version> <build num> [<sg url>]"
exit 1
}

if [ "$#" -ne 3 ]; then usage; fi
if [ "$#" -lt 2 ] | [ "$#" -gt 3 ] ; then usage; fi

EDITION="$1"
if [ -z "$EDITION" ]; then usage; fi

VERSION="$2"
VERSION="$1"
if [ -z "$VERSION" ]; then usage; fi

BUILD_NUMBER="$3"
BUILD_NUMBER="$2"
if [ -z "$BUILD_NUMBER" ]; then usage; fi

SG_URL="$3"


echo "Install Android SDK"
yes | ${SDK_MGR} --licenses > /dev/null 2>&1
Expand All @@ -42,11 +41,9 @@ echo "Start the Test Server"
adb shell am start -a android.intent.action.MAIN -n com.couchbase.lite.android.mobiletest/.MainActivity
popd > /dev/null

echo "Start Server/SGW"
pushd environment > /dev/null
./start_environment.py
echo "Start Environment"
jenkins/pipelines/shared/setup_backend.sh "${SG_URL}"

popd > /dev/null
cp -f "jenkins/pipelines/android/config.android.json" tests

echo "Configure tests"
Expand Down
14 changes: 7 additions & 7 deletions jenkins/pipelines/java/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ pipeline {
agent none
parameters {
choice(name: 'CBL_EDITION', choices: ['enterprise', 'community'], description: 'Couchbase Lite Edition')
string(name: 'CBL_VERSION', defaultValue: '3.2.0', description: 'Couchbase Lite Version')
string(name: 'CBL_VERSION', defaultValue: '', description: 'Couchbase Lite Version')
string(name: 'CBL_BUILD', defaultValue: '', description: 'Couchbase Lite Build Number')
string(name: 'SGW_URL', defaultValue: '', description: "The url of Sync Gateway to download")
}
Expand All @@ -29,7 +29,7 @@ pipeline {
stage('OSX Desktop Tests') {
steps {
sh """
jenkins/pipelines/java/desktop/osx_tests.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD}
jenkins/pipelines/java/desktop/osx_tests.sh "${params.CBL_VERSION}" "${params.CBL_BUILD}" "${params.SGW_URL}"
"""
}
post {
Expand All @@ -45,7 +45,7 @@ pipeline {
when { expression { true } }
steps {
sh """
jenkins/pipelines/java/webservice/osx_tests.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD}
jenkins/pipelines/java/webservice/osx_tests.sh "${params.CBL_VERSION}" "${params.CBL_BUILD}" "${params.SGW_URL}"
"""
}
post {
Expand All @@ -65,7 +65,7 @@ pipeline {
stage('Windows Desktop Tests') {
steps {
pwsh """
jenkins/pipelines/java/desktop/win_tests.ps1 ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD}
jenkins/pipelines/java/desktop/win_tests.ps1 "${params.CBL_VERSION}" "${params.CBL_BUILD}" "${params.SGW_URL}"
"""
}
post {
Expand All @@ -81,7 +81,7 @@ pipeline {
when { expression { false } }
steps {
pwsh """
jenkins/pipelines/java/webservice/win_tests.ps1 ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD}
jenkins/pipelines/java/webservice/win_tests.ps1 "${params.CBL_VERSION}" "${params.CBL_BUILD}" "${params.SGW_URL}"
"""
}
post {
Expand All @@ -101,7 +101,7 @@ pipeline {
stage('Linux Desktop Tests') {
steps {
sh """
jenkins/pipelines/java/desktop/linux_tests.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD}
jenkins/pipelines/java/desktop/linux_tests.sh "${params.CBL_VERSION}" "${params.CBL_BUILD}" "${params.SGW_URL}"
"""
}
post {
Expand All @@ -117,7 +117,7 @@ pipeline {
when { expression { false } }
steps {
sh """
jenkins/pipelines/java/webservice/linux_tests.sh ${params.CBL_EDITION} ${params.CBL_VERSION} ${params.CBL_BUILD}
jenkins/pipelines/java/webservice/linux_tests.sh "${params.CBL_VERSION}" "${params.CBL_BUILD}" "${params.SGW_URL}"
"""
}
post {
Expand Down
2 changes: 1 addition & 1 deletion jenkins/pipelines/java/desktop/config_java_desktop.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://packages.couchbase.com/couchbase-lite/testserver.schema.json",
"sync-gateways": [{"hostname": "localhost"}],
"sync-gateways": [{"hostname": "localhost", "tls": true}],
"couchbase-servers": [{"hostname": "localhost"}],
"api-version": 1,
23 changes: 10 additions & 13 deletions jenkins/pipelines/java/desktop/linux_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,20 @@
LATESTBUILDS="https://latestbuilds.service.couchbase.com/builds/latestbuilds/couchbase-lite-java"

function usage() {
echo "Usage: $0 <edition> <version> <build num>"
echo "Usage: $0 <version> <build num> [<sg url>]"
exit 1
}

if [ "$#" -ne 3 ]; then usage; fi
if [ "$#" -lt 2 ] | [ "$#" -gt 3 ] ; then usage; fi

EDITION="$1"
if [ -z "$EDITION" ]; then usage; fi

VERSION="$2"
VERSION="$1"
if [ -z "$VERSION" ]; then usage; fi

BUILD_NUMBER="$3"
BUILD_NUMBER="$2"
if [ -z "$BUILD_NUMBER" ]; then usage; fi

SG_URL="$3"

# Force the Couchbase Lite Java version
pushd servers/jak > /dev/null
echo "$VERSION" > cbl-version.txt
Expand All @@ -41,13 +40,10 @@ nohup java -jar ./app/build/libs/CBLTestServer-Java-Desktop-${VERSION}-${BUILD_N
echo $! > server.pid
popd > /dev/null

echo "Start Server & SG"
pushd environment > /dev/null
./start_environment.py

popd > /dev/null
cp -f "jenkins/pipelines/java/desktop/config_java_desktop.json" tests
echo "Start Environment"
jenkins/pipelines/shared/setup_backend.sh "${SG_URL}"

echo "Wait for the Test Server..."
SERVER_FILE="servers/jak/desktop/server.url"
SERVER_URL=`cat $SERVER_FILE 2> /dev/null`
n=0
Expand All @@ -62,6 +58,7 @@ while [[ -z "$SERVER_URL" ]]; do
done

echo "Configure tests"
cp -f "jenkins/pipelines/java/desktop/config_java_desktop.json" tests
pushd tests > /dev/null
echo ' "test-servers": ["'"$SERVER_URL"'"]' >> config_java_desktop.json
echo '}' >> config_java_desktop.json
Expand Down
20 changes: 9 additions & 11 deletions jenkins/pipelines/java/desktop/osx_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@
# Build the Java Desktop test server, deploy it, and run the tests

function usage() {
echo "Usage: $0 <edition> <version> <build num>"
echo "Usage: $0 <version> <build num> [<sg url>]"
exit 1
}

if [ "$#" -ne 3 ]; then usage; fi
if [ "$#" -lt 2 ] | [ "$#" -gt 3 ] ; then usage; fi

EDITION="$1"
if [ -z "$EDITION" ]; then usage; fi

VERSION="$2"
VERSION="$1"
if [ -z "$VERSION" ]; then usage; fi

BUILD_NUMBER="$3"
BUILD_NUMBER="$2"
if [ -z "$BUILD_NUMBER" ]; then usage; fi

SG_URL="$3"


# Force the Couchbase Lite Java version
pushd servers/jak > /dev/null
echo "$VERSION" > cbl-version.txt
Expand All @@ -32,11 +32,9 @@ nohup java -jar ./app/build/libs/CBLTestServer-Java-Desktop-${VERSION}-${BUILD_N
echo $! > server.pid
popd > /dev/null

echo "Start Server & SG"
pushd environment > /dev/null
./start_environment.py
echo "Start Environment"
jenkins/pipelines/shared/setup_backend.sh "${SG_URL}"

popd > /dev/null
cp -f "jenkins/pipelines/java/desktop/config_java_desktop.json" tests

SERVER_FILE="servers/jak/desktop/server.url"
Expand Down
16 changes: 7 additions & 9 deletions jenkins/pipelines/java/desktop/win_tests.ps1
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
param (
[Parameter(Mandatory=$true)]
[string]$edition,

[Parameter(Mandatory=$true)]
[string]$version,

[Parameter(Mandatory=$true)]
[string]$buildNumber

[Parameter(Mandatory=$false)]
[string]$sgUrl,
)

# Force the Couchbase Lite Java version
Expand All @@ -27,13 +27,10 @@ $app = Start-Process java -ArgumentList "-jar .\app\build\libs\CBLTestServer-Jav
$app.Id | Out-File server.pid
Pop-Location

Write-Host "Start Server & SG"
Push-Location environment
& .\start_environment.py

Pop-Location
Copy-Item .\jenkins\pipelines\java\desktop\config_java_desktop.json -Destination tests
Write-Host "Start Environment"
& .\jenkins\pipelines\shared\setup_backend.ps1 $sgUrl

Write-Host "Wait for the Test Server..."
$n = 0
$serverUrl = ""
$urlFile = .\servers\jak\desktop\app\server.url
Expand All @@ -59,6 +56,7 @@ while ($true) {
}

Write-Host "Configure tests"
Copy-Item .\jenkins\pipelines\java\desktop\config_java_desktop.json -Destination tests
Push-Location tests
Add-Content config_java_desktop.json " `"test-servers`": [`"$serverUrl`"]"
Add-Content config_java_desktop.json '}'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "https://packages.couchbase.com/couchbase-lite/testserver.schema.json",
"sync-gateways": [{"hostname": "localhost"}],
"sync-gateways": [{"hostname": "localhost", "tls": true}],
"couchbase-servers": [{"hostname": "localhost"}],
"api-version": 1,
21 changes: 10 additions & 11 deletions jenkins/pipelines/java/webservice/linux_tests.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
#!/bin/bash
# Build and run the Java WebService test server, and run the tests

LATESTBUILDS="https://latestbuilds.service.couchbase.com/builds/latestbuilds/couchbase-lite-java"

function usage() {
echo "Usage: $0 <edition> <version> <build num>"
echo "Usage: $0 <version> <build num> [<sg url>]"
exit 1
}

if [ "$#" -ne 3 ]; then usage; fi

EDITION="$1"
if [ -z "$EDITION" ]; then usage; fi
if [ "$#" -lt 2 ] | [ "$#" -gt 3 ] ; then usage; fi

VERSION="$2"
VERSION="$1"
if [ -z "$VERSION" ]; then usage; fi

BUILD_NUMBER="$3"
BUILD_NUMBER="$2"
if [ -z "$BUILD_NUMBER" ]; then usage; fi

SG_URL="$3"

# Force the Couchbase Lite Java version
pushd servers/jak > /dev/null
echo "$VERSION" > cbl-version.txt
Expand All @@ -35,12 +36,10 @@ rm -rf server.log app/server.url
nohup ./gradlew jettyStart -PbuildNumber="${BUILD_NUMBER}" < /dev/null > server.log 2>&1 &
popd > /dev/null

echo "Start Server & SG"
pushd environment > /dev/null
./start_environment.py
echo "Start Environment"
jenkins/pipelines/shared/setup_backend.sh "${SG_URL}"

echo "Wait for the Test Server..."
popd > /dev/null
SERVER_FILE="servers/jak/webservice/app/server.url"
SERVER_URL=`cat $SERVER_FILE 2> /dev/null`
n=0
Expand Down
Loading

0 comments on commit d3c4bbb

Please sign in to comment.