Merge pull request #8125 from eugenp/revert-8119-BAEL-3275-2

Revert "BAEL-3275: Using blocking queue for pub-sub"
This commit is contained in:
Eric Martin
2019-10-31 20:43:47 -05:00
committed by GitHub
parent db85c8f275
commit 3225470df5
20543 changed files with 1642750 additions and 0 deletions
@@ -0,0 +1,72 @@
package com.baeldung.spring.data.reactive.redis.template;
import com.baeldung.spring.data.reactive.redis.SpringRedisReactiveApplication;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.connection.ReactiveKeyCommands;
import org.springframework.data.redis.connection.ReactiveStringCommands;
import org.springframework.data.redis.connection.ReactiveStringCommands.SetCommand;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import redis.embedded.RedisServerBuilder;
import java.io.IOException;
import java.nio.ByteBuffer;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisReactiveApplication.class)
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
public class RedisKeyCommandsIntegrationTest {
private static redis.embedded.RedisServer redisServer;
@Autowired
private ReactiveKeyCommands keyCommands;
@Autowired
private ReactiveStringCommands stringCommands;
@BeforeClass
public static void startRedisServer() throws IOException {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
redisServer.stop();
}
@Test
public void givenFluxOfKeys_whenPerformOperations_thenPerformOperations() {
Flux<String> keys = Flux.just("key1", "key2", "key3", "key4");
Flux<SetCommand> generator = keys.map(String::getBytes)
.map(ByteBuffer::wrap)
.map(key -> SetCommand.set(key)
.value(key));
StepVerifier.create(stringCommands.set(generator))
.expectNextCount(4L)
.verifyComplete();
Mono<Long> keyCount = keyCommands.keys(ByteBuffer.wrap("key*".getBytes()))
.flatMapMany(Flux::fromIterable)
.count();
StepVerifier.create(keyCount)
.expectNext(4L)
.verifyComplete();
}
}
@@ -0,0 +1,70 @@
package com.baeldung.spring.data.reactive.redis.template;
import com.baeldung.spring.data.reactive.redis.SpringRedisReactiveApplication;
import java.io.IOException;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.ReactiveListOperations;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import redis.embedded.RedisServerBuilder;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisReactiveApplication.class)
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
public class RedisTemplateListOpsIntegrationTest {
private static final String LIST_NAME = "demo_list";
private static redis.embedded.RedisServer redisServer;
@Autowired
private ReactiveRedisTemplate<String, String> redisTemplate;
private ReactiveListOperations<String, String> reactiveListOps;
@BeforeClass
public static void startRedisServer() throws IOException {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
redisServer.stop();
}
@Before
public void setup() {
reactiveListOps = redisTemplate.opsForList();
}
@Test
public void givenListAndValues_whenLeftPushAndLeftPop_thenLeftPushAndLeftPop() {
Mono<Long> lPush = reactiveListOps.leftPushAll(LIST_NAME, "first", "second")
.log("Pushed");
StepVerifier.create(lPush)
.expectNext(2L)
.verifyComplete();
Mono<String> lPop = reactiveListOps.leftPop(LIST_NAME)
.log("Popped");
StepVerifier.create(lPop)
.expectNext("second")
.verifyComplete();
}
}
@@ -0,0 +1,93 @@
package com.baeldung.spring.data.reactive.redis.template;
import java.io.IOException;
import java.time.Duration;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.ReactiveRedisTemplate;
import org.springframework.data.redis.core.ReactiveValueOperations;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.junit4.SpringRunner;
import com.baeldung.spring.data.reactive.redis.SpringRedisReactiveApplication;
import com.baeldung.spring.data.reactive.redis.model.Employee;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import redis.embedded.RedisServerBuilder;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, classes = SpringRedisReactiveApplication.class)
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
public class RedisTemplateValueOpsIntegrationTest {
private static redis.embedded.RedisServer redisServer;
@Autowired
private ReactiveRedisTemplate<String, Employee> redisTemplate;
private ReactiveValueOperations<String, Employee> reactiveValueOps;
@BeforeClass
public static void startRedisServer() throws IOException {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
redisServer.stop();
}
@Before
public void setup() {
reactiveValueOps = redisTemplate.opsForValue();
}
@Test
public void givenEmployee_whenSet_thenSet() {
Mono<Boolean> result = reactiveValueOps.set("123", new Employee("123", "Bill", "Accounts"));
StepVerifier.create(result)
.expectNext(true)
.verifyComplete();
}
@Test
public void givenEmployeeId_whenGet_thenReturnsEmployee() {
Mono<Employee> fetchedEmployee = reactiveValueOps.get("123");
StepVerifier.create(fetchedEmployee)
.expectNext(new Employee("123", "Bill", "Accounts"))
.verifyComplete();
}
@Test
public void givenEmployee_whenSetWithExpiry_thenSetsWithExpiryTime() throws InterruptedException {
Mono<Boolean> result = reactiveValueOps.set("129", new Employee("129", "John", "Programming"), Duration.ofSeconds(1));
Mono<Employee> fetchedEmployee = reactiveValueOps.get("129");
StepVerifier.create(result)
.expectNext(true)
.verifyComplete();
Thread.sleep(2000L);
StepVerifier.create(fetchedEmployee)
.expectNextCount(0L)
.verifyComplete();
}
}
@@ -0,0 +1,52 @@
package com.baeldung.spring.data.redis;
import static org.junit.Assert.assertTrue;
import java.io.IOException;
import java.util.UUID;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.spring.data.redis.config.RedisConfig;
import com.baeldung.spring.data.redis.queue.RedisMessagePublisher;
import com.baeldung.spring.data.redis.queue.RedisMessageSubscriber;
import redis.embedded.RedisServerBuilder;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RedisConfig.class)
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
public class RedisMessageListenerIntegrationTest {
private static redis.embedded.RedisServer redisServer;
@Autowired
private RedisMessagePublisher redisMessagePublisher;
@BeforeClass
public static void startRedisServer() throws IOException {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
redisServer.stop();
}
@Test
public void testOnMessage() throws Exception {
String message = "Message " + UUID.randomUUID();
redisMessagePublisher.publish(message);
Thread.sleep(1000);
assertTrue(RedisMessageSubscriber.messageList.get(0).contains(message));
}
}
@@ -0,0 +1,83 @@
package com.baeldung.spring.data.redis.repo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.annotation.DirtiesContext.ClassMode;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.spring.data.redis.config.RedisConfig;
import com.baeldung.spring.data.redis.model.Student;
import redis.embedded.RedisServerBuilder;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RedisConfig.class)
@DirtiesContext(classMode = ClassMode.BEFORE_CLASS)
public class StudentRepositoryIntegrationTest {
@Autowired
private StudentRepository studentRepository;
private static redis.embedded.RedisServer redisServer;
@BeforeClass
public static void startRedisServer() throws IOException {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 128M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() throws IOException {
redisServer.stop();
}
@Test
public void whenSavingStudent_thenAvailableOnRetrieval() throws Exception {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student);
final Student retrievedStudent = studentRepository.findById(student.getId()).get();
assertEquals(student.getId(), retrievedStudent.getId());
}
@Test
public void whenUpdatingStudent_thenAvailableOnRetrieval() throws Exception {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student);
student.setName("Richard Watson");
studentRepository.save(student);
final Student retrievedStudent = studentRepository.findById(student.getId()).get();
assertEquals(student.getName(), retrievedStudent.getName());
}
@Test
public void whenSavingStudents_thenAllShouldAvailableOnRetrieval() throws Exception {
final Student engStudent = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
final Student medStudent = new Student("Med2015001", "Gareth Houston", Student.Gender.MALE, 2);
studentRepository.save(engStudent);
studentRepository.save(medStudent);
List<Student> students = new ArrayList<>();
studentRepository.findAll().forEach(students::add);
assertEquals(students.size(), 2);
}
@Test
public void whenDeletingStudent_thenNotAvailableOnRetrieval() throws Exception {
final Student student = new Student("Eng2015001", "John Doe", Student.Gender.MALE, 1);
studentRepository.save(student);
studentRepository.deleteById(student.getId());
final Student retrievedStudent = studentRepository.findById(student.getId()).orElse(null);
assertNull(retrievedStudent);
}
}
@@ -0,0 +1,36 @@
package org.baeldung;
import com.baeldung.spring.data.redis.config.RedisConfig;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import redis.embedded.RedisServerBuilder;
import static org.springframework.test.annotation.DirtiesContext.ClassMode.BEFORE_CLASS;
@RunWith(SpringJUnit4ClassRunner.class)
@DirtiesContext(classMode = BEFORE_CLASS)
@ContextConfiguration(classes = RedisConfig.class)
public class SpringContextIntegrationTest {
private static redis.embedded.RedisServer redisServer;
@BeforeClass
public static void startRedisServer() {
redisServer = new RedisServerBuilder().port(6379).setting("maxmemory 256M").build();
redisServer.start();
}
@AfterClass
public static void stopRedisServer() {
redisServer.stop();
}
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}
@@ -0,0 +1,17 @@
package org.baeldung;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import com.baeldung.spring.data.redis.config.RedisConfig;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = RedisConfig.class)
public class SpringContextTest {
@Test
public void whenSpringContextIsBootstrapped_thenNoExceptions() {
}
}