Skip to content

Commit

Permalink
ID-4250: fikse config, fjerne dependabot (#22)
Browse files Browse the repository at this point in the history
* fikse config, fjerne dependabot

* fikse config, fjerne dependabot

* testfix

* test with one node
  • Loading branch information
annemarte authored May 13, 2024
1 parent 6f9e694 commit df31387
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 27 deletions.
25 changes: 0 additions & 25 deletions .github/dependabot.yml

This file was deleted.

12 changes: 12 additions & 0 deletions eidas-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,18 @@
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,11 @@ private LettuceConnectionFactory createSentinelConnectionFactory() {
RedisSentinelConfiguration sentinelConfig = new RedisSentinelConfiguration()
.master(sentinelMaster);

for (int i = 1; i < nodes.size(); i++) {
String[] parts = nodes.get(i).split(":");
for (String node : nodes) {
String[] parts = node.split(":");
if(parts.length != 2) {
throw new IllegalArgumentException(String.format("Invalid sentinel node configuration %s", node));
}
sentinelConfig.sentinel(parts[0], Integer.parseInt(parts[1]));
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package no.idporten.eidas.redis.cache;

import org.junit.Before;
import org.junit.Test;
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory;

import static org.junit.Assert.*;


public class RedisConfigTest {

private RedisConfig config;


@Before
public void setUp() {
config = new RedisConfig();
config.setRedisHost("localhost");
config.setRedisPort("6379");
config.setRedisPassword("password");
}

@Test
public void testStandaloneRedisConnectionFactory() {
config.setSentinelNodes(null);
LettuceConnectionFactory factory = config.redisConnectionFactory();
assertNotNull(factory);
assertEquals("localhost", factory.getHostName());
assertEquals(6379, factory.getPort());
assertFalse(factory.isRedisSentinelAware());
}

@Test(expected = IllegalArgumentException.class)
public void testStandaloneRedisConnectionFactoryMissingHost() {
config.setRedisHost(null);
config.redisConnectionFactory();
}

@Test
public void testSentinelRedisConnectionFactory() {
config.setSentinelNodes("node1:26379");
config.setSentinelMaster("mymaster");
LettuceConnectionFactory factory = config.redisConnectionFactory();
assertNotNull(factory);
assertTrue(factory.isRedisSentinelAware());
}

@Test
public void testMultipleSentinelRedisConnectionFactory() {
config.setSentinelNodes("node1:26379,node2:26379");
config.setSentinelMaster("mymaster");
LettuceConnectionFactory factory = config.redisConnectionFactory();
assertNotNull(factory);
assertTrue(factory.isRedisSentinelAware());
}

@Test(expected = IllegalArgumentException.class)
public void testSentinelRedisConnectionFactoryInvalidNode() {
config.setSentinelNodes("node1:26379,invalid_node");
config.redisConnectionFactory();
}

@Test(expected = IllegalArgumentException.class)
public void testSentinelRedisConnectionFactoryMissingPassword() {
config.setSentinelNodes("node1:26379,node2:26379");
config.setSentinelMaster("mymaster");
config.setRedisPassword(null);
config.redisConnectionFactory();
}
}

0 comments on commit df31387

Please sign in to comment.