Skip to content

Commit

Permalink
build(distributed-lock): Spring 3 compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
alturkovic committed Nov 28, 2023
1 parent 0e4cd35 commit 68bbafd
Show file tree
Hide file tree
Showing 14 changed files with 121 additions and 70 deletions.
3 changes: 0 additions & 3 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,15 @@ To add the Redis dependency for an example, add the following under your `<depen

=== Compatibility

Fully compatible with Spring 3. For earlier version support check the compatibility table below.
Older versions will not be maintained or bugfixed.

|===
|Version |Spring Boot version

|2.0.0+
|3.1.5

|1.4.1+
|2.4.3

Expand Down
2 changes: 1 addition & 1 deletion distributed-lock-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.alturkovic</groupId>
<artifactId>distributed-lock</artifactId>
<version>1.5.5</version>
<version>2.0.0</version>
</parent>

<artifactId>distributed-lock-api</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion distributed-lock-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.alturkovic</groupId>
<artifactId>distributed-lock</artifactId>
<version>1.5.5</version>
<version>2.0.0</version>
</parent>

<artifactId>distributed-lock-core</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion distributed-lock-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.alturkovic</groupId>
<artifactId>distributed-lock</artifactId>
<version>1.5.5</version>
<version>2.0.0</version>
</parent>

<artifactId>distributed-lock-example</artifactId>
Expand Down
26 changes: 21 additions & 5 deletions distributed-lock-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.alturkovic</groupId>
<artifactId>distributed-lock</artifactId>
<version>1.5.5</version>
<version>2.0.0</version>
</parent>

<artifactId>distributed-lock-jdbc</artifactId>
Expand All @@ -29,14 +29,30 @@
</dependency>

<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>test</scope>
</dependency>

</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,31 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase;
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.jdbc.core.ColumnMapRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.test.context.jdbc.Sql;
import org.testcontainers.containers.PostgreSQLContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import static org.assertj.core.api.Assertions.assertThat;

@DataJdbcTest
@SpringBootTest
@Testcontainers
@Sql(value = "/locks-table-create.sql", executionPhase = Sql.ExecutionPhase.BEFORE_TEST_METHOD)
@Sql(value = "/locks-table-drop.sql", executionPhase = Sql.ExecutionPhase.AFTER_TEST_METHOD)
public class SimpleJdbcLockTest implements InitializingBean {

@Container
@ServiceConnection
private static final PostgreSQLContainer<?> postgres = new PostgreSQLContainer<>(DockerImageName.parse("postgres:alpine")).withExposedPorts(5432);

@Autowired
private JdbcTemplate jdbcTemplate;

Expand Down Expand Up @@ -161,4 +174,4 @@ private static Map<String, Object> values(final String key, final String token)

@SpringBootApplication
static class TestApplication {}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
CREATE TABLE locks (
id int NOT NULL AUTO_INCREMENT PRIMARY KEY,
id SERIAL NOT NULL,
lock_key varchar(255) UNIQUE,
token varchar(255),
expireAt TIMESTAMP,
PRIMARY KEY(`id`)
);
PRIMARY KEY(id)
);
20 changes: 15 additions & 5 deletions distributed-lock-mongo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.alturkovic</groupId>
<artifactId>distributed-lock</artifactId>
<version>1.5.5</version>
<version>2.0.0</version>
</parent>

<artifactId>distributed-lock-mongo</artifactId>
Expand All @@ -29,14 +29,24 @@
</dependency>

<dependency>
<groupId>de.flapdoodle.embed</groupId>
<artifactId>de.flapdoodle.embed.mongo</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>mongodb</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,25 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.containers.MongoDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import static org.assertj.core.api.Assertions.assertThat;

@DataMongoTest
@SpringBootTest
@Testcontainers
public class SimpleMongoLockTest implements InitializingBean {

@Container
@ServiceConnection
private static final MongoDBContainer mongo = new MongoDBContainer("mongo:latest").withExposedPorts(27017);

@Autowired
private MongoTemplate mongoTemplate;

Expand Down Expand Up @@ -129,4 +141,4 @@ public void shouldNotRefreshBecauseKeyExpired() {

@SpringBootApplication
static class TestApplication {}
}
}
21 changes: 12 additions & 9 deletions distributed-lock-redis/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<parent>
<groupId>com.github.alturkovic</groupId>
<artifactId>distributed-lock</artifactId>
<version>1.5.5</version>
<version>2.0.0</version>
</parent>

<artifactId>distributed-lock-redis</artifactId>
Expand All @@ -29,21 +29,24 @@
</dependency>

<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-bootstrap</artifactId>
<version>3.0.1</version>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.playtika.testcontainers</groupId>
<artifactId>embedded-redis</artifactId>
<version>2.0.3</version>
<groupId>org.testcontainers</groupId>
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<artifactId>spring-boot-testcontainers</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>testcontainers</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -32,23 +32,33 @@
import org.assertj.core.data.Offset;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = {
"spring.redis.host=${embedded.redis.host}",
"spring.redis.port=${embedded.redis.port}",
"spring.redis.user=${embedded.redis.user}",
"spring.redis.password=${embedded.redis.password}"
})
@SpringBootTest
@Testcontainers
public class MultiRedisLockTest implements InitializingBean {

@Container
@ServiceConnection
private static final GenericContainer<?> redis = new GenericContainer<>(DockerImageName.parse("redis:alpine")).withExposedPorts(6379);

@Autowired
private StringRedisTemplate redisTemplate;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,25 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.data.redis.core.RedisCallback;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import org.testcontainers.utility.DockerImageName;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.NONE, properties = {
"spring.redis.host=${embedded.redis.host}",
"spring.redis.port=${embedded.redis.port}",
"spring.redis.user=${embedded.redis.user}",
"spring.redis.password=${embedded.redis.password}"
})
@SpringBootTest
@Testcontainers
public class SimpleRedisLockTest implements InitializingBean {

@Container
@ServiceConnection
private static final GenericContainer<?> redis = new GenericContainer<>(DockerImageName.parse("redis:alpine")).withExposedPorts(6379);

@Autowired
private StringRedisTemplate redisTemplate;

Expand Down Expand Up @@ -131,4 +137,4 @@ public void shouldExpire() throws InterruptedException {

@SpringBootApplication
static class TestApplication {}
}
}
Loading

0 comments on commit 68bbafd

Please sign in to comment.