Skip to content

Commit 4e2ad32

Browse files
committed
--wip-- [skip ci]
1 parent 0e40303 commit 4e2ad32

File tree

3 files changed

+138
-0
lines changed

3 files changed

+138
-0
lines changed
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package com.redis.om.spring.annotations.hash;
2+
3+
import com.redis.om.spring.AbstractBaseEnhancedRedisTest;
4+
import com.redis.om.spring.fixtures.hash.model.Issue322User;
5+
import com.redis.om.spring.fixtures.hash.repository.Issue322UserRepository;
6+
7+
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.data.redis.core.RedisTemplate;
11+
import org.springframework.context.annotation.Bean;
12+
import org.springframework.context.annotation.Configuration;
13+
import org.springframework.context.annotation.Import;
14+
import org.springframework.data.redis.connection.RedisConnectionFactory;
15+
16+
import static org.assertj.core.api.Assertions.assertThat;
17+
18+
/**
19+
* Test to verify issue #322 is resolved: @EnableRedisEnhancedRepositories creating bean
20+
* with potential ambiguous RedisOperations beans.
21+
*
22+
* This test verifies that enhanced repositories work correctly even when multiple
23+
* RedisTemplate beans are present in the application context.
24+
*/
25+
@Import(Issue322TestContainerBeanCreationTest.AdditionalRedisConfig.class)
26+
public class Issue322TestContainerBeanCreationTest extends AbstractBaseEnhancedRedisTest {
27+
28+
@Autowired
29+
private Issue322UserRepository userRepository;
30+
31+
@Autowired(required = false)
32+
private RedisTemplate<String, String> stringRedisTemplate;
33+
34+
@Autowired
35+
private RedisTemplate<Object, Object> redisTemplate;
36+
37+
@BeforeEach
38+
void setup() {
39+
userRepository.deleteAll();
40+
}
41+
42+
@Test
43+
void testRepositoryBeanCreationWithMultipleRedisTemplates() {
44+
// This test verifies that the repository bean is created successfully
45+
// even when multiple RedisTemplate beans are available
46+
assertThat(userRepository).isNotNull();
47+
48+
// Verify that multiple Redis templates can coexist
49+
assertThat(stringRedisTemplate).isNotNull();
50+
assertThat(redisTemplate).isNotNull();
51+
52+
// Test basic repository functionality
53+
Issue322User user = new Issue322User();
54+
user.setFirstName("TestFirst");
55+
user.setLastName("TestLast");
56+
user.setEmail("[email protected]");
57+
58+
Issue322User savedUser = userRepository.save(user);
59+
assertThat(savedUser).isNotNull();
60+
assertThat(savedUser.getId()).isNotNull();
61+
62+
// Verify we can find the user
63+
assertThat(userRepository.findById(savedUser.getId())).isPresent();
64+
65+
// Test finding by indexed field
66+
assertThat(userRepository.findByEmail("[email protected]")).isPresent();
67+
}
68+
69+
@Configuration
70+
static class AdditionalRedisConfig {
71+
72+
// Create a secondary RedisTemplate that could potentially cause ambiguity
73+
// This simulates the scenario described in issue #322 where multiple
74+
// RedisTemplate beans exist
75+
@Bean
76+
public RedisTemplate<String, String> stringRedisTemplate(RedisConnectionFactory connectionFactory) {
77+
RedisTemplate<String, String> template = new RedisTemplate<>();
78+
template.setConnectionFactory(connectionFactory);
79+
template.afterPropertiesSet();
80+
return template;
81+
}
82+
}
83+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package com.redis.om.spring.fixtures.hash.model;
2+
3+
import com.redis.om.spring.annotations.Indexed;
4+
import com.redis.om.spring.annotations.Bloom;
5+
import lombok.Data;
6+
import lombok.NoArgsConstructor;
7+
import lombok.NonNull;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.data.annotation.CreatedDate;
10+
import org.springframework.data.annotation.Id;
11+
import org.springframework.data.annotation.LastModifiedDate;
12+
import org.springframework.data.redis.core.RedisHash;
13+
14+
import java.util.Date;
15+
16+
@Data
17+
@NoArgsConstructor
18+
@RequiredArgsConstructor
19+
@RedisHash
20+
public class Issue322User {
21+
@Id
22+
private String id;
23+
24+
@Indexed
25+
@NonNull
26+
private String firstName;
27+
28+
@Indexed
29+
private String middleName;
30+
31+
@Indexed
32+
@NonNull
33+
private String lastName;
34+
35+
@NonNull
36+
@Indexed
37+
@Bloom(name = "bf_user_email_322", capacity = 100000, errorRate = 0.001)
38+
private String email;
39+
40+
@CreatedDate
41+
private Date createdDate;
42+
43+
@LastModifiedDate
44+
private Date lastModifiedDate;
45+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.redis.om.spring.fixtures.hash.repository;
2+
3+
import com.redis.om.spring.fixtures.hash.model.Issue322User;
4+
import com.redis.om.spring.repository.RedisEnhancedRepository;
5+
6+
import java.util.Optional;
7+
8+
public interface Issue322UserRepository extends RedisEnhancedRepository<Issue322User, String> {
9+
Optional<Issue322User> findByEmail(String email);
10+
}

0 commit comments

Comments
 (0)