Search in sources :

Example 1 with ActivateRequestContext

use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.

the class MultiplePersistenceUnitsCdiTest method testDefaultSession.

@Test
@ActivateRequestContext
public void testDefaultSession() {
    DefaultPUEntity entity = new DefaultPUEntity("someText");
    inTransaction(() -> defaultPUSession.toEntityManager().persist(entity));
    inTransaction(() -> assertThat(defaultPUSession.search(DefaultPUEntity.class).where(f -> f.matchAll()).fetchHits(20)).hasSize(1).element(0).returns(entity.getId(), DefaultPUEntity::getId));
}
Also used : DefaultPUEntity(io.quarkus.hibernate.search.elasticsearch.test.multiplepersistenceunits.defaultpu.DefaultPUEntity) ActivateRequestContext(javax.enterprise.context.control.ActivateRequestContext) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Example 2 with ActivateRequestContext

use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.

the class MultiplePersistenceUnitsCdiTest method testPU2Session.

@Test
@ActivateRequestContext
public void testPU2Session() {
    PU2Entity entity = new PU2Entity("someText");
    inTransaction(() -> pu2Session.toEntityManager().persist(entity));
    inTransaction(() -> assertThat(pu2Session.search(PU2Entity.class).where(f -> f.matchAll()).fetchHits(20)).hasSize(1).element(0).returns(entity.getId(), PU2Entity::getId));
}
Also used : PU2Entity(io.quarkus.hibernate.search.elasticsearch.test.multiplepersistenceunits.pu2.PU2Entity) ActivateRequestContext(javax.enterprise.context.control.ActivateRequestContext) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Example 3 with ActivateRequestContext

use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.

the class QuarkusTransactionTest method testCallJoinExisting.

@Test
@ActivateRequestContext
public void testCallJoinExisting() throws SystemException {
    RunOptions options = runOptions().semantic(RunOptions.Semantic.JOIN_EXISTING);
    QuarkusTransaction.begin();
    var tx = transactionManager.getTransaction();
    QuarkusTransaction.call(options, () -> {
        Assertions.assertTrue(QuarkusTransaction.isActive());
        if (tx != transactionManager.getTransaction()) {
            throw new RuntimeException("Running in different transaction");
        }
        return null;
    });
}
Also used : RunOptions(io.quarkus.narayana.jta.RunOptions) ActivateRequestContext(javax.enterprise.context.control.ActivateRequestContext) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Example 4 with ActivateRequestContext

use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.

the class QuarkusTransactionTest method testCallDisallowExisting.

@Test
@ActivateRequestContext
public void testCallDisallowExisting() {
    RunOptions options = runOptions().semantic(RunOptions.Semantic.DISALLOW_EXISTING);
    Assertions.assertEquals(Status.STATUS_COMMITTED, QuarkusTransaction.call(options, this::register).completionStatus);
    QuarkusTransaction.begin();
    Assertions.assertThrows(QuarkusTransactionException.class, () -> QuarkusTransaction.call(options, this::register));
}
Also used : RunOptions(io.quarkus.narayana.jta.RunOptions) ActivateRequestContext(javax.enterprise.context.control.ActivateRequestContext) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Example 5 with ActivateRequestContext

use of javax.enterprise.context.control.ActivateRequestContext in project quarkus by quarkusio.

the class QuarkusTransactionTest method testCallRequiresNew.

@Test
@ActivateRequestContext
public void testCallRequiresNew() throws SystemException {
    RunOptions options = runOptions().semantic(RunOptions.Semantic.REQUIRE_NEW);
    QuarkusTransaction.begin();
    var tx = transactionManager.getTransaction();
    QuarkusTransaction.call(options, () -> {
        Assertions.assertTrue(QuarkusTransaction.isActive());
        if (tx == transactionManager.getTransaction()) {
            throw new RuntimeException("Running in same transaction");
        }
        return null;
    });
}
Also used : RunOptions(io.quarkus.narayana.jta.RunOptions) ActivateRequestContext(javax.enterprise.context.control.ActivateRequestContext) QuarkusUnitTest(io.quarkus.test.QuarkusUnitTest) Test(org.junit.jupiter.api.Test)

Aggregations

ActivateRequestContext (javax.enterprise.context.control.ActivateRequestContext)9 QuarkusUnitTest (io.quarkus.test.QuarkusUnitTest)6 Test (org.junit.jupiter.api.Test)6 RunOptions (io.quarkus.narayana.jta.RunOptions)3 ArrayList (java.util.ArrayList)2 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AggregationCommand (com.redhat.cloud.notifications.models.AggregationCommand)1 CollectorRegistry (io.prometheus.client.CollectorRegistry)1 Gauge (io.prometheus.client.Gauge)1 PushGateway (io.prometheus.client.exporter.PushGateway)1 DefaultPUEntity (io.quarkus.hibernate.search.elasticsearch.test.multiplepersistenceunits.defaultpu.DefaultPUEntity)1 PU1Entity (io.quarkus.hibernate.search.elasticsearch.test.multiplepersistenceunits.pu1.PU1Entity)1 PU2Entity (io.quarkus.hibernate.search.elasticsearch.test.multiplepersistenceunits.pu2.PU2Entity)1 IOException (java.io.IOException)1 Duration (java.time.Duration)1 Duration.ofSeconds (java.time.Duration.ofSeconds)1 Instant (java.time.Instant)1 Instant.now (java.time.Instant.now)1 LocalDateTime (java.time.LocalDateTime)1