Skip to content

Commit 95b99ba

Browse files
authored
FMWK-695 Add demo applications and tests (#146)
1 parent 25b10b1 commit 95b99ba

File tree

128 files changed

+3609
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

128 files changed

+3609
-57
lines changed

asciidoc/getting-started.adoc

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ Movie document class will look the following way:
7878
[source,java]
7979
----
8080
@Value // <1>
81-
@Document(collection = "demo-service-movies") // <2>
81+
@Document(collection = "demo-simplecrud-set") // <2>
8282
@Builder(toBuilder = true) // <3>
8383
// Spring Data object creation can use all-args constructor instead of reflection which is much faster
8484
@AllArgsConstructor // <4>
@@ -107,7 +107,10 @@ Document explained:
107107
<1> https://projectlombok.org/features/Value[`@Value`] makes class immutable, all fields are made private and final,
108108
`toString()`, `equals()`, `hashCode()`, field getters and all args constructor are generated.
109109

110-
<2> `@Document(collection = "demo-service-movies")` marks a class as an entity to be persisted to Aerospike. It also allows to specify set name, expiration and touch on read values. In current example custom set name is specified via `collection`. Please note that a set name cannot contain the ':' or ';' characters. (See more https://www.aerospike.com/docs/guide/limitations.html[limitations])
110+
<2> `@Document(collection = "demo-simplecrud-set")` marks a class as an entity to be persisted to Aerospike.
111+
It also allows to specify set name, expiration and touch on read values. In current example custom set name is specified
112+
via `collection`. Please note that a set name cannot contain the ':' or ';' characters
113+
(see more https://www.aerospike.com/docs/guide/limitations.html[limitations]).
111114

112115
<3> `@Builder` provide Builder API for a class.
113116

@@ -222,8 +225,15 @@ public class MovieRepositoryTests extends SimpleCrudAerospikeDemoApplicationTest
222225
}
223226
224227
@Test
225-
void deleteById_doesNothingForNonExistingMovie() {
228+
void deleteById_skipsNonExistingMovie() {
226229
repository.deleteById(id);
230+
repository.deleteById(id);
231+
assertThat(repository.findById(id)).isNotPresent();
232+
233+
repository.save(movie);
234+
repository.deleteById("testId");
235+
assertThat(repository.findById(id)).isPresent();
236+
assertThat(repository.findById(id).get()).isEqualTo(movie);
227237
}
228238
}
229239
----

asciidoc/optimistic-locking.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public class WatchedMoviesService {
123123
private WatchedMoviesDocument updateExistingDocument(WatchedMoviesDocument existingDocument, String newWatchedMovie) {
124124
// NOTE: we do not create new document here, but only update existing while retaining the version
125125
return existingDocument.toBuilder()
126-
.watchedMovie(newWatchedMovie)
126+
.watchedMovie(newWatchedMovie) // add to the List
127127
.build();
128128
}
129129
@@ -185,7 +185,7 @@ public class WatchedMoviesConcurrentTest extends OptimisticLockingAerospikeDemoA
185185
186186
@Test
187187
void addWatchedMovie_addsMoviesConcurrently() throws Exception {
188-
String id = "age::" + UUID.randomUUID();
188+
String id = "watched::" + UUID.randomUUID();
189189
runTasksAndWaitForCompletion(() -> watchedMoviesService.addWatchedMovie(id, "Movie " + UUID.randomUUID()));
190190
191191
List<String> watchedMovies = watchedMoviesService.getWatchedMovies(id);

examples-reactive/pom.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,19 @@
1717
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1818
</properties>
1919

20+
<dependencies>
21+
<dependency>
22+
<groupId>com.aerospike</groupId>
23+
<artifactId>spring-data-aerospike</artifactId>
24+
</dependency>
25+
<dependency>
26+
<groupId>com.aerospike</groupId>
27+
<artifactId>aerospike-reactor-client</artifactId>
28+
</dependency>
29+
<dependency>
30+
<groupId>io.projectreactor</groupId>
31+
<artifactId>reactor-test</artifactId>
32+
<scope>test</scope>
33+
</dependency>
34+
</dependencies>
2035
</project>
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[[demo-simple-crud]]
2+
= Reactive Batch Read Operations Demo
3+
4+
This directory contains a sample project for demonstration of using basic batch read operations with Spring Data Aerospike reactively.
5+
6+
== Prerequisites
7+
8+
- JDK 17
9+
- Docker installed and running (optional)
10+
11+
== Tests
12+
13+
:base_path_reactive: ../../../../../../../..
14+
:tests_path_reactive: examples-reactive/src/test/java/com/demo/reactive
15+
16+
To see tests go to link:{base_path_reactive}/{tests_path_reactive}/batchread[reactive batch read tests].
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.demo.reactive.batchread;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class ReactiveBatchReadAerospikeDemoApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(ReactiveBatchReadAerospikeDemoApplication.class, args);
11+
}
12+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.demo.reactive.batchread.configuration;
2+
3+
import com.demo.reactive.batchread.repository.ReactiveMovieRepositoryForBatchRead;
4+
import org.springframework.context.annotation.Configuration;
5+
import org.springframework.data.aerospike.config.AbstractReactiveAerospikeDataConfiguration;
6+
import org.springframework.data.aerospike.config.AerospikeDataSettings;
7+
import org.springframework.data.aerospike.repository.config.EnableReactiveAerospikeRepositories;
8+
9+
@Configuration
10+
@EnableReactiveAerospikeRepositories(basePackageClasses = ReactiveMovieRepositoryForBatchRead.class)
11+
public class AerospikeConfiguration extends AbstractReactiveAerospikeDataConfiguration {
12+
13+
@Override
14+
protected void configureDataSettings(AerospikeDataSettings dataSettings) {
15+
dataSettings.setScansEnabled(true); // allow scan operations required for finding by entities (findAll)
16+
}
17+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.demo.reactive.batchread.entity;
2+
3+
import com.aerospike.client.query.IndexCollectionType;
4+
import com.aerospike.client.query.IndexType;
5+
import lombok.AllArgsConstructor;
6+
import lombok.Builder;
7+
import lombok.Value;
8+
import org.springframework.data.aerospike.annotation.Indexed;
9+
import org.springframework.data.aerospike.mapping.Document;
10+
import org.springframework.data.aerospike.mapping.Field;
11+
import org.springframework.data.annotation.Id;
12+
13+
@Value
14+
@Document(collection = "demo-batchRead-reactive-set")
15+
@Builder(toBuilder = true)
16+
// Spring Data object creation can use all-args constructor instead of reflection which is much faster
17+
@AllArgsConstructor
18+
public class MovieDocumentForBatchRead {
19+
20+
@Id
21+
String id;
22+
23+
@Field
24+
String name;
25+
26+
@Field("desc")
27+
String description;
28+
29+
@Indexed(type = IndexType.NUMERIC, collectionType = IndexCollectionType.DEFAULT)
30+
@Field
31+
int likes;
32+
33+
@Field
34+
double rating;
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package com.demo.reactive.batchread.repository;
2+
3+
import com.demo.reactive.batchread.entity.MovieDocumentForBatchRead;
4+
import org.springframework.data.aerospike.repository.ReactiveAerospikeRepository;
5+
6+
public interface ReactiveMovieRepositoryForBatchRead extends ReactiveAerospikeRepository<MovieDocumentForBatchRead, String> {
7+
8+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
[[demo-simple-crud]]
2+
= Reactive Batch Write Operations Demo
3+
4+
This directory contains a sample project for demonstration of using basic batch write operations with Spring Data Aerospike reactively.
5+
6+
== Prerequisites
7+
8+
- JDK 17
9+
- Docker installed and running (optional)
10+
11+
== Tests
12+
13+
:base_path_reactive: ../../../../../../../..
14+
:tests_path_reactive: examples-reactive/src/test/java/com/demo/reactive
15+
16+
To see tests go to link:{base_path_reactive}/{tests_path_reactive}/batchwrite[reactive batch write tests].
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.demo.reactive.batchwrite;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
@SpringBootApplication
7+
public class ReactiveBatchWriteAerospikeDemoApplication {
8+
9+
public static void main(String[] args) {
10+
SpringApplication.run(ReactiveBatchWriteAerospikeDemoApplication.class, args);
11+
}
12+
}

0 commit comments

Comments
 (0)