Skip to content

Commit

Permalink
add test module
Browse files Browse the repository at this point in the history
  • Loading branch information
Foxcapades committed Mar 8, 2023
1 parent 619691e commit d6788bb
Show file tree
Hide file tree
Showing 75 changed files with 260 additions and 121 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.gradle/
.idea/
/build/
/build/
/lib/build/
/test/build/
125 changes: 8 additions & 117 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,127 +1,18 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm") version "1.8.0"
id("org.jetbrains.dokka") version "1.7.20"
java
`maven-publish`
}

group = "org.veupathdb.lib"
version = "1.3.6"

repositories {
mavenLocal()
mavenCentral()
maven {
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/veupathdb/maven-packages")
credentials {
username = if (extra.has("gpr.user")) extra["gpr.user"] as String? else System.getenv("GITHUB_USERNAME")
password = if (extra.has("gpr.key")) extra["gpr.key"] as String? else System.getenv("GITHUB_TOKEN")
}
}
}

dependencies {

// Logging
implementation("org.slf4j:slf4j-api:1.7.36")

// Jackson
implementation(platform("com.fasterxml.jackson:jackson-bom:2.14.2"))
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("org.veupathdb.lib:jackson-singleton:3.0.0")

// DB
implementation("com.zaxxer:HikariCP:5.0.1")
implementation("org.postgresql:postgresql:42.5.1")

// S3
implementation("org.veupathdb.lib.s3:s34k-minio:0.4.0+s34k-0.8.0")
implementation("org.veupathdb.lib.s3:workspaces:4.1.0")

// Rabbit
implementation("org.veupathdb.lib:rabbit-job-queue:1.2.0")

// Metrics
implementation("io.prometheus:simpleclient:0.16.0")
implementation("io.prometheus:simpleclient_common:0.16.0")

// Misc & Utils
api("org.veupathdb.lib:hash-id:1.0.2")

// Testing
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}

tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "17"
}

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17

withJavadocJar()
withSourcesJar()
}

tasks.javadoc {
// This is required to generate the javadoc jar when publishing a release.
exclude("module-info.java")
}

tasks.dokkaHtml {
outputDirectory.set(file("build/docs/dokka"))
}

tasks.dokkaJavadoc {
outputDirectory.set(file("build/docs/javadoc"))
}

task("docs") {
dependsOn("dokkaHtml", "dokkaJavadoc")
}

publishing {
allprojects {
repositories {
mavenLocal()
mavenCentral()
maven {
name = "GitHub"
url = uri("https://maven.pkg.github.com/VEuPathDB/lib-compute-platform")
name = "GitHubPackages"
url = uri("https://maven.pkg.github.com/veupathdb/maven-packages")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
username = if (extra.has("gpr.user")) extra["gpr.user"] as String? else System.getenv("GITHUB_USERNAME")
password = if (extra.has("gpr.key")) extra["gpr.key"] as String? else System.getenv("GITHUB_TOKEN")
}
}
}

publications {
create<MavenPublication>("gpr") {
from(components["java"])
pom {
name.set("S3 Workspaces")
description.set("Workspaces backed by an S3 object store.")
url.set("https://github.com/VEuPathDB/lib-compute-platform")
developers {
developer {
id.set("epharper")
name.set("Elizabeth Paige Harper")
email.set("epharper@upenn.edu")
url.set("https://github.com/foxcapades")
organization.set("VEuPathDB")
}
}
scm {
connection.set("scm:git:git://github.com/VEuPathDB/lib-compute-platform.git")
developerConnection.set("scm:git:ssh://github.com/VEuPathDB/lib-compute-platform.git")
url.set("https://github.com/VEuPathDB/lib-compute-platform")
}
}
}
}
}
}
112 changes: 112 additions & 0 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("jvm")
id("org.jetbrains.dokka") version "1.7.20"
java
`maven-publish`
}

group = "org.veupathdb.lib"
version = "1.3.6"


dependencies {

// Logging
implementation("org.slf4j:slf4j-api:1.7.36")

// Jackson
implementation(platform("com.fasterxml.jackson:jackson-bom:2.14.2"))
implementation("com.fasterxml.jackson.core:jackson-databind")
implementation("org.veupathdb.lib:jackson-singleton:3.0.0")

// DB
implementation("com.zaxxer:HikariCP:5.0.1")
implementation("org.postgresql:postgresql:42.5.1")

// S3
implementation("org.veupathdb.lib.s3:s34k-minio:0.4.1+s34k-0.8.0")
implementation("org.veupathdb.lib.s3:workspaces:4.1.1")

// Rabbit
implementation("org.veupathdb.lib:rabbit-job-queue:1.2.0")

// Metrics
implementation("io.prometheus:simpleclient:0.16.0")
implementation("io.prometheus:simpleclient_common:0.16.0")

// Misc & Utils
api("org.veupathdb.lib:hash-id:1.0.2")

// Testing
testImplementation(kotlin("test"))
}

tasks.test {
useJUnitPlatform()
}

kotlin {
jvmToolchain(17)
}

java {
withJavadocJar()
withSourcesJar()
}

tasks.javadoc {
// This is required to generate the javadoc jar when publishing a release.
exclude("module-info.java")
}

tasks.dokkaHtml {
outputDirectory.set(file("build/docs/dokka"))
}

tasks.dokkaJavadoc {
outputDirectory.set(file("build/docs/javadoc"))
}

task("docs") {
dependsOn("dokkaHtml", "dokkaJavadoc")
}

publishing {
repositories {
maven {
name = "GitHub"
url = uri("https://maven.pkg.github.com/VEuPathDB/lib-compute-platform")
credentials {
username = project.findProperty("gpr.user") as String? ?: System.getenv("USERNAME")
password = project.findProperty("gpr.key") as String? ?: System.getenv("TOKEN")
}
}
}

publications {
create<MavenPublication>("gpr") {
from(components["java"])
pom {
name.set("S3 Workspaces")
description.set("Workspaces backed by an S3 object store.")
url.set("https://github.com/VEuPathDB/lib-compute-platform")
developers {
developer {
id.set("epharper")
name.set("Elizabeth Paige Harper")
email.set("epharper@upenn.edu")
url.set("https://github.com/foxcapades")
organization.set("VEuPathDB")
}
}
scm {
connection.set("scm:git:git://github.com/VEuPathDB/lib-compute-platform.git")
developerConnection.set("scm:git:ssh://github.com/VEuPathDB/lib-compute-platform.git")
url.set("https://github.com/VEuPathDB/lib-compute-platform")
}
}
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package org.veupathdb.lib.compute.platform.intern.db

import org.slf4j.LoggerFactory
import java.util.zip.ZipInputStream
import kotlin.io.path.isRegularFile
import kotlin.io.path.toPath

private const val MigrationPath = "db/migrations/"

Expand All @@ -27,7 +29,7 @@ internal class DatabaseMigrator : Runnable {
Log.debug("Found {} migrations", migs.size)

if (migs.isNotEmpty()) {
QueueDB.ds!!.connection.use { con ->
QueueDB.ds.connection.use { con ->
migs.forEach {
Log.info("Executing database migration script: {}", it)
con.createStatement().use { stmt -> stmt.execute(loadSQL(it)) }
Expand All @@ -37,6 +39,8 @@ internal class DatabaseMigrator : Runnable {
}

private fun listMigrations(version: String): List<String> {
Log.trace("listMigrations(version={})", version)

val jarStream = ZipInputStream(thisJar.openStream())
val migrations = ArrayList<String>(10)

Expand All @@ -49,6 +53,8 @@ internal class DatabaseMigrator : Runnable {
if (migVersion(entry) <= version)
continue

Log.debug("found migration entry {}", entry)

migrations.add(entry)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@ import java.sql.Connection
import java.sql.ResultSet
import java.util.stream.Stream

// language=postgresql
private const val SQL = """
SELECT
job_id
, status
, queue
, config
, input_files
, created
, last_accessed
, grabbed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ private const val SQL = """
, status
, queue
, config
, input_files
, created
, last_accessed
, grabbed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,20 @@ internal object S3 {
fun listJobIDs(): Sequence<HashID> {
return s3.buckets[BucketName(config.bucket)]!!
.objects
.listSubPaths(config.rootPath)
.listSubPaths(config.rootPath.appendSlash())
.commonPrefixes()
.asSequence()
.map { it.getJobID() }
.map { try { HashID(it) } catch (e: Throwable) { null } }
.filterNotNull()
}

private fun String.appendSlash() =
if (!endsWith('/'))
"$this/"
else
this

private fun String.getJobID() =
substring(lastIndexOf('/', length - 2) + 1, length - 1)
}
4 changes: 4 additions & 0 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ publish-local:
.PHONY: docs
docs:
@gradle docs

run-test:
@./gradlew :test:shadowJar
@java -jar test/build/libs/test.jar
6 changes: 5 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@

rootProject.name = "compute-platform"

include(":lib")
project(":lib").name = "compute-platform"

include(":test")
project(":test").name = "test"
20 changes: 20 additions & 0 deletions test/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
plugins {
kotlin("jvm")
id("com.github.johnrengelman.shadow") version "7.1.2"
}

dependencies {
implementation(project(":compute-platform"))

implementation("org.slf4j:slf4j-api:1.7.36")
implementation("org.apache.logging.log4j:log4j-core:2.19.0")
runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl:2.19.0")
}

tasks.shadowJar {
archiveFileName.set("test.jar")

manifest {
attributes["Main-Class"] = "lcp.MainKt"
}
}
Loading

0 comments on commit d6788bb

Please sign in to comment.