首页 > 解决方案 > java - 使用 IgniteFuture 进行单元测试

问题描述

在我的代码中,我有以下内容:

// for the test:
// executor is an ExecutorService that will run in the current thread
// compute is an IgniteCompute (can be mocked)

String other = "blah";
IgniteFuture<String> future = compute.callAsync(callable).chainAsync(i -> myCreate(i, other), executor);

该方法myCreate是类中的私有方法,我想确保对其进行单元测试。我尝试模拟,IgniteCompute但结果callAsyncchainAsync被模拟,导致我的方法没有被调用。关于如何让真正的myCreate方法在运行上述行的测试中运行的任何想法?

标签: javajunitmockitoignite

解决方案


您可以在嵌入式内存模式下启动 Ignite 进行测试。要启动节点,请使用Ignition.start(...)方法。

Ignite 节点非常轻量级,不需要太多资源即可启动。我认为,它比模拟 IgniteCompute 更容易、更透明。


推荐阅读