Skip to content

Commit

Permalink
Batch custom scopes activation
Browse files Browse the repository at this point in the history
Added job/step/partition scope management
Add IT tests copied from
https://github.com/jberet/jsr352/tree/main/test-apps/cdiScopes
  • Loading branch information
luca-bassoricci committed Jan 15, 2024
1 parent 2ae6d52 commit e97e5e6
Show file tree
Hide file tree
Showing 30 changed files with 1,249 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
import jakarta.enterprise.inject.AmbiguousResolutionException;
import jakarta.inject.Named;

import org.jberet.cdi.JobScoped;
import org.jberet.cdi.PartitionScoped;
import org.jberet.cdi.StepScoped;
import org.jberet.creation.ArchiveXmlLoader;
import org.jberet.creation.BatchBeanProducer;
import org.jberet.job.model.BatchArtifacts;
Expand Down Expand Up @@ -62,12 +65,17 @@
import io.quarkiverse.jberet.runtime.JBeretRecorder;
import io.quarkiverse.jberet.runtime.JobsProducer;
import io.quarkiverse.jberet.runtime.QuarkusJobScheduler;
import io.quarkiverse.jberet.runtime.scope.QuarkusJobScopedContextImpl;
import io.quarkiverse.jberet.runtime.scope.QuarkusPartitionScopedContextImpl;
import io.quarkiverse.jberet.runtime.scope.QuarkusStepScopedContextImpl;
import io.quarkus.agroal.spi.JdbcDataSourceBuildItem;
import io.quarkus.arc.Unremovable;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.AnnotationsTransformerBuildItem;
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem;
import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem;
import io.quarkus.arc.deployment.ContextRegistrationPhaseBuildItem.ContextConfiguratorBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem;
import io.quarkus.arc.deployment.ValidationPhaseBuildItem.ValidationErrorBuildItem;
import io.quarkus.arc.processor.AnnotationsTransformer;
Expand Down Expand Up @@ -112,6 +120,14 @@ public RuntimeInitializedClassBuildItem runtimeInitializedDefaultHolder() {
return new RuntimeInitializedClassBuildItem("org.jberet.spi.JobOperatorContext$DefaultHolder");
}

@BuildStep
public void batchScopes(ContextRegistrationPhaseBuildItem c, BuildProducer<ContextConfiguratorBuildItem> v) {
v.produce(new ContextConfiguratorBuildItem(
c.getContext().configure(JobScoped.class).contextClass(QuarkusJobScopedContextImpl.class),
c.getContext().configure(StepScoped.class).contextClass(QuarkusStepScopedContextImpl.class),
c.getContext().configure(PartitionScoped.class).contextClass(QuarkusPartitionScopedContextImpl.class)));
}

@BuildStep
public void config(BuildProducer<RunTimeConfigBuilderBuildItem> runTimeConfigBuilder) {
runTimeConfigBuilder.produce(new RunTimeConfigBuilderBuildItem(JBeretConfigSourceFactoryBuilder.class.getName()));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkiverse.jberet.runtime.scope;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

import org.jberet.cdi.JobScoped;
import org.jberet.creation.JobScopedContextImpl;

import io.quarkus.arc.InjectableContext;

public class QuarkusJobScopedContextImpl implements InjectableContext {
private final JobScopedContextImpl impl;

public QuarkusJobScopedContextImpl() {
this.impl = JobScopedContextImpl.getInstance();
}

@Override
public void destroy(Contextual<?> contextual) {
this.impl.destroy(contextual);
}

@Override
public Class<? extends Annotation> getScope() {
return JobScoped.class;
}

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
return impl.get(contextual, creationalContext);
}

@Override
public <T> T get(Contextual<T> contextual) {
return impl.get(contextual);
}

@Override
public boolean isActive() {
return impl.isActive();
}

@Override
public void destroy() {
this.impl.destroy(null);
}

@Override
public ContextState getState() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkiverse.jberet.runtime.scope;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

import org.jberet.cdi.PartitionScoped;
import org.jberet.creation.PartitionScopedContextImpl;

import io.quarkus.arc.InjectableContext;

public class QuarkusPartitionScopedContextImpl implements InjectableContext {
private final PartitionScopedContextImpl impl;

public QuarkusPartitionScopedContextImpl() {
this.impl = PartitionScopedContextImpl.getInstance();
}

@Override
public void destroy(Contextual<?> contextual) {
this.impl.destroy(contextual);
}

@Override
public Class<? extends Annotation> getScope() {
return PartitionScoped.class;
}

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
return impl.get(contextual, creationalContext);
}

@Override
public <T> T get(Contextual<T> contextual) {
return impl.get(contextual);
}

@Override
public boolean isActive() {
return impl.isActive();
}

@Override
public void destroy() {
this.impl.destroy(null);
}

@Override
public ContextState getState() {
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package io.quarkiverse.jberet.runtime.scope;

import java.lang.annotation.Annotation;

import jakarta.enterprise.context.spi.Contextual;
import jakarta.enterprise.context.spi.CreationalContext;

import org.jberet.cdi.StepScoped;
import org.jberet.creation.StepScopedContextImpl;

import io.quarkus.arc.InjectableContext;

public class QuarkusStepScopedContextImpl implements InjectableContext {
private final StepScopedContextImpl impl;

public QuarkusStepScopedContextImpl() {
this.impl = StepScopedContextImpl.getInstance();
}

@Override
public void destroy(Contextual<?> contextual) {
this.impl.destroy(contextual);
}

@Override
public Class<? extends Annotation> getScope() {
return StepScoped.class;
}

@Override
public <T> T get(Contextual<T> contextual, CreationalContext<T> creationalContext) {
return impl.get(contextual, creationalContext);
}

@Override
public <T> T get(Contextual<T> contextual) {
return impl.get(contextual);
}

@Override
public boolean isActive() {
return impl.isActive();
}

@Override
public void destroy() {
this.impl.destroy(null);
}

@Override
public ContextState getState() {
return null;
}
}
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
<module>client</module>
<module>scripting</module>
<module>tck</module>
<module>scopes</module>
</modules>

<profiles>
Expand Down
44 changes: 44 additions & 0 deletions integration-tests/scopes/common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
Copyright (c) 2017 Red Hat, Inc. and/or its affiliates.
This program and the accompanying materials are made
available under the terms of the Eclipse Public License 2.0
which is available at https://www.eclipse.org/legal/epl-2.0/
SPDX-License-Identifier: EPL-2.0
-->

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>io.quarkiverse.jberet</groupId>
<artifactId>quarkus-jberet-integration-tests</artifactId>
<version>2.2.1-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>quarkus-jberet-integration-tests-scopes-commons</artifactId>
<name>Quarkus - JBeret - Commons components</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-junit5</artifactId>
</dependency>
<dependency>
<groupId>org.jberet.test-apps</groupId>
<version>${jberet.version}</version>
<artifactId>cdiScopes-commons</artifactId>
<exclusions>
<exclusion>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package io.quarkiverse.jberet.it.cdiscopes;

import jakarta.inject.Inject;

import org.jberet.testapps.common.AbstractIT;
import org.junit.jupiter.api.BeforeEach;

import io.quarkiverse.jberet.runtime.QuarkusJobOperator;

/**
* Quarkus version of JBeret {@link AbstractIT}
*/
public abstract class AbstractQuarkusIT extends AbstractIT {
@Inject
QuarkusJobOperator quarkusJobOperator;

@BeforeEach
@Override
public void before() throws Exception {
super.jobOperator = new JobOperatorImplQuarkusDelegate(quarkusJobOperator);
}
}
Loading

0 comments on commit e97e5e6

Please sign in to comment.