在反应库中保存方法

时间:2018-04-13 08:21:54

标签: spring spring-data reactive-programming project-reactor

您好我想问您下面有什么看法,特别请注意保存方法。 我的问题是阻止还是不阻止?

@Repository class ImageSizeRepositoryInMemoryImpl实现ImageSizeRepository {

private volatile Map<String, ImageSize> imageSizes = HashMap.empty();

@Override
public Mono<Void> save(ImageSize imageSize) {
    this.imageSizes = imageSizes.put(imageSize.getName(), imageSize);
    return Mono.empty();
}

我在ma应用程序服务中调用此方法:

@Service
@RequiredArgsConstructor
public class ImageResizeServiceFacade {

    private final ImageSizeRepository imageSizeRepository;

    public Mono<Void> addPredefinedSize(Mono<ImageSizeDto> predefinedSizeDto) {
        return predefinedSizeDto
                //.publishOn(Schedulers.parallel())
                .doOnNext(imageSizeDto -> {
                    imageSizeRepository.save(Mapper.ImageSizeMapper.mapFromDto(imageSizeDto)); })
                .then();
    }


Bu i dont know how to test in spock:

class ImageResizerSpec extends Specification implements SampleSize {

    ImageResizeServiceFacade imageResizeServiceFacade = new ResizerConfiguration().imageResizeServiceFacade()

    def "should add new size"() {
        given: "we have new size to add"
        Mono<ImageSizeDto> newSize = Mono.just(imageSizeDto)

        when: "we add new size"
        Mono<Void> empty = imageResizeServiceFacade.addPredefinedSize(newSize)
        empty.block()

        then: "system has this size"
        imageResizeServiceFacade.listPredefinedSizes().blockFirst().name == imageSizeDto.name
    }

正如我们在上面的测试中看到的那样,当块我必须等待操作完成时,所以我使用块方法...... }

0 个答案:

没有答案