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

Chore: version bump Spring boot 3.2.2 Infinitic 0.12.1" #32

Merged
merged 2 commits into from
Feb 9, 2024
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
2 changes: 1 addition & 1 deletion infinitic-spring-boot-3-example/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {

group = "com.tiarebalbi.example"
version = "0.0.1-SNAPSHOT"
extra["infiniticVersion"] = "0.11.6"
extra["infiniticVersion"] = "0.11.7"

java {
sourceCompatibility = JavaVersion.VERSION_17
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.tiarebalbi.example

import com.tiarebalbi.example.demo.DemoService
import io.infinitic.clients.InfiniticClient
import org.springframework.beans.factory.InitializingBean
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication
Expand All @@ -18,7 +19,9 @@ fun main(args: Array<String>) {
class Config {

@Bean
fun initService(demoService: DemoService) = InitializingBean {
demoService.runDemoFlow()
fun initService(demoService: DemoService, client: InfiniticClient) = InitializingBean {
val execution = client.dispatch(demoService::runDemoFlow)
println("Execution id: ${execution.id}")
println("Result: ${execution.await()}")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@ import org.springframework.stereotype.Service

@Service
class DemoService(private val infiniticClient: InfiniticClient) {
fun runDemoFlow() {
fun runDemoFlow(): String {
val event = this.infiniticClient.newWorkflow(AnnotatedWorkflow::class.java)
val result = event.concatABC("Demo-")
println("Result: $result")

return result
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.tiarebalbi.infinitic.spring

import io.infinitic.clients.InfiniticClient
import io.infinitic.pulsar.config.ClientConfig
import io.infinitic.workers.InfiniticWorker
import io.infinitic.workers.config.WorkerConfig
import org.slf4j.LoggerFactory
import org.springframework.beans.factory.InitializingBean
import org.springframework.boot.autoconfigure.AutoConfiguration
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty
Expand All @@ -17,33 +14,46 @@ import org.springframework.core.io.ResourceLoader
/**
* Configuration class for Infinitic Auto-Configuration.
*
* This class is responsible for configuring the Infinitic library based on the provided application properties.
* It creates an InfiniticClient and configures it with the specified client configuration file.
* This class is responsible for configuring the Infinitic library based on
* the provided application properties. It creates an InfiniticClient and
* configures it with the specified client configuration file.
*
* This class is annotated with `@Configuration` to indicate that it should be processed by Spring's application context.
* It is also annotated with `@ConditionalOnProperty` to conditionally enable this configuration based on the value of the
* "infinitic.enabled" property. If the property is not present or has a value other than "true", this configuration will
* This class is annotated with `@Configuration` to indicate that it should
* be processed by Spring's application context. It is also annotated with
* `@ConditionalOnProperty` to conditionally enable this configuration
* based on the value of the "infinitic.enabled" property. If the property
* is not present or has a value other than "true", this configuration will
* not be loaded.
*
* Configuration properties can be provided using the `InfiniticProperties` class, which is enabled with the
* `@EnableConfigurationProperties` annotation.
* Configuration properties can be provided using the `InfiniticProperties`
* class, which is enabled with the `@EnableConfigurationProperties`
* annotation.
*
* The InfiniticAutoConfiguration class requires two constructor arguments: `InfiniticProperties` and `ResourceLoader`.
* The InfiniticAutoConfiguration class requires two constructor arguments:
* `InfiniticProperties` and `ResourceLoader`.
*
* The `InfiniticProperties` argument is used to access the configuration properties for the Infinitic library,
* including the location of the client configuration file.
* The `InfiniticProperties` argument is used to access the configuration
* properties for the Infinitic library, including the location of the
* client configuration file.
*
* The `ResourceLoader` argument is used to load the client configuration file from the classpath or file system.
* The `ResourceLoader` argument is used to load the client configuration
* file from the classpath or file system.
*
* The `configureClient` method is annotated with `@Bean`, `@ConditionalOnProperty`, and `@ConditionalOnMissingBean`.
* It creates and configures an InfiniticClient bean if the "infinitic.client.enabled" property is present and has a
* value of "true". It uses the `getClientConfig` method to obtain the client configuration.
* The `configureClient` method is annotated with `@Bean`,
* `@ConditionalOnProperty`, and `@ConditionalOnMissingBean`. It creates
* and configures an InfiniticClient bean if the "infinitic.client.enabled"
* property is present and has a value of "true". It uses the
* `getClientConfig` method to obtain the client configuration.
*
* The `getClientConfig` method retrieves the client configuration file location from the `InfiniticProperties` object,
* loads the file using the `ResourceLoader`, and creates a `ClientConfig` object from the loaded file.
* The `getClientConfig` method retrieves the client configuration file
* location from the `InfiniticProperties` object, loads the file using the
* `ResourceLoader`, and creates a `ClientConfig` object from the loaded
* file.
*
* @param properties the InfiniticProperties object containing the configuration properties for the Infinitic library
* @param resourceLoader the ResourceLoader object used to load the client configuration file
* @param properties the InfiniticProperties object containing the
* configuration properties for the Infinitic library
* @param resourceLoader the ResourceLoader object used to load the client
* configuration file
* @author tiare.balbi
*/
@AutoConfiguration
Expand All @@ -62,40 +72,42 @@ class InfiniticAutoConfiguration(
@Bean
@ConditionalOnProperty(name = ["infinitic.worker.enabled"], havingValue = "true")
@ConditionalOnMissingBean
fun configureWorker() =
InitializingBean {
val config = getWorkerConfig()
InfiniticWorker.fromConfig(config).use {
logger.info("Starting infinitic worker")
if (properties.worker.executionMode.isAsync()) {
it.startAsync()
} else {
it.start()
}
fun configureWorker(): InfiniticWorker {
val config = getWorkerConfig()
val worker = InfiniticWorker.fromConfigFile(config)
worker.use {
logger.info("Starting infinitic worker")
if (properties.worker.executionMode.isAsync()) {
it.startAsync()
} else {
it.start()
}
}

return worker
}

@Bean
@ConditionalOnProperty(name = ["infinitic.client.enabled"], havingValue = "true")
@ConditionalOnMissingBean
fun configureClient(): InfiniticClient {
logger.info("Configuring infinitic client")
return InfiniticClient.fromConfig(getClientConfig(), getWorkerConfig())
return InfiniticClient.fromConfigFile(getClientConfig(), getWorkerConfig())
}

private fun getClientConfig(): ClientConfig {
private fun getClientConfig(): String {
val configuration =
properties.client.configuration
?: throw IllegalStateException("Unable to find client configuration file for infinitic.")
val configurationFile = resourceLoader.getResource(configuration)
return ClientConfig.fromFile(configurationFile.file.absolutePath)
return configurationFile.file.absolutePath
}

private fun getWorkerConfig(): WorkerConfig {
private fun getWorkerConfig(): String {
val configuration =
properties.worker.configuration
?: throw IllegalStateException("Unable to find worker infinitic configuration")
val configurationFile = resourceLoader.getResource(configuration)
return WorkerConfig.fromFile(configurationFile.file.absolutePath)
return configurationFile.file.absolutePath
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,26 @@ package com.tiarebalbi.infinitic.spring

import com.tiarebalbi.infinitic.tests.AnnotatedWorkflow
import io.infinitic.clients.InfiniticClient
import io.infinitic.workers.InfiniticWorker
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest(classes = [InfiniticAutoConfiguration::class], properties = ["infinitic.enabled=true"])
@SpringBootTest(classes = [InfiniticAutoConfiguration::class])
class InfiniticAutoConfigurationTest {
@Autowired
private lateinit var infiniticClient: InfiniticClient

@Autowired
private lateinit var infiniticWorker: InfiniticWorker

@Test
fun `should be able to trigger flow`() {
val event = this.infiniticClient.newWorkflow(AnnotatedWorkflow::class.java)
val result = event.concatABC("Demo-")
val event: AnnotatedWorkflow =
this.infiniticClient.newWorkflow(AnnotatedWorkflow::class.java, setOf("unit-test"))
val result = this.infiniticClient.dispatch(event::concatABC, "Demo-")

assertThat(result).isEqualTo("Demo-abc")
assertThat(result.await()).isEqualTo("Demo-abc")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ infinitic.enabled=true

## Worker Setting
infinitic.worker.enabled=true
infinitic.worker.configuration=classpath:infinitic-worker.yml
infinitic.worker.configuration=classpath:infinitic-test.yml

## Client Setting
infinitic.client.enabled=true
infinitic.client.configuration=classpath:infinitic-client.yml
infinitic.client.configuration=classpath:infinitic-test.yml

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,11 @@ services:
workflows:
- name: annotatedWorkflow
class: com.tiarebalbi.infinitic.tests.AnnotatedWorkflowImpl
concurrency: 5
concurrency: 5

workflowDefault:
concurrency: 5
timeoutInSeconds: 30
retry:
maximumRetries: 6
checkMode: strict