Skip to content

Commit

Permalink
HSEARCH-5297 Switch to narayana-spring-boot instead of atomikos
Browse files Browse the repository at this point in the history
  • Loading branch information
marko-bekhta committed Jan 2, 2025
1 parent 5e19a87 commit 3ed0965
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 56 deletions.
13 changes: 4 additions & 9 deletions build/parents/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -181,15 +181,10 @@
<version.org.wildfly.security.wildfly-security-manager>1.1.2.Final</version.org.wildfly.security.wildfly-security-manager>

<!-- >>> Spring integration tests -->
<!-- When updating Spring Boot check if it supports JDK23 and enable testing with it if so (see testWithJdk23 profile). -->
<!--
See https://github.com/atomikos/transactions-essentials/issues/234.
Atomikos has to be fixed/updated before we can bump the Spring Boot version.
-->
<version.org.springframework.boot>3.3.0</version.org.springframework.boot>
<!-- Spring Boot 3 Atomikos starter and related libs version: -->
<!-- Enable Spring Boot updates once Atomikos is updated -->
<version.com.atomikos>6.0.0</version.com.atomikos>
<!-- When updating Spring Boot check if it supports JDK24 and enable testing with it if so (see testWithJdk24 profile). -->
<version.org.springframework.boot>3.4.1</version.org.springframework.boot>
<!-- Spring Boot 3 JTA starter and related libs version: -->
<version.dev.snowdrop>3.3.1</version.dev.snowdrop>

<version.jsoup>1.18.3</version.jsoup>
<version.snakeyaml>2.3</version.snakeyaml>
Expand Down
13 changes: 9 additions & 4 deletions integrationtest/mapper/orm-spring/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>com.atomikos</groupId>
<artifactId>transactions-spring-boot3-starter</artifactId>
<version>${version.com.atomikos}</version>
<groupId>dev.snowdrop</groupId>
<artifactId>narayana-spring-boot-starter</artifactId>
<version>${version.dev.snowdrop}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.agroal</groupId>
<artifactId>agroal-spring-boot-starter</artifactId>
<version>2.5</version>
<scope>test</scope>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import com.atomikos.icatch.jta.TransactionManagerImp;
import com.arjuna.ats.arjuna.coordinator.TxControl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand Down Expand Up @@ -48,8 +48,8 @@ void checkJta() {
.getServiceRegistry().getService( TransactionCoordinatorBuilder.class ) )
.returns( true, TransactionCoordinatorBuilder::isJta );

// We changed the default Atomikos timeout to 1s (1000ms)
assertThat( TransactionManagerImp.getDefaultTimeout() ).isOne();
// We changed the default timeout to 1s (1000ms)
assertThat( TxControl.getDefaultTimeout() ).isOne();

// However, the test is not supposed to time out,
// because we raised the timeout to 60 seconds in Hibernate Search properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;

import java.util.concurrent.TimeUnit;

import jakarta.persistence.EntityManagerFactory;

import org.hibernate.engine.spi.SessionFactoryImplementor;
Expand All @@ -19,7 +21,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import com.atomikos.icatch.jta.TransactionManagerImp;
import com.arjuna.ats.arjuna.coordinator.TxControl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
Expand All @@ -45,8 +47,8 @@ void checkJta() {
.getServiceRegistry().getService( TransactionCoordinatorBuilder.class ) )
.returns( true, TransactionCoordinatorBuilder::isJta );

// We changed the default Atomikos timeout to 1s (1000ms)
assertThat( TransactionManagerImp.getDefaultTimeout() ).isOne();
// We changed the default timeout to 1s (1000ms)
assertThat( TxControl.getDefaultTimeout() ).isOne();

// The test is supposed to time out
}
Expand All @@ -62,6 +64,7 @@ void test() {
snertDAO.persist( snert );

await( "Waiting for indexing assertions" )
.pollDelay( 1, TimeUnit.SECONDS )
.untilAsserted( () -> assertThat( TimeoutFailureCollector.EXCEPTIONS ).isNotEmpty() );

Throwable exception = TimeoutFailureCollector.EXCEPTIONS.iterator().next();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

import org.hibernate.search.util.impl.integrationtest.mapper.orm.DatabaseContainer;

import org.junit.jupiter.api.BeforeEach;

import com.arjuna.ats.arjuna.common.CoordinatorEnvironmentBean;
import com.arjuna.ats.arjuna.coordinator.TxControl;
import com.arjuna.common.internal.util.propertyservice.BeanPopulator;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
Expand All @@ -16,4 +22,11 @@ public abstract class AbstractMapperOrmSpringIT {
static void configureProperties(DynamicPropertyRegistry registry) {
DatabaseContainer.configuration().addAsSpring( (key, value) -> registry.add( key, () -> value ) );
}

@BeforeEach
void setUp() {
// Because the default timeout is set as a static property it won't get reinitialized between tests on its own,
// that is why we set it ourselves here:
TxControl.setDefaultTimeout( BeanPopulator.getDefaultInstance( CoordinatorEnvironmentBean.class ).getDefaultTimeout() );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

// Adding a property here is just a "workaround" to make sure that a different context is used for this test
// otherwise there can be build errors when running all the tests via maven.
@SpringBootTest(properties = "spring.jta.atomikos.datasource.bean-name=hsearch-datasource1")
@SpringBootTest(properties = "spring.datasource.name=hsearch-datasource1")
@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_EACH_TEST_METHOD)
class TransactionIT extends AbstractMapperOrmSpringIT {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,7 @@ spring.jpa:
use_second_level_cache: false
use_query_cache: false

spring:
jta:
atomikos:
datasource:
borrow-connection-timeout: 3000
local-transaction-mode: true # allow-local-transactions ?
min-pool-size: 5
max-pool-size: 100
properties:
transaction-manager-unique-name: xaDataSource
spring.datasource:
agroal:
min-size: 5
max-size: 100
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ spring.jpa:
internal:
configurer: org.hibernate.search.integrationtest.spring.jta.timeout.TimeoutOutboxPollingInternalConfigurer
background_failure_handler: org.hibernate.search.integrationtest.spring.jta.timeout.TimeoutFailureCollector
atomikos:
properties:
# note this value is converted to seconds (default-jta-timeout/1000) so we should keep in mind when updating it:
default-jta-timeout: 1000
narayana:
default-timeout: 1
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ spring.datasource:
url: ${JDBC_URL} # From environment variable
username: ${JDBC_USERNAME} # From environment variable
password: ${JDBC_PASSWORD} # From environment variable
generate-unique-name: false
name: hsearch-datasource
type: io.agroal.springframework.boot.AgroalDataSource
agroal:
min-size: 2
max-size: 10

logging.level:
org.springframework.core.env: DEBUG
Expand All @@ -20,13 +26,8 @@ logging.level:
org.hibernate.search.elasticsearch.client.request: DEBUG
org.hibernate.search.backend.lucene: DEBUG

# since atomikos connection pool has a max size set to 1 ...
# we will not be able to execute more than one transaction at a time, leading to errors in tests
spring:
jta:
atomikos:
datasource:
bean-name: hsearch-datasource
min-pool-size: 2
max-pool-size: 10

enabled: true
narayana:
log-dir: target/transaction-logs
14 changes: 0 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1378,20 +1378,6 @@
</properties>
</profile>

<profile>
<id>testWithJdk23</id>
<activation>
<property>
<name>java-version.test.release</name>
<value>23</value>
</property>
</activation>
<properties>
<!-- Spring Boot 3 isn't ready for JDK23 yet -->
<failsafe.spring.skip>true</failsafe.spring.skip>
</properties>
</profile>

<profile>
<id>testWithJdk24</id>
<activation>
Expand Down

0 comments on commit 3ed0965

Please sign in to comment.