小编Hai*_*man的帖子

当看起来没问题时,Mockito会给出UnfinishedVerificationException

UnfinishedVerificationException当我认为我已经完成了所有事情时,Mockito似乎正在投掷.这是我的部分测试用例:

HttpServletRequest req = mock(HttpServletRequest.class);
when(req.getHeader("Authorization")).thenReturn("foo");

HttpServletResponse res = mock(HttpServletResponse.class);

classUnderTest.doMethod(req, res); // Use the mock

verify(res, never());
verify(req).setAttribute(anyString(), anyObject());
Run Code Online (Sandbox Code Playgroud)

这是部分类和方法:

class ClassUnderTest extends AnotherClass {
    @Override
    public String doMethod(ServletRequest req, ServletRequest res) {
        // etc.
        return "someString";
    }
}
Run Code Online (Sandbox Code Playgroud)

忽略你不应该模仿你不拥有的接口的事实,为什么Mockito给我以下信息?

org.mockito.exceptions.misusing.UnfinishedVerificationException: 
Missing method call for verify(mock) here:
-> at (redacted)

Example of correct verification:
    verify(mock).doSomething()

Also, this error might show up because you verify either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.

at [test method name and …
Run Code Online (Sandbox Code Playgroud)

junit unit-testing mockito junit5

37
推荐指数
5
解决办法
3万
查看次数

Groovy加载.csv文件

如何在grails上的groovy中读取和导入.csv文件.我有.csv文件包含数据,
需要使用用户界面导入到db.

csv import groovy

35
推荐指数
2
解决办法
6万
查看次数

Cassandra cqlsh无法连接到任何服务器 - 127.0.0.1:9160(已关闭)>已关闭

我在OSX上安装了Cassandra.尝试从/ bin /运行cqlsh时,出现以下错误:

> Connection error: ('Unable to connect to any servers', {'127.0.0.1':
> ConnectionShutdown('Connection <AsyncoreConnection(4522252560)
> 127.0.0.1:9160 (closed)> is already closed',)})
Run Code Online (Sandbox Code Playgroud)

我在安装Cassandra时遇到了困难,并且使用了brew install cassandra,从datastax安装了DSE,并从Apache下载了二进制文件.

cassandra cqlsh

19
推荐指数
5
解决办法
7万
查看次数

Jersey 2.6 REST服务升级到Java 8 tomcat 8异常:java.lang.NoSuchMethodError:javax.validation.Configuration.getBootstrapConfiguration

我们有一场战争,通过基于hibernate-4.2.7验证的验证(实现validation-api-1.0.0.GA),在场地2.6上展示休息服务.

在我们升级到java 8和tc-server 3.1.X之前,一切正常.
升级到java 8之后,看起来在验证API中出现了问题.
我们得到了

java.lang.NoSuchMethodError:javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;

当我们从客户端发送休息请求时.
最奇怪的是,这种行为并不构成
当我从依赖项添加或删除jar时,它有时会起作用,有时候不起作用.

我们得到以下例外

SEVERE [tomcat-http--1] org.apache.catalina.core.StandardWrapperValve.invoke Servlet.service() for servlet [jerseyServlet] in context with path [/Analyzer] threw exception [A MultiException has 1 exceptions.  They are:
1. java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;
] with root cause
 java.lang.NoSuchMethodError: javax.validation.Configuration.getBootstrapConfiguration()Ljavax/validation/BootstrapConfiguration;
    at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getTraversableResolver(ValidationBinder.java:287)
    at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getDefaultValidatorContext(ValidationBinder.java:268)
    at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.getDefaultValidator(ValidationBinder.java:248)
    at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.provide(ValidationBinder.java:199)
    at org.glassfish.jersey.server.validation.internal.ValidationBinder$ConfiguredValidatorProvider.provide(ValidationBinder.java:173)
    at org.jvnet.hk2.internal.FactoryCreator.create(FactoryCreator.java:96)
    at org.jvnet.hk2.internal.SystemDescriptor.create(SystemDescriptor.java:456)
    at org.jvnet.hk2.internal.PerLookupContext.findOrCreate(PerLookupContext.java:69)
    at org.jvnet.hk2.internal.Utilities.createService(Utilities.java:2445)
    at org.jvnet.hk2.internal.ServiceLocatorImpl.getService(ServiceLocatorImpl.java:621)
    at org.jvnet.hk2.internal.IterableProviderImpl.get(IterableProviderImpl.java:107)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:135)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$VoidOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:136)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:406)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:350)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271) …
Run Code Online (Sandbox Code Playgroud)

validation jersey java-8 jersey-2.0 hk2

11
推荐指数
1
解决办法
2534
查看次数

Jersey @ManagedAsync并在HTTP线程和Worker线程之间复制数据

我正在研究一个有两种口味的项目,有多种租赁方式.

该项目公开了一个我希望异步的REST服务.所以我的基本服务看起来像

@Component
@Path("/resouce")
@Consumes(MediaType.APPLICATION_JSON)
public class ResouceEndpoint {
    @POST
    @ManagedAsync
    public void add(final Event event, @Suspended final AsyncResponse asyncResponse) {
        resouce.insert (event);
        asyncResponse.resume( Response.status(Response.Status.NO_CONTENT).build());     
    }
}
Run Code Online (Sandbox Code Playgroud)

没有多租户就可以正常工作,我可以免费获得内部Jersey执行器服务的好处.请参阅@ManagedAsync

当我切换到多租户时,我在请求上添加了一个过滤器,用于解析租户ID并将其放在本地线程上(在我们的例子中是HTTP线程).

当处理链命中上面的"add()"方法时,当前线程是Jersey执行器服务提供的线程,因此它不包括我的租户ID.我只能考虑以下选项来解决这个问题.

将ResouceEndpoint扩展为MutliTenantResouceEndpoint并使用我自己的线程执行器删除@ManagedAsync

public class MutliTenantResouceEndpoint extends ResouceEndpoint {
    @POST
    public void add(final Event event, @Suspended final AsyncResponse asyncResponse) {
        final String tenantId = getTeantIdFromThreadLocal();
        taskExecutor.submit(new Callable<Void>() {
            @Override
            public Void call() throws Exception {
                setTeantIdToThreadLocal(tenantId);
                browserEventsAnalyzer.insertEvent(event);
                Response response = Response.status(Response.Status.NO_CONTENT).build();
                asyncResponse.resume(response);
                return null;
            }
        });
    }
}
Run Code Online (Sandbox Code Playgroud)

但是这样我需要管理自己的线程执行器,感觉就像我在这里遗漏了一些东西.有关不同方法的任何建议吗?

java rest multithreading jersey servlet-3.0

10
推荐指数
1
解决办法
2947
查看次数

使用sFTP服务构建Azure存储blob

我们需要创建大型(1G-16G)行数据报告来压缩和加密它们.我们的客户将通过sFTP使用这些报告.我们正在替换现有的实施,因此我们的客户应该透明地进行此更改.

Azure Blob服务不公开sFTP服务,因此我们需要一些方法来使用sFTP服务来覆盖它.类似于FTP到Azure Blob存储桥的基于工作者角色的东西.worker角色会将sFTP端点暴露给外部世界.我们将为每个客户设置一个容器,并限制工作者角色的访问权限,以便保护容器免受直接访问.

我的问题是:

  1. 您如何看待这种方法?
  2. 使用辅助角色的sFTP是否可以动态缩放/缩小,同时从客户的角度保持相同的DNS名称?
  3. Azure Blob服务是否支持压缩或加密?
  4. 您熟悉sFTP工作者角色,类似于FTP到Azure Blob存储桥(更好的开源)吗?

相关问题:
在Windows Azure中:什么是Web角色,辅助角色和VM角色?
Azure架构设计

sftp azure azure-storage-blobs azure-worker-roles

7
推荐指数
1
解决办法
4973
查看次数

使用 Azure powershell 列出容器上的现有 SASToken

通过 powershell 创建 SASToken 时,它会从 New-AzureStorageContainerSASToken comdlet 返回创建的 SAS 令牌 URL。

$Context = New-AzureStorageContext -StorageAccountName $StorageAccount -StorageAccountKey $StorageAccountKey                                                        
$now = Get-Date

$sasUrl = New-AzureStorageContainerSASToken -Name mycontainer -Permission rwdl -StartTime $now.AddHours(-1) -ExpiryTime $now.AddMonths(1) -Context $context -FullUri  
echo $sasUrl 
Run Code Online (Sandbox Code Playgroud)

但是现在万一我丢失了它,我该如何列出现有的 SASToken?您可能在同一个容器上有几个。

尝试了 Get-AzureStorageContainer,但此信息不可用。
与其他 Get-AzureStorage* 一起玩,但未能找到它。
是否通过 powershell 支持此操作?

powershell azure azure-storage azure-powershell azure-blob-storage

4
推荐指数
1
解决办法
4377
查看次数

在 Spring Batch 中访问 Step Scope 之外的 Bean

是否可以访问在步骤范围之外定义的 bean?例如,如果我定义一个策略“strategyA”并将其传递到作业参数中,我希望 @Value 解析为 strategyA bean。这可能吗?我目前正在通过从 applicationContext 手动获取 bean 来解决这个问题。

@Bean
@StepScope
public Tasklet myTasklet(
        @Value("#{jobParameters['strategy']}") MyCustomClass myCustomStrategy)

    MyTasklet myTasklet= new yTasklet();

    myTasklet.setStrategy(myCustomStrategy);

    return myTasklet;
}
Run Code Online (Sandbox Code Playgroud)

我希望能够在无需修改代码的情况下添加更多策略。

spring spring-batch

3
推荐指数
1
解决办法
3735
查看次数

与 java-client / spring-rabbit 进行rabbitmq-consistency-hash-exchange

我想从 java 客户端使用rabbitmq-consistency-hash-exchange 的功能,或者最好使用 spring 抽象 spring-amqp。不幸的是,我未能找到一个解释 java 用法并引用要包含的 jar 依赖项的示例,请提出建议。

rabbitmq spring-rabbit

2
推荐指数
1
解决办法
1494
查看次数

是否可以创建我自己的自定义注释来充当 Spring @Controller 注释?

在我的 Spring 应用程序中,我有带有两个注释的控制器:

@Controller - Spring注解

@AdminPanelController - 我的注释

是否可以更改我的注释,以便我可以使用 if 而无需另外放置 @Controller ?

我希望 Spring 将我的注释处理为 @Controller 注释。

java spring spring-boot

1
推荐指数
1
解决办法
3754
查看次数

当我在 springboot 项目中点击 http://localhost:8080/h2-console url 时,出现 Whitelabel 错误页面错误

this is my application.properties file in src/main/resource


spring.datasource.platform=h2
spring.h2.console.enabled=true  
spring.datasource.url=jdbc:h2:mem:testdb
Run Code Online (Sandbox Code Playgroud)

我在 pom.xml 中添加了 h2 依赖项

<dependency>
        <groupId>com.h2database</groupId>
        <artifactId>h2</artifactId>
        <scope>runtime</scope>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

另一种是Jpa依赖和Web依赖

<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-data-jpa</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
Run Code Online (Sandbox Code Playgroud)

整个项目在邮递员中运行良好,但当我在网络浏览器中点击 url 时不起作用

java h2 spring-boot postman

1
推荐指数
1
解决办法
3631
查看次数