刚开始使用ScalaTest,我非常喜欢它.
仅仅阅读的文档我迄今一直无法弄清楚是否有任何实质性的区别can,should以及must条款的FlatSpec.
特别是,我想知道must失败是否与一个失败有什么不同should- 或者仅仅是"语法糖"使得测试更好地自我记录.
这在IntelliJ中是一个相当容易的问题(并在PyCharm中设置PEP8),但我一直在谷歌搜索,我找不到配置文件(我假设在XML或任何CLion使用),我可以使用它来配置它以遵守到Google风格指南.
这是一个"未来的特征"还是我错过了一些基本的东西?
当然,我可以手动配置它,但这是一个繁琐而耗时的操作; 如果有人已经这样做了,真棒,感谢分享!
更新
我把这个问题缩小到(可能!它并不完全清楚,甚至可以阅读我能找到的关于该主题的所有内容)安装stdlibc++-7-dev将为我提供合适的(即符合C++ 17的)STL标头和库.
这(显然)也与Ubuntu 17.04(artful?)捆绑在一起,但不适用于xenial我正在使用的(Ubuntu 16.04.3 LTS).
我已经尝试下载单个.deb软件包并安装它们,但它很快就变成了一个未解决的依赖项迷宫.
如果有人能指出如何libstdc++-7-dev在16.04 安装,我将非常感激.
原始问题
我刚刚通过包管理器在Ubuntu 16.04中安装了clang ++ 6.0(遵循这些说明)并且一切看起来都很好:/usr/bin/clang++-6.0工作得很好,如果我尝试使用仅适用于C++ 17(non-type template arguments with auto见此处)的东西,它会编译并且一旦我设置,就会运行CMAKE_CXX_COMPILER=/usr/bin/clang++-6.0- 而当我没有运行时它会失败.
所以...... clang 6.0像宣传的那样理解C++ 17(doh!)但是当我使用时:
#include <variant>
Run Code Online (Sandbox Code Playgroud)
找不到我期望的文件:
$ ll /usr/include/clang/6.0.0/
total 0
lrwxrwxrwx 1 root root 45 Aug 6 21:32 include -> ../../../lib/llvm-6.0/lib/clang/6.0.0/include
Run Code Online (Sandbox Code Playgroud)
或者我能想到的任何其他地方.
是否有人知道(a)是否应该在那里和(b)如果是这样,我在哪里可以找到它?
更新
我仔细检查过我有最新的(我认为)stdc++库:
$ sudo apt-get install libstdc++-5-dev
Reading package lists... Done …Run Code Online (Sandbox Code Playgroud) 我已经尝试了asyncio一段时间并阅读了PEP;一些教程;甚至奥莱利的书。
我想我已经掌握了它的窍门,但我仍然对这种行为感到困惑,loop.close()我无法完全弄清楚何时可以“安全”调用。
简而言之,我的用例是一堆阻塞的“老派”调用,我将它们包装在run_in_executor()和一个外部协程中;如果这些调用中的任何一个出现问题,我想停止进度,取消仍然未完成的调用,打印合理的日志,然后(希望是干净的)离开。
说吧,像这样:
import asyncio
import time
def blocking(num):
time.sleep(num)
if num == 2:
raise ValueError("don't like 2")
return num
async def my_coro(loop, num):
try:
result = await loop.run_in_executor(None, blocking, num)
print(f"Coro {num} done")
return result
except asyncio.CancelledError:
# Do some cleanup here.
print(f"man, I was canceled: {num}")
def main():
loop = asyncio.get_event_loop()
tasks = []
for num in range(5):
tasks.append(loop.create_task(my_coro(loop, num)))
try:
# No point in waiting; if …Run Code Online (Sandbox Code Playgroud) 几天来,我一直在反对这一点,查找它并在开源项目中寻找类似的代码:无法真正找到我正在做错的事情.
基本上,考虑到下面的代码(提炼到其本质):
#include <iostream>
using std::cout;
using std::endl;
using std::string;
template <typename T>
class Node {
T value_;
public:
Node(const T& value) : value_(value) {}
T const value() const { return value_; }
friend
std::ostream& operator <<(std::ostream& out, const Node<T>& node);
Node<T> operator +(const Node<T>& other) {
return Node(value() + other.value());
}
};
template <typename T>
std::ostream& operator <<(std::ostream& out, const Node<T>& node) {
return out << node.value();
}
Run Code Online (Sandbox Code Playgroud)
当在这样的代码中使用时:
int main(int argc, char* argv[]) {
Node<string> node("node X");
cout …Run Code Online (Sandbox Code Playgroud) 在我的请求处理程序中,如果传入的内容accountId无法转换为有效的,ObjectId我想捕获错误并发回有意义的消息;但是,这样做会导致返回类型不兼容,并且我无法弄清楚如何实现这个非常简单的用例。
我的代码:
@GetMapping("/{accountId}")
public Mono<ResponseEntity<Account>> get(@PathVariable String accountId) {
log.debug(GETTING_DATA_FOR_ACCOUNT, accountId);
try {
ObjectId id = new ObjectId(accountId);
return repository.findById(id)
.map(ResponseEntity::ok)
.switchIfEmpty(Mono.just(ResponseEntity.notFound().build()));
} catch (IllegalArgumentException ex) {
log.error(MALFORMED_OBJECT_ID, accountId);
// TODO(marco): find a way to return the custom error message. This seems to be currently
// impossible with the Reactive API, as using body(message) changes the return type to
// be incompatible (and Mono<ResponseEntity<?>> does not seem to cut it).
return Mono.just(ResponseEntity.badRequest().build());
}
}
Run Code Online (Sandbox Code Playgroud)
该body(T …
我在这里关注文档,这似乎根本不起作用; 但我甚至不确定我在这里做错了什么.
首先,只是在project/Build.scala文件中添加给定的片段会导致编译错误; 所以这不是一个开始.将其包装在扩展的对象内Build(如在SBT示例中)不会导致编译错误,但不会运行测试.
最后,我已将以下内容添加到我的 build.sbt
libraryDependencies ++= Seq(
"org.scalatestplus" %% "play" % "1.0.0" % "test",
...
Run Code Online (Sandbox Code Playgroud)
这稍微好一点,但在IntelliJ中,我ApplicationSpec有各种编译错误:
import org.scalatestplus.play._
import scala.collection.mutable.Stack
class ApplicationSpec extends PlaySpec {
"A Stack" must {
"pop values in last-in-first-out order" in {
val stack = new Stack[Int]
stack.push(1)
stack.push(2)
stack.pop() mustBe 2
stack.pop() mustBe 1
}
"throw NoSuchElementException if an empty stack is popped" in {
val emptyStack = new Stack[Int]
a [NoSuchElementException] must be thrownBy …Run Code Online (Sandbox Code Playgroud) 我正在使用以下类实现自定义端点:
@Component
@Endpoint(id = "bootstrap")
public class BootstrapUrlEndpoint {
private final URL bootstrapUrl;
@Autowired
public BootstrapUrlEndpoint(URL bootstrapUrl) {
this.bootstrapUrl = bootstrapUrl;
}
@ReadOperation
public Map<String, String> getBootstrapUrl() {
Map<String, String> result = new HashMap<>();
result.put("bootstrap_url", bootstrapUrl.toExternalForm());
return result;
}
@WriteOperation
public void setBootstrapUrl(@Selector String property, String value) throws MalformedURLException {
System.out.println(String.format(">>> Setting %s = %s", property, value));
}
}
Run Code Online (Sandbox Code Playgroud)
这一切都"按预期工作" 没有的@Selector注释; 忽略它,并发送POST至http://localhost:8080/actuator/bootstrap具有:
{
"value": "http://localhost:27017/tables/application"
}
Run Code Online (Sandbox Code Playgroud)
按预期调用方法.
但是,我无法使"选择器"工作; 我在启动日志中看到它被注册为有效端点:
Mapped "{[/actuator/bootstrap/{arg0}],methods=[POST],consumes=[application/vnd.spring-boot.actuator.v2+json || application/json]}" …Run Code Online (Sandbox Code Playgroud) 我的最终目标是在3节点CoreOS集群上运行Kubernetes(如果有人有更好的建议,我会全力以赴:在这个阶段,我正在考虑CoreOS完全浪费我的时间).
我已经开始跟随CoreOS指南运行游民群(我甚至有在行动书CoreOs和,要么是没有太大的帮助) -我已经获得了新的discovery token和修改过的user-data和config.rb文件与那里描述:
#cloud-config
---
coreos:
etcd2:
discovery: https://discovery.etcd.io/7b9a3e994a14c2bf530ed88676e3fc97
Run Code Online (Sandbox Code Playgroud)
和:
$ cat config.rb
# Size of the CoreOS cluster created by Vagrant
$num_instances = 3
$update_channel = "stable"
Run Code Online (Sandbox Code Playgroud)
其余的都在原始coreos-vagrant存储库中.
首次启动时,似乎etcd不是作为服务启动的; 启动它systemctl似乎让它继续下去,但它没有发现它的同行:
core@core-01 ~ $ etcdctl member list
8e9e05c52164694d: name=4adff068c464446a8423e9b9f7c28711 peerURLs=http://localhost:2380 clientURLs=http://localhost:2379 isLeader=true
Run Code Online (Sandbox Code Playgroud)
所有其他三个Vagrant虚拟机也是如此.
在我看来,要么修改user-data未被修改,要么以某种方式忽略发现标记.
我一直在谷歌搜索,但似乎没有出现.
我发现的主要困难是几乎所有围绕CoreOS/etcd的指令指向这些YAML文件,然后状态必须ct用来生成"真实"配置:但它们并没有真正显示如何在运行VM,或如何更改运行配置.
几个问题:
1)让三个虚拟机etcd启动并找到对方的"正确方法"是什么?阅读这里的指南真的没那么有用.
这三个虚拟机位于"仅限主机"网络上:
core@core-01 ~ $ ip address show …Run Code Online (Sandbox Code Playgroud) 更新:我已将代码推送到我的存储库中,以便人们可以查看那里以了解可能出了什么问题。
编辑:我几乎可以肯定是客户端代码没有将任何统计信息发布到服务器,但是下面的指南都没有解释应该如何启用它:是否有我缺少的配置设置?
我一直在关注OpenZipkin和Spring Sleuth的快速入门:我有一个来自docker-zipkin的正在运行的 Zipkin 服务器,使用docker-composeCassandra 作为后端:
$ d ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5ca0f0b29900 openzipkin/zipkin:1.12.1 "/bin/sh -c 'test -n " 14 minutes ago Up 8 minutes 0.0.0.0:9410-9411->9410-9411/tcp zipkin
7b243a0b61e3 openzipkin/zipkin-dependencies "crond -f" 14 minutes ago Up 8 minutes dependencies
e2e047fb3851 openzipkin/zipkin-cassandra:1.12.1 "/bin/sh -c /usr/loca" 14 minutes ago Up 8 minutes 7000-7001/tcp, 0.0.0.0:3306->3306/tcp, 7199/tcp, 0.0.0.0:9042->9042/tcp, 9160/tcp cassandra
Run Code Online (Sandbox Code Playgroud)
我已经创建并运行了Spring Sleuth 示例应用程序,它似乎已正确配置以跟踪调用: …
我找不到如何根据 Go 处理程序返回的错误在 Step 函数中定义错误条件匹配器的详细说明。
这handler是一个标准的 Go 函数,error如果从上游服务获取 503 则返回:
func HandleHotelBookingRequest(ctx context.Context, booking HotelBookingRequest) (
confirmation HotelBookingResponse, err error) {
...
if statusCode == http.StatusServiceUnavailable {
err = errors.New("TransientError")
} else {
Run Code Online (Sandbox Code Playgroud)
我可以控制函数返回的内容以及它如何格式化字符串;我找不到任何关于在这里使用什么的真实信息(或者在一个Catch子句中),所以这与上面的内容相匹配:
"Retry": [
{
"ErrorEquals": [
"TransientError"
],
"BackoffRate": 1,
"IntervalSeconds": 1,
"MaxAttempts": 3,
"Comment": "Retry for Transient Errors (503)"
}
]
Run Code Online (Sandbox Code Playgroud)
当我在控制台中测试 Lambda 时,当上游返回 503 时,我得到的结果(如预期):
{
"errorMessage": "TransientError",
"errorType": "errorString"
}
Run Code Online (Sandbox Code Playgroud)
我有一个明显的印象(但不太确定如何验证这一点),如果我更改为:
"ErrorEquals": [
"errorString"
],
Run Code Online (Sandbox Code Playgroud)
有效Retry(至少,查看 …
c++ ×3
scala ×2
scalatest ×2
spring ×2
aws-lambda ×1
c++11 ×1
c++17 ×1
clang ×1
clion ×1
coreos ×1
etcd ×1
friend ×1
go ×1
intellij-13 ×1
java ×1
kubernetes ×1
python ×1
spring-boot ×1
templates ×1
unit-testing ×1
variant ×1
zipkin ×1