- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我是 Reactive 编程的新手,我写了一些我想测试的代码。这些更像是一个集成测试,因为我正在实时复制文件,然后检查它们是否相同。我有一个 MockWebServer
mock 我的回答是4xx
这在代码中处理得很好。不幸的是,我也收到了 io.netty.handler.timeout.ReadTimeoutException
这掩盖了我的习惯WebClientResponseException
所以在测试中我得到了错误的异常。基本上我有两个问题,为什么我会得到这个 io.netty.handler.timeout.ReadTimeoutException
异常(exception)?它只出现在 doOnError()
之后出于某种原因的方法,我不确定它为什么会发生。
现在代码是同步的,我很清楚这一点。
第二个问题是,在给定的重试次数后,我如何处理测试中的自定义异常?现在它是 3,只有到那时我才希望抛出我的另一个异常。
代码如下:
AsynchronousFileChannel fileChannel = AsynchronousFileChannel.open(targetPath, StandardOpenOption.WRITE);
Flux<DataBuffer> fileDataStream = Mono.just(filePath)
.map(file -> targetPath.toFile().exists() ? targetPath.toFile().length() : 0)
.map(bytes -> webClient
.get()
.uri(uri)
.accept(MediaType.APPLICATION_OCTET_STREAM)
.header("Range", String.format("bytes=%d-", bytes))
.retrieve()
.onStatus(HttpStatus::is4xxClientError, clientResponse -> Mono.error(new CustomException("4xx error")))
.onStatus(HttpStatus::is5xxServerError, clientResponse -> Mono.error(new CustomException("5xx error")))
.bodyToFlux(DataBuffer.class)
.doOnError(throwable -> log.info("fileDataStream onError", throwable))
)
.flatMapMany(Function.identity());
return DataBufferUtils
.write(fileDataStream, fileChannel)
.map(DataBufferUtils::release)
.doOnError(throwable -> {
try {
fileChannel.force(true);
} catch (IOException e) {
throw new WritingException("failed force update to file channel", e);
}
})
.retry(3)
.doOnComplete(() -> {
try {
fileChannel.force(true);
} catch (IOException e) {
log.warn("failed force update to file channel", e);
throw new WritingException("failed force update to file channel", e);
}
})
.doOnError(throwable -> targetPath.toFile().delete())
.then(Mono.just(target));
响应是Mono<Path>
因为我只对 Path
感兴趣新创建和复制的文件。
欢迎对代码提出任何意见。
复制机制是基于这个线程Downlolad and save file from ClientRequest using ExchangeFunction in Project Reactor
最佳答案
所以基本上问题出在测试中。我有一个 MockResponse
只排队到 MockWebServer
一次,所以在 WebClient
中重试时模拟服务器没有任何响应集(基本上它表现得像它根本不可用,因为没有模拟响应)。
为了能够在服务器完全关闭的情况下处理异常,在我看来,值得将类似这样的行添加到您的通量链中:
.doOnError(ChannelException.class, e -> {
throw new YourCustomExceptionForHandlingServerIsDownSituation("Server is unreachable", e);
})
这将帮助您处理来自 Netty 的 ReadTimeoutException
(在服务器无法访问的情况下),因为它扩展了 ChannelException
类。始终处理您的异常。
关于java - 在 WebClient 中处理异常抛出 io.netty.handler.timeout.ReadTimeoutException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58417422/
我正在使用 heroku 来托管支持 iOS 应用程序的 ruby on rails 应用程序。我有一个可能会运行很长时间的请求,我需要能够在我的请求被终止之前捕获超时。我正在使用 Timeout
我在 https://stackoverflow.com/questions/517219?tab=oldest#tab-top 找到了我认为应该完美运行的东西但是,它对我不起作用。 我在 Windo
我有这段代码: begin complete_results = Timeout.timeout(4) do results = platform.search(artist,
我正在开发一个音乐训练游戏,我使用 Unity 3D 来创建它。 它会发出随机音符。 问题是,我的 android 设备只有五个“屏幕熄灭前的时间”选项,其中最长的是 10 分钟。 所以 10 分钟后
我运行以下代码来捕获任何可能挂起的 SQL 语句。在尝试对此进行测试时,我编写了一个非常优化的 sql 语句,它需要一分钟的时间才能运行。我在 activerecord execute sql 语句周
由于 Faraday 没有文档,我无法在任何地方找到它。法拉第什么是“timeout”,什么是“open timeout”? 最佳答案 如果您在 https://github.com/lostisla
我想对 Angular.js $timeout 进行单元测试,以检查是否已使用正确的持续时间/延迟值调用它。 断言看起来像这样: expect($timeout).toHaveBeenCalledWi
我正在循环一个列表并对列表中的每个成员执行一些操作。如果某个成员花费了太多时间(在本例中为 1 秒),我打算跳过它。但是,try 语句内的 block 始终处于处理状态,并且永远不会超时。我不明白为什
我有一个程序可以打印出通过或失败。我想检测卡在那里的程序并回显“超时” 我写了这样一个脚本: #!/bin/bash echo -n 'test' && timeout 5 ./mytest | gr
我有一个 Sinatra 应用程序。我正在使用 Rack::Test 对其进行测试。我想确保将查询字符串参数传递给 Timeout::timeout()。 我认为 expect_any_instanc
相同的脚本不同的错误。这可能更多地与我的网络有关,而不是我的代码。脚本如下: #!/usr/bin/env ruby -rubygems require File.join(File.dirname(
我需要测试一个从 url 加载图像的 AngularJs 服务。这是我的服务: /*global angular, Image*/ (function () { 'use strict'; f
随着数据库大小的增加,我有一个查询需要更长的时间来执行。查询已优化并且是必要的,但我的 C# 控制台应用程序最近给我这个错误: Unhandled Exception: MySql.Data.MySq
我正在研究 Linux shell 中的 timeout 命令。 当我尝试 timeout 1 bash 时,bash 将运行并在 1 秒后终止。 当我尝试 timeout 2 timeout 1 y
随着数据库大小的增加,我有一个查询需要更长的时间来执行。查询已优化并且是必要的,但我的 C# 控制台应用程序最近给我这个错误: Unhandled Exception: MySql.Data.MySq
我希望使用 Spring boot 和 Tomcat 扩展 Spring MVC 应用程序中的用户 session 。查看文档似乎有 2 个相关 properties : server.servlet
我正在尝试升级 Puppet 以使用 Ruby 1.9,但遇到了常量问题。 const_defined?("Timeout") 返回真,即使 :Timeout 不在常量列表中。这不会发生在 Ruby
首先,这是一个几乎重复的: How to differentiate when wait(long timeout) exit for notify or timeout? 但这是一个新的后续问题。
对于下面的代码,notifyAll() 会一直持有锁直到完成,即使超时了,这个 block 也不持有锁,必须等待notifyAll() block 完成。那么wait(timeout)中的timeou
Thread.Sleep(timeout) 和resetEvent.Wait(timeout) 都会导致执行暂停至少timeout 毫秒,那么它们之间有区别吗?我知道 Thread.Sleep 导致线
我是一名优秀的程序员,十分优秀!