Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Проект на Java и библиотеке Reactor - а как же ...

Проект на Java и библиотеке Reactor - а как же тесты?

Merkushev Kirill

December 06, 2018
Tweet

More Decks by Merkushev Kirill

Other Decks in Programming

Transcript

  1. 16 service.getUser(id) .filter(permissionsService!::allowed) .flatMap(user !-> service .fetchDocumentRequests(user.getId()) .zipWith(logService!::reportAction) ) .doOnError(logService!::reportFail)

    .onErrorReturn( RateLimitException.class, status(TOO_MANY_REQUESTS).build() ) .onErrorReturn(status(INTERNAL_SERVER_ERROR).build()); Reactor way
  2. 30 service.getUser(id) .filter(permissionsService!::allowed) .flatMap(user !-> service .fetchDocumentRequests(user.getId()) .zipWith(logService!::reportAction) ) .doOnError(logService!::reportFail)

    .onErrorReturn( RateLimitException.class, status(TOO_MANY_REQUESTS).build() ) .onErrorReturn(status(INTERNAL_SERVER_ERROR).build()); We have
  3. 31 service.getUser(id) .filter(permissionsService!::allowed) .flatMap(user !-> service .fetchDocumentRequests(user.getId()) .zipWith(logService!::reportAction) ) .doOnError(logService!::reportFail)

    .onErrorReturn( RateLimitException.class, status(TOO_MANY_REQUESTS).build() ) .onErrorReturn(status(INTERNAL_SERVER_ERROR).build()); We have flow
  4. 32 service.getUser(id) .filter(permissionsService!::allowed) .flatMap(user !-> service .fetchDocumentRequests(user.getId()) .zipWith(logService!::reportAction) ) .doOnError(logService!::reportFail)

    .onErrorReturn( RateLimitException.class, status(TOO_MANY_REQUESTS).build() ) .onErrorReturn(status(INTERNAL_SERVER_ERROR).build()); We have merge
  5. 33 service.getUser(id) .filter(permissionsService!::allowed) .flatMap(user !-> service .fetchDocumentRequests(user.getId()) .zipWith(logService!::reportAction) ) .doOnError(logService!::reportFail)

    .onErrorReturn( RateLimitException.class, status(TOO_MANY_REQUESTS).build() ) .onErrorReturn(status(INTERNAL_SERVER_ERROR).build()); We have Error handling
  6. 39 service.getUser(id) .filter(permissionsService!::allowed) .flatMap(user !-> service .fetchDocumentRequests(user.getId()) .zipWith(logService!::reportAction) ) .doOnError(logService!::reportFail)

    .onErrorReturn( RateLimitException.class, status(TOO_MANY_REQUESTS).build() ) .onErrorReturn(status(INTERNAL_SERVER_ERROR).build());
  7. 40 Unhandled exception at reactor.util.Loggers$Slf4JLogger.error(Loggers.java:295) at reactor.core.publisher.SignalLogger.lambda$onErrorCall$5(SignalLogger.java:296) at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onError(FluxPeekFuseable.java:219) at

    reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onError(FluxMapFuseable.java:134) at reactor.core.publisher.MonoCollectList$MonoBufferAllSubscriber.onError(MonoCollectList.java:107) at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.drain(FluxMergeSequential.java:341) at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.onError(FluxMergeSequential.java:242) at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.drainAsync(FluxFlattenIterable.java:305) onErrorReturn
  8. 41 Checkpoints .checkpoint("allow-service") Assembly site of producer [reactor.core.publisher.MonoIgnoreThen] is identified

    by light checkpoint [allow- service]."description" : "allow-service" at reactor.util.Loggers$Slf4JLogger.error(Loggers.java:295) at reactor.core.publisher.SignalLogger.lambda$onErrorCall$5(SignalLogger.java:296) at reactor.core.publisher.FluxPeekFuseable$PeekFuseableSubscriber.onError(FluxPeekFuseable.java:219) at reactor.core.publisher.FluxMapFuseable$MapFuseableSubscriber.onError(FluxMapFuseable.java:134) at reactor.core.publisher.MonoCollectList$MonoBufferAllSubscriber.onError(MonoCollectList.java:107) at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.drain(FluxMergeSequential.java:341) at reactor.core.publisher.FluxMergeSequential$MergeSequentialMain.onError(FluxMergeSequential.java:242) at reactor.core.publisher.FluxFlattenIterable$FlattenIterableSubscriber.drainAsync(FluxFlattenIterable.java:305)
  9. 42 DEBUG - logs .log("flow") 2018-11-21 17:59:23.285 INFO --- [

    Test worker] flow : | request(unbounded) 2018-11-21 17:59:23.275 INFO --- [ Test worker] flow : | onSubscribe([Fuseable] FluxOnAssembly.OnAssemblySubscriber) 2018-11-21 17:59:23.291 ERROR --- [ Test worker] flow : | onError(java.lang.IllegalStateException)
  10. 44 hooks + tests Hooks.onOperatorDebug(); warn: performance impact Error has

    been observed by the following operator(s): |_ Mono.create(PublicEmergencyDataRepository.java:101) |_ MonoCreate$DefaultMonoSink.error(DefaultAsyncHandler.java:14) |_ Mono.onErrorMap(PublicEmergencyDataRepository.java:102) |_ Mono.then(PublicEmergencyDataRepository.java:103) |_ MonoCreate$DefaultMonoSink.error(DefaultAsyncHandler.java:14) |_ Mono.onErrorResume(PublicEmergencyDataService.java:70) |_ Mono.then(PublicEmergencyDataService.java:71) |_ Mono.then(UserEventLogConsumer.java:63) |_ Mono.defer(UserEventLogConsumer.java:29)
  11. 45 unittest void expectTwoUsers(Flux<User> flux) { StepVerifier.create(flux) .expectNextMatches( user !->

    user.getUsername().equals("swhite") ) .expectNextMatches( user !-> user.getUsername().equals("jpinkman") ) .expectComplete(); }
  12. 56 fully non blocking already reactive or Mono.fromCallable Mono.fromRunnable .subscribeOn(

    Schedulers.elastic ) Mono!::block Flux… or deal with leaks, race conditions, deadlocks