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 Dec 22, 2023
1 parent 2ae6d52 commit 4a7a042
Show file tree
Hide file tree
Showing 30 changed files with 1,299 additions and 67 deletions.

Large diffs are not rendered by default.

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 4a7a042

Please sign in to comment.