在单元测试中从字符串构造TextMessage的最佳方法是什么?
我只看到Session#createTextMessage(String),但这需要一个需要进行一些设置的会话。
替代方法是仅模拟TextMessage,但我认为避免模拟数据对象是一种好习惯。
我们的通信超出了默认的grpc-java消息大小限制:
Caused by: io.grpc.StatusRuntimeException: INTERNAL:
Frame size 4555602 exceeds maximum: 4194304.
If this is normal, increase the maxMessageSize
in the channel/server builder
Run Code Online (Sandbox Code Playgroud)
该限制可以增加,请参见https://github.com/grpc/grpc-java/issues/917:
在通道/服务器构建器上设置 maxMessageSize()。
然而,当试图在我们的代码库中实现修复时,我不清楚如何做到这一点,因为并非所有Channel实现都有一个maxMessageSize方法。
我们的代码使用ManagedChannel. 设置代码如下所示:
ManagedChannel channel =
ManagedChannelBuilder.forAddress(rpcHost, grpcPort)
.usePlaintext(true).build();
CatalogGrpcServiceGrpc.CatalogGrpcServiceBlockingStub stub =
CatalogGrpcServiceGrpc.newBlockingStub(channel);
CatalogRetrieverGrpcServiceAdapter grpcServiceAdapter =
new CatalogRetrieverGrpcServiceAdapter(
stub, metricRegistry);
Run Code Online (Sandbox Code Playgroud)
也许我遗漏了一些东西,但我看不到如何增加ManagedChannel. 只有OkHttpChannelBuilder拥有它 ( OkHttpChannelBuilder#maxMessageSize)。
问题:
ManagedChannel?ManagedChannel,我该如何重写代码以使用另一个支持增加默认限制的通道实现?Clang 具有-fsanitize-blacklist编译开关来抑制来自 ThreadSanitizer 的警告。不幸的是,我无法让它工作。
这是我想抑制的一个例子:
WARNING: ThreadSanitizer: data race (pid=21502)
Read of size 8 at 0x7f0dcf5b31a8 by thread T6:
#0 tbb::interface6::internal::auto_partition_type_base<tbb::interface6::internal::auto_partition_type>::check_being_stolen(tbb::task&) /usr/include/tbb/partitioner.h:305 (exe+0x000000388b38)
#1 <null> <null>:0 (libtbb.so.2+0x0000000224d9)
Previous write of size 8 at 0x7f0dcf5b31a8 by thread T1:
#0 auto_partition_type_base /usr/include/tbb/partitioner.h:299 (exe+0x000000388d9a)
#1 <null> <null>:0 (libtbb.so.2+0x0000000224d9)
#2 GhostSearch::Ghost3Search::SearchTask::execute_impl() /home/phil/ghost/search/ghost3/ghost3_search_alg.cpp:1456 (exe+0x000000387a8a)
#3 <null> <null>:0 (libtbb.so.2+0x0000000224d9)
#4 GhostSearch::Ghost3Search::Ghost3SearchAlg::NullWindowSearch(int, MOVE, int, std::vector<MOVE, std::allocator<MOVE> >&) /home/phil/ghost/search/ghost3/ghost3_search_alg.cpp:1640 (exe+0x000000388310)
#5 GhostSearch::PureMTDSearchAlg::FullWindowSearch(GhostSearch::SearchWindow, GhostSearch::SearchWindow, MOVE, int, std::vector<MOVE, std::allocator<MOVE> >&) /home/phil/ghost/search/pure_mtd_search_alg.cpp:41 (exe+0x000000370e3f)
#6 GhostSearch::PureSearchAlgWrapper::RequestHandlerThread::EnterHandlerMainLoop() /home/phil/ghost/search/pure_search_alg_wrapper.cpp:124 (exe+0x000000372d1b)
#7 operator() …Run Code Online (Sandbox Code Playgroud) 当我从SpookyJS运行hello示例时,它失败并出现以下错误:
$ node examples/hello.js
events.js:72
throw er; // Unhandled 'error' event
^
Error: spawn ENOENT
at errnoException (child_process.js:998:11)
at Process.ChildProcess._handle.onexit (child_process.js:789:34)
Run Code Online (Sandbox Code Playgroud)
实际上,我尝试的所有示例都会导致此错误.我陷入困境,因为即使在查看源代码时我也无法解释错误消息.你有什么想法?
(我正在使用Ubuntu和phantomjs 1.9.7)
现在,我正在通过简单的测试来测试 Web Crypto API。所以,我有用户的公钥(作为字符串),我想让他传递他的私钥(也作为字符串),所以我的应用程序可以做一些加密/解密。因此,我尝试通过执行以下操作将他的密钥导入到 Web Crypto API:
var textEncoder = new TextEncoder();
var alg = {
name: "RSA-OAEP",
hash: {name: "SHA-256"}
}
window.crypto.subtle.importKey('raw', textEncoder.encode(myPublicKey), alg, false, ['encrypt'])
Run Code Online (Sandbox Code Playgroud)
密钥由
openssl genrsa -out mykey.pem 4096
openssl rsa -in mykey.pem -pubout > mykey.pub
Run Code Online (Sandbox Code Playgroud)
WCAPI 抛出
Unsupported import key format for algorithm
Run Code Online (Sandbox Code Playgroud)
我在 alg 中尝试了其他哈希,但仍然没有成功。
一个例子的帮助会很好。
我刚刚了解了 Crystal 中的存在&-=运算符。它有什么作用?
这是Mutex#try_lock的示例:
private def try_lock
i = 1000
while @state.swap(1) != 0
while @state.get != 0
Intrinsics.pause
i &-= 1
return false if i == 0
end
end
true
end
Run Code Online (Sandbox Code Playgroud)
在尝试时,我看不出与熟悉的-=操作员有任何区别。例如,这两个片段产生相同的输出:
i = 1000
while i != 0
puts i
i -= 1
end
Run Code Online (Sandbox Code Playgroud)
i = 1000
while i != 0
puts i
i &-= 1
end
Run Code Online (Sandbox Code Playgroud) java ×2
ascii ×1
c ×1
c++ ×1
clang ×1
crystal-lang ×1
grpc ×1
grpc-java ×1
javascript ×1
jms ×1
node.js ×1
openssl ×1
rsa ×1
spookyjs ×1
unit-testing ×1