GH-8869: Fix NPE in RedisLockRegistry.setExecutor

Fixes: #8869

Do not set the `redisMessageListenerContainer`'s executor in the setter method
since the Redis Message Listener container is not initialised during configuration due to lazy loading

**Cherry-pick to `6.2.x` & `6.0.x`**
This commit is contained in:
Neville Bonavia
2024-01-26 02:31:21 -05:00
committed by Artem Bilan
parent 35f3a87109
commit 62fd3e6c20
2 changed files with 12 additions and 4 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -198,8 +198,6 @@ public final class RedisLockRegistry implements ExpirableLockRegistry, Disposabl
public void setExecutor(Executor executor) {
this.executor = executor;
this.executorExplicitlySet = true;
this.redisMessageListenerContainer.setTaskExecutor(this.executor);
this.redisMessageListenerContainer.setSubscriptionExecutor(this.executor);
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2023 the original author or authors.
* Copyright 2014-2024 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,6 +41,7 @@ import org.apache.commons.logging.LogFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.EnumSource;
@@ -52,6 +53,8 @@ import org.springframework.integration.test.util.TestUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
import static org.assertj.core.api.Assertions.assertThatNoException;
import static org.mockito.Mockito.mock;
/**
* @author Gary Russell
@@ -875,6 +878,13 @@ class RedisLockRegistryTests implements RedisContainerTest {
registry.destroy();
}
@Test
void testInitialiseWithCustomExecutor() {
RedisLockRegistry redisLockRegistry = new RedisLockRegistry(redisConnectionFactory, "registryKey");
redisLockRegistry.setRedisLockType(RedisLockType.PUB_SUB_LOCK);
assertThatNoException().isThrownBy(() -> redisLockRegistry.setExecutor(mock()));
}
private Long getExpire(RedisLockRegistry registry, String lockKey) {
StringRedisTemplate template = createTemplate();
String registryKey = TestUtils.getPropertyValue(registry, "registryKey", String.class);