Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
138 changes: 77 additions & 61 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -1,78 +1,89 @@
name: Java CI Combined

on: [push, pull_request, workflow_dispatch]
name: Java CI

on:
push:
pull_request:
workflow_dispatch:
inputs:
deploy:
description: 'Deploy to Maven Central'
type: boolean
default: false
luceeVersions:
description: 'JSON array of Lucee versions to test'
required: false
default: '[ "6/snapshot/light", "7.0/snapshot/light", "7.1/snapshot/light" ]'

jobs:
setup:
build:
runs-on: ubuntu-latest
timeout-minutes: 15
outputs:
version: ${{ steps.extract-version.outputs.VERSION }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up JDK 11
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '11'
distribution: 'temurin'

- name: Cache Maven packages
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
path: ~/.m2/repository
key: maven-${{ hashFiles('pom.xml') }}
restore-keys: maven-

- name: Extract version number
id: extract-version
run: |
VERSION=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout)
echo "::set-output name=VERSION::$VERSION"
echo "VERSION=$VERSION" >> $GITHUB_OUTPUT

- name: Cache Lucee files
uses: actions/cache@v4
with:
path: ~/work/_actions/lucee/script-runner/main/lucee-download-cache
key: lucee-downloads
- name: Build extension
run: mvn -B -e clean package

- name: Import GPG key
run: |
echo "$GPG_PRIVATE_KEY" | base64 --decode | gpg --batch --import
env:
GPG_PRIVATE_KEY: ${{ secrets.GPG_PRIVATE_KEY }}
- name: Upload Artifact
uses: actions/upload-artifact@v7
with:
name: ehcache-lex
path: target/*.lex

build-and-test:
test:
runs-on: ubuntu-latest
needs: setup
env:
LUCEE_TEST_VERSIONS_PLUS: ${{ vars.LUCEE_TEST_VERSIONS_PLUS }}
timeout-minutes: 30
needs: build
strategy:
fail-fast: false
matrix:
lucee: ${{ fromJSON(vars.LUCEE_TEST_VERSIONS_PLUS) }}
lucee: ${{ fromJSON(inputs.luceeVersions || '["6/snapshot/light", "7.0/snapshot/light", "7.1/snapshot/light"]') }}
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up JDK 11
uses: actions/setup-java@v4
- name: Cache Lucee files
uses: actions/cache@v5
with:
java-version: '11'
distribution: 'adopt'

- name: Build and Install with Maven
run: |
echo "------- Maven Install -------";
mvn -B -e -f pom.xml clean install
path: ~/work/_actions/lucee/script-runner/main/lucee-download-cache
key: lucee-downloads

- name: Upload Artifact
uses: actions/upload-artifact@v4
- name: Download extension artifact
uses: actions/download-artifact@v8
with:
name: ehcache-lex-${{ matrix.lucee.version }}
path: target/*.lex
name: ehcache-lex
path: target

- name: Set up Postgres
run: |
sudo /etc/init.d/postgresql start
sudo -u postgres psql -c 'create database lucee;'
sudo -u postgres psql -c "create user lucee with encrypted password 'lucee'";
sudo -u postgres psql -c 'grant all privileges on database lucee to lucee;'
sudo -u postgres psql -c 'grant all on schema public to lucee;' -d lucee

- name: Checkout Lucee
uses: actions/checkout@v4
uses: actions/checkout@v6
with:
repository: lucee/lucee
path: lucee
Expand All @@ -82,34 +93,38 @@ jobs:
with:
webroot: ${{ github.workspace }}/lucee/test
execute: /bootstrap-tests.cfm
luceeVersion: ${{ matrix.lucee.version }}
luceeVersionQuery: ${{ matrix.lucee.query }}
luceeVersion: ${{ matrix.lucee }}
extensionDir: ${{ github.workspace }}/target
env:
testLabels: ehcache
testAdditional: ${{ github.workspace }}/tests
LUCEE_ADMIN_PASSWORD: admin
POSTGRES_SERVER: localhost
POSTGRES_USERNAME: lucee
POSTGRES_PASSWORD: lucee
POSTGRES_PORT: 5432
POSTGRES_DATABASE: lucee

deploy:
runs-on: ubuntu-latest
needs: [build-and-test]
if: always() && needs.build-and-test.result == 'success'
timeout-minutes: 15
needs: [build, test]
if: github.event_name == 'workflow_dispatch' && inputs.deploy
steps:
- name: Checkout repository
uses: actions/checkout@v4
- uses: actions/checkout@v6

- name: Set up JDK 11
uses: actions/setup-java@v4
uses: actions/setup-java@v5
with:
distribution: 'temurin'
java-version: '11'

- name: Cache Maven packages
uses: actions/cache@v4
uses: actions/cache@v5
with:
path: ~/.m2
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: |
${{ runner.os }}-maven-
path: ~/.m2/repository
key: maven-${{ hashFiles('pom.xml') }}
restore-keys: maven-

- name: Import GPG key
run: |
Expand All @@ -119,14 +134,15 @@ jobs:

- name: Build and Deploy with Maven
env:
VERSION: ${{ needs.build.outputs.version }}
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_PASSWORD: ${{ secrets.MAVEN_PASSWORD }}
GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}
run: |
if [[ "${{ needs.setup.outputs.version }}" == *-SNAPSHOT ]]; then
echo "------- Maven Deploy snapshot on ${{ github.event_name }} -------";
mvn -B -e -f pom.xml clean deploy --settings maven-settings.xml
if [[ "$VERSION" == *-SNAPSHOT ]]; then
echo "------- Maven Deploy snapshot -------";
mvn -B -e clean deploy --settings maven-settings.xml
else
echo "------- Maven Deploy release on ${{ github.event_name }} -------";
mvn -B -e -f pom.xml clean deploy -DperformRelease=true --settings maven-settings.xml
echo "------- Maven Deploy release -------";
mvn -B -e clean deploy -DperformRelease=true --settings maven-settings.xml
fi
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ target/*
*.lock
*.DS_Store
.vscode/launch.json
/test-output
103 changes: 103 additions & 0 deletions tests/EHCacheBasicTest.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
component extends="org.lucee.cfml.test.LuceeTestCase" labels="ehcache" {

public function beforeAll() {
createCache();
}

public function run( testResults, testBox ) {

describe( "EHCache Basic Operations", function() {

beforeEach( function() {
cacheClear( "", "ehcacheBasic" );
});

it( "can put and get a value", function() {
cachePut( "basicKey", "hello world", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
var result = cacheGet( "basicKey", "ehcacheBasic" );
expect( result ).toBe( "hello world" );
});

it( "returns false for a cache miss", function() {
expect( cacheIdExists( "nonExistentKey_#createUUID()#", "ehcacheBasic" ) ).toBeFalse();
});

it( "reports contains correctly", function() {
cachePut( "existsKey", "value", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
expect( cacheIdExists( "existsKey", "ehcacheBasic" ) ).toBeTrue();
expect( cacheIdExists( "doesNotExist_#createUUID()#", "ehcacheBasic" ) ).toBeFalse();
});

it( "can remove an entry", function() {
cachePut( "removeMe", "gone soon", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
expect( cacheIdExists( "removeMe", "ehcacheBasic" ) ).toBeTrue();
cacheRemove( "removeMe", false, "ehcacheBasic" );
expect( cacheIdExists( "removeMe", "ehcacheBasic" ) ).toBeFalse();
});

it( "can clear all entries", function() {
cachePut( "clearA", "a", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
cachePut( "clearB", "b", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
cachePut( "clearC", "c", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
expect( cacheCount( "ehcacheBasic" ) ).toBe( 3 );
cacheClear( "", "ehcacheBasic" );
expect( cacheCount( "ehcacheBasic" ) ).toBe( 0 );
});

it( "can list keys", function() {
cachePut( "keyA", "a", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
cachePut( "keyB", "b", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
cachePut( "keyC", "c", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
var ids = cacheGetAllIds( cacheName: "ehcacheBasic" );
expect( ids ).toBeArray();
expect( arrayLen( ids ) ).toBe( 3 );
});

it( "can get all values", function() {
cachePut( "valA", "alpha", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
cachePut( "valB", "bravo", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
var all = cacheGetAll( cacheName: "ehcacheBasic" );
expect( all ).toBeStruct();
expect( structCount( all ) ).toBe( 2 );
});

it( "can overwrite an existing entry", function() {
cachePut( "overwrite", "first", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
expect( cacheGet( "overwrite", "ehcacheBasic" ) ).toBe( "first" );
cachePut( "overwrite", "second", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
expect( cacheGet( "overwrite", "ehcacheBasic" ) ).toBe( "second" );
});

it( "reports count correctly", function() {
expect( cacheCount( "ehcacheBasic" ) ).toBe( 0 );
cachePut( "countA", "a", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
cachePut( "countB", "b", createTimespan( 0, 0, 5, 0 ), createTimespan( 0, 0, 5, 0 ), "ehcacheBasic" );
expect( cacheCount( "ehcacheBasic" ) ).toBe( 2 );
});

});

}

private function createCache() {
application action="update" name="ehcacheBasicTest" caches={
"ehcacheBasic": {
class: "org.lucee.extension.cache.eh.EHCache",
storage: false,
custom: {
"eternal": "false",
"maxelementsinmemory": "1000",
"memoryevictionpolicy": "LRU",
"timeToIdleSeconds": "300",
"timeToLiveSeconds": "300",
"overflowtodisk": "true",
"diskpersistent": "false",
"maxelementsondisk": "10000",
"distributed": "off"
},
default: ""
}
};
}

}
21 changes: 21 additions & 0 deletions tests/EHCacheCachedWithin/Application.cfc
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
component {

this.name = "ehcacheCachedWithinTest-#hash( getCurrentTemplatePath() )#";

this.cache.function = {
class: "org.lucee.extension.cache.eh.EHCache",
storage: false,
custom: {
"eternal": "false",
"maxelementsinmemory": "1000",
"memoryevictionpolicy": "LRU",
"timeToIdleSeconds": "86400",
"timeToLiveSeconds": "86400",
"overflowtodisk": "false",
"diskpersistent": "false",
"maxelementsondisk": "0",
"distributed": "off"
}
};

}
27 changes: 27 additions & 0 deletions tests/EHCacheCachedWithin/cachedWithinFlush.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<cfscript>

function getCachedValue( id ) cachedwithin="#createTimeSpan( 0, 1, 0, 0 )#" {
return createUUID();
}

function run() {
var first = getCachedValue( 1 );
var second = getCachedValue( 1 );

if ( first != second )
throw( message: "caching broken: first != second" );

var flushed = cachedWithinFlush( getCachedValue, [ 1 ] );
if ( !flushed )
throw( message: "cachedWithinFlush returned false" );

var third = getCachedValue( 1 );
if ( third == first )
throw( message: "value not flushed: third == first" );

echo( "PASS" );
}

run();

</cfscript>
23 changes: 23 additions & 0 deletions tests/EHCacheCachedWithin/cachedWithinFlushDouble.cfm
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<cfscript>

function getCachedValue( id ) cachedwithin="#createTimeSpan( 0, 1, 0, 0 )#" {
return createUUID();
}

function run() {
getCachedValue( 999 );

var r1 = cachedWithinFlush( getCachedValue, [ 999 ] );
if ( !r1 )
throw( message: "first flush should return true, got false" );

var r2 = cachedWithinFlush( getCachedValue, [ 999 ] );
if ( r2 )
throw( message: "second flush should return false, got true" );

echo( "PASS" );
}

run();

</cfscript>
Loading