Skip to content

Commit

Permalink
Merge pull request #143 from graben/xanodes
Browse files Browse the repository at this point in the history
Compute XA recovery nodes from node identifier by default
  • Loading branch information
geoand authored Jun 21, 2024
2 parents 7c0cd3f + af0ed42 commit 275ac77
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public class NarayanaProperties {
/**
* XA recovery nodes.
*/
private List<String> xaRecoveryNodes = List.of("1");
private List<String> xaRecoveryNodes = List.of();

public String getLogDir() {
return this.logDir;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ private void setNodeIdentifier(String nodeIdentifier) {
}

private void setXARecoveryNodes(List<String> xaRecoveryNodes) {
if (xaRecoveryNodes.isEmpty()) {
xaRecoveryNodes = List.of(getPopulator(CoreEnvironmentBean.class).getNodeIdentifier());
}
getPopulator(JTAEnvironmentBean.class).setXaRecoveryNodes(xaRecoveryNodes);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package dev.snowdrop.boot.narayana.core.properties;

import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -56,6 +55,8 @@ void shouldSetDefaultProperties() {

assertThat(BeanPopulator.getDefaultInstance(CoreEnvironmentBean.class)
.getNodeIdentifier()).isEqualTo("1");
assertThat(BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class)
.getXaRecoveryNodes()).containsOnly("1");
assertThat(BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class)
.getObjectStoreDir()).contains("ObjectStore");
assertThat(BeanPopulator
Expand All @@ -75,7 +76,7 @@ void shouldSetDefaultProperties() {
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getExpiryScanInterval()).isEqualTo(12);

List<String> xaResourceOrphanFilters = Arrays.asList(
List<String> xaResourceOrphanFilters = List.of(
"com.arjuna.ats.internal.jta.recovery.arjunacore.JTATransactionLogXAResourceOrphanFilter",
"com.arjuna.ats.internal.jta.recovery.arjunacore.JTANodeNameXAResourceOrphanFilter",
"com.arjuna.ats.internal.jta.recovery.arjunacore.JTAActionStatusServiceXAResourceOrphanFilter");
Expand All @@ -95,15 +96,15 @@ void shouldSetDefaultProperties() {
.getCommitMarkableResourceJNDINames())
.isEmpty();

List<String> recoveryModules = Arrays.asList(
List<String> recoveryModules = List.of(
"com.arjuna.ats.internal.jta.recovery.arjunacore.CommitMarkableResourceRecordRecoveryModule",
"com.arjuna.ats.internal.arjuna.recovery.AtomicActionRecoveryModule",
"com.arjuna.ats.internal.txoj.recovery.TORecoveryModule",
"com.arjuna.ats.internal.jta.recovery.arjunacore.XARecoveryModule");
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getRecoveryModuleClassNames()).isEqualTo(recoveryModules);

List<String> expiryScanners = Arrays.asList(
List<String> expiryScanners = List.of(
"com.arjuna.ats.internal.arjuna.recovery.ExpiredTransactionStatusManagerScanner");
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getExpiryScannerClassNames()).isEqualTo(expiryScanners);
Expand All @@ -115,22 +116,25 @@ void shouldSetDefaultProperties() {
@Test
void shouldSetModifiedProperties() {
NarayanaProperties narayanaProperties = new NarayanaProperties();
narayanaProperties.setTransactionManagerId("test-id");
narayanaProperties.setTransactionManagerId("test-id-1");
narayanaProperties.setXaRecoveryNodes(List.of("test-id-1", "test-id-2"));
narayanaProperties.setLogDir("test-dir");
narayanaProperties.setDefaultTimeout(1);
narayanaProperties.setPeriodicRecoveryPeriod(2);
narayanaProperties.setRecoveryBackoffPeriod(3);
narayanaProperties.setOnePhaseCommit(false);
narayanaProperties.setXaResourceOrphanFilters(Arrays.asList("test-filter-1", "test-filter-2"));
narayanaProperties.setRecoveryModules(Arrays.asList("test-module-1", "test-module-2"));
narayanaProperties.setExpiryScanners(Arrays.asList("test-scanner-1", "test-scanner-2"));
narayanaProperties.setXaResourceOrphanFilters(List.of("test-filter-1", "test-filter-2"));
narayanaProperties.setRecoveryModules(List.of("test-module-1", "test-module-2"));
narayanaProperties.setExpiryScanners(List.of("test-scanner-1", "test-scanner-2"));

NarayanaPropertiesInitializer narayanaPropertiesInitializer =
new NarayanaPropertiesInitializer(narayanaProperties);
narayanaPropertiesInitializer.afterPropertiesSet();

assertThat(BeanPopulator.getDefaultInstance(CoreEnvironmentBean.class)
.getNodeIdentifier()).isEqualTo("test-id");
.getNodeIdentifier()).isEqualTo("test-id-1");
assertThat(BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class)
.getXaRecoveryNodes()).containsExactly("test-id-1", "test-id-2");
assertThat(BeanPopulator.getDefaultInstance(ObjectStoreEnvironmentBean.class)
.getObjectStoreDir()).isEqualTo("test-dir");
assertThat(BeanPopulator
Expand All @@ -149,12 +153,12 @@ void shouldSetModifiedProperties() {
.getRecoveryBackoffPeriod()).isEqualTo(3);
assertThat(BeanPopulator.getDefaultInstance(JTAEnvironmentBean.class)
.getXaResourceOrphanFilterClassNames())
.isEqualTo(Arrays.asList("test-filter-1", "test-filter-2"));
.isEqualTo(List.of("test-filter-1", "test-filter-2"));
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getRecoveryModuleClassNames())
.isEqualTo(Arrays.asList("test-module-1", "test-module-2"));
.isEqualTo(List.of("test-module-1", "test-module-2"));
assertThat(BeanPopulator.getDefaultInstance(RecoveryEnvironmentBean.class)
.getExpiryScannerClassNames())
.isEqualTo(Arrays.asList("test-scanner-1", "test-scanner-2"));
.isEqualTo(List.of("test-scanner-1", "test-scanner-2"));
}
}

0 comments on commit 275ac77

Please sign in to comment.