Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Java CI Workflow and fix DatabasePerTenantSpec.groovy #1408

Merged
merged 3 commits into from
Dec 15, 2020
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
14 changes: 8 additions & 6 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ jobs:
env:
WORKSPACE: ${{ github.workspace }}
GRADLE_OPTS: -Xmx1500m -Dfile.encoding=UTF-8
RUN_TESTS_ONLY: false
steps:
- uses: actions/checkout@v2
- uses: actions/cache@v2
Expand All @@ -33,17 +34,18 @@ jobs:
run: |
[ -f ./setup.sh ] && ./setup.sh || true
- name: Run Tests
run: ./gradlew check
run: |
./gradlew --no-daemon --refresh-dependencies clean check
- name: Publish Test Report
uses: scacap/action-surefire-report@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
report_paths: '**/build/test-results/test/TEST-*.xml'
- name: Run Assemble
if: success() && github.event_name == 'push' && matrix.java == '8'
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
run: ./gradlew assemble
- name: Publish to repo.grails.org
if: success() && github.event_name == 'push' && matrix.java == '8'
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
env:
SECRING_FILE: ${{ secrets.SECRING_FILE }}
SIGNING_KEY: ${{ secrets.SIGNING_KEY }}
Expand All @@ -54,15 +56,15 @@ jobs:
echo $SECRING_FILE | base64 -d > secring.gpg
./gradlew -Dorg.gradle.internal.publish.checksums.insecure=true -Psigning.keyId="$SIGNING_KEY" -Psigning.password="$SIGNING_PASSPHRASE" -Psigning.secretKeyRingFile="secring.gpg" publish
- name: Extract branch name
if: success() && github.event_name == 'push' && matrix.java == '8'
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
id: extract_branch
run: echo ::set-output name=value::${GITHUB_REF:11}
- name: Create Snapshot Message for the Workflow Dispatch
if: success() && github.event_name == 'push' && matrix.java == '8'
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
id: dispatch_message
run: echo ::set-output name=value::{\"message\":\"New Core Snapshot $(date) - $GITHUB_SHA\"}
- name: Invoke the Java CI workflow in GORM Hibernate5
if: success() && github.event_name == 'push' && matrix.java == '8'
if: success() && github.event_name == 'push' && matrix.java == '8' && env.RUN_TESTS_ONLY == false
uses: benc-uk/[email protected]
with:
workflow: Java CI
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package grails.gorm.services.multitenancy.database

import grails.gorm.MultiTenant
import grails.gorm.annotation.Entity

@Entity
class Book implements MultiTenant<Book> {
String title
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package grails.gorm.services.multitenancy.database

import grails.gorm.multitenancy.CurrentTenant
import grails.gorm.transactions.ReadOnly
import grails.gorm.transactions.Transactional

@CurrentTenant
@Transactional
class BookService {

void saveBook(String title) {
new Book(title: "The Stand").save()
}

@ReadOnly
int countBooks() {
Book.count()
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
package grails.gorm.services.multitenancy.database

import grails.gorm.MultiTenant
import grails.gorm.annotation.Entity
import grails.gorm.multitenancy.CurrentTenant
import grails.gorm.services.Service
import grails.gorm.transactions.ReadOnly
import grails.gorm.transactions.Transactional

import org.grails.datastore.mapping.config.Settings
import org.grails.datastore.mapping.core.DatastoreUtils
import org.grails.datastore.mapping.core.connections.ConnectionSource
import org.grails.datastore.mapping.multitenancy.MultiTenancySettings
import org.grails.datastore.mapping.multitenancy.exceptions.TenantNotFoundException
Expand All @@ -22,11 +18,11 @@ import spock.lang.Specification
class DatabasePerTenantSpec extends Specification {

@Shared @AutoCleanup SimpleMapDatastore datastore = new SimpleMapDatastore(
[(Settings.SETTING_MULTI_TENANCY_MODE) : MultiTenancySettings.MultiTenancyMode.DATABASE,
DatastoreUtils.createPropertyResolver([(Settings.SETTING_MULTI_TENANCY_MODE) : MultiTenancySettings.MultiTenancyMode.DATABASE,
(Settings.SETTING_MULTI_TENANT_RESOLVER): new SystemPropertyTenantResolver(),
(Settings.SETTING_DB_CREATE) : "create-drop"],
(Settings.SETTING_DB_CREATE) : "create-drop"]),
[ConnectionSource.DEFAULT, "foo", "bar"],
getClass().getPackage()
Book
)
@Shared IBookService bookDataService = datastore.getService(IBookService)

Expand Down Expand Up @@ -66,30 +62,7 @@ class DatabasePerTenantSpec extends Specification {
}
}

@Entity
class Book implements MultiTenant<Book> {
String title
}

@CurrentTenant
@Transactional
class BookService {

void saveBook(String title) {
new Book(title: "The Stand").save()
}

@ReadOnly
int countBooks() {
Book.count()
}
}

@CurrentTenant
@Service(Book)
interface IBookService {

Book saveBook(String title)

Integer countBooks()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package grails.gorm.services.multitenancy.database

import grails.gorm.multitenancy.CurrentTenant
import grails.gorm.services.Service

@CurrentTenant
@Service(Book)
interface IBookService {

Book saveBook(String title)

Integer countBooks()
}