是否可以使用AutoMapper为私有setter分配属性?
如果调试器附加到当前测试执行,有没有办法检查 JUnit 代码?
在 .NET/C# 中,我知道这可以通过Debugger.IsAttached.
用例是在连接调试器时更改或完全禁用测试超时,因为如果您只有大约 15 秒(定义的超时)来调试测试,这会很烦人。
我想以嵌套的方式定义我的消息,如下所示:
FooRequest
并在我的 grpc 服务定义中使用请求,如下所示:
service SessionManager {
rpc CreateSession (CreateSessionRequest) returns (CreateSessionResponse) {}
rpc DropSession (DropSessionRequest) returns (DropSessionResponse) {}
}
Run Code Online (Sandbox Code Playgroud)
为此,最好Request只定义一次原型并将其重新用于我想要创建的所有请求。
message Request {
string messageId = 1;
string origin = 2;
string correlationId = 3;
int32 sentAt = 4;
string type = 5;
int32 version = 6;
google.protobuf.Any metadata = 7;
google.protobuf.Any payload = 8;
}
Run Code Online (Sandbox Code Playgroud)
而不是这样做:
message CreateSessionRequest {
string messageId = 1;
string origin = 2;
string correlationId …Run Code Online (Sandbox Code Playgroud) 我想在我的一个类上拦截一些方法调用,但这些类没有默认的构造函数.
鉴于以下类,我如何设置Byte Buddy也创建一个公共无参数构造函数来创建生成的类?
public class GetLoggedInUsersSaga extends AbstractSpaceSingleEventSaga {
private final UserSessionRepository userSessionRepository;
@Inject
public GetLoggedInUsersSaga(final UserSessionRepository userSessionRepository) {
this.userSessionRepository = userSessionRepository;
}
@StartsSaga
public void handle(final GetLoggedInUsersRequest request) {
// this is the method in want to intercept
}
}
Run Code Online (Sandbox Code Playgroud)
编辑:具体的用例是简化单元测试设置.
目前我们总是要写这样的东西:
@Test
public void someTest() {
// Given
// When
GetLoggedInUsersRequest request = new GetLoggedInUsersRequest();
setMessageForContext(request); // <-- always do this before calling handle
sut.handle(request);
// Then
}
Run Code Online (Sandbox Code Playgroud)
我认为在@Before方法中创建代理会自动为您设置上下文会很好.
@Before
public void before() {
sut = new GetLoggedInUsersSaga(someDependency); …Run Code Online (Sandbox Code Playgroud) 我想要重用现有任务的用例之一是:将本地构建的 Docker 映像发布到自定义注册表。
如果我可以重复使用:Docker / publishLocal但可以使用其他设置值,那就太好了。
最初我认为这样的事情是可能的:
Docker / publishMyReg := {
dockerAlias := dockerAlias.value.withRegistryHost(Option("myregistry.foo.bar"))
(Docker / publishLocal).value
}
Run Code Online (Sandbox Code Playgroud)
我很惊讶地发现无法使用Task不同的设置值运行或具有Task特定的设置。
引入此类自定义任务的预期方式是什么?
我一直在看,Commmand但似乎在这里不起作用。对于上面的用例,我希望能够执行以下操作:sbt my-project/docker:publishMyReg据我所知,这对于Command.
我试图通过 HTTP 管理 API 向默认交换和其他一些交换发布一条消息,但我总是收到授权错误。
curl -i -u myuser:mypw -XPOST -d'{"properties":{},"routing_key":"my_key","payload":"my body","payload_encoding":"string"}' https://myinstance.rmq.cloudamqp.com/api/exchanges/vhost/myvhost/publish
Run Code Online (Sandbox Code Playgroud)
HTTP/1.1 401 Unauthorized
Server: nginx/1.14.2
Date: Mon, 01 Apr 2019 05:27:10 GMT
Content-Type: application/json
Content-Length: 53
Connection: keep-alive
content-security-policy: default-src 'self'
vary: accept, accept-encoding, origin
{"error":"not_authorised","reason":"Access refused."}%
Run Code Online (Sandbox Code Playgroud)
我在自托管的 RabbitMQ(通过 k8s 上的 helm 安装)和我们的 CloudAMQP 实例上都进行了尝试。
但是,如果我使用相同的用户登录管理 Web UI,那么我可以将消息发布到交换并从队列中消费。我希望管理 Web UI 仅使用 HTTP API 来执行此操作,因此当我通过 UI 执行此操作时,我很困惑为什么它会起作用。
另一方面,读取所有虚拟主机也适用于 HTTP API。
curl -i -u myuser:mypw https://myinstance.rmq.cloudamqp.com/api/vhosts
Run Code Online (Sandbox Code Playgroud)
HTTP/1.1 200 OK
Run Code Online (Sandbox Code Playgroud)
有人可以向我解释那里发生了什么吗?最让我困惑的是它使用相同的用户:pw 在 UI 上工作。
正如标题所说,当我还配置了命名实例时,structuremap不会返回默认实例.
这是我的类型注册:
/// <summary>
/// Initializes a new instance of the <see cref="CommandProcessingTypeRegistry"/> class.
/// </summary>
public CommandProcessingTypeRegistry()
{
For<ICommandProcessor>().Singleton().Use<CommandCoordinator>();
For<ICommandProcessor>().Singleton().Use<SystemCommandSwitch>().Named(typeof(SystemCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<TelephonyCommandSwitch>().Named(typeof(TelephonyCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<AudioCommandSwitch>().Named(typeof(AudioCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<TetraCommandSwitch>().Named(typeof(TetraCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<RadioCommandSwitch>().Named(typeof(RadioCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<SnapshotCommandSwitch>().Named(typeof(SnapshotCommandSwitch).FullName);
For<ICommandProcessor>().Singleton().Use<TakeNextCommandSwitch>().Named(typeof(TakeNextCommandSwitch).FullName);
}
Run Code Online (Sandbox Code Playgroud)
这就是我请求实例的方式:
_commandProcessor = _container.GetInstance<ICommandProcessor>(); // _container is the structuremap IContainer instance
Run Code Online (Sandbox Code Playgroud)
我希望上面的行返回CommandCoordinator实例,但返回TakeNextCommandSwitch实例.我在这做错了什么?
java ×2
automapper ×1
byte-buddy ×1
bytecode ×1
debugging ×1
docker ×1
grpc ×1
junit ×1
private ×1
rabbitmq ×1
sbt ×1
scala ×1
setter ×1
structuremap ×1