有一个基于 spring-boot 的 hazelcast 微服务,它通过HazelcastClient
.
考虑到集群是使用 ? 模拟的,编写集成测试的过程是TestHazelcastInstance
什么?
尝试创建一个@TestConfiguration
提供 的配置类TestHazelcastInstance
,但在这种情况下,另一个配置类HazelcastConfig
(提供客户端)似乎没有执行,导致客户端实例没有被实例化。
有什么见解吗?
应用程序.java:
@SpringBootApplication
public class App {
public static void main( final String[] args ) {
SpringApplication.run( App.class, args );
}
}
HazelcastConfig.java(提供客户端):
@Configuration
@ConfigurationProperties( prefix = "hazelcast" )
@Getter
@Setter
public class HazelcastConfig {
private ClientConfig config;
@Bean
public HazelcastInstance hazelcastInstance() {
return HazelcastClient.newHazelcastClient( config );
}
}
AppTest.java,有问题的测试:
@RunWith( SpringRunner.class )
@SpringBootTest( classes = { TestConfig.class } )
@ActiveProfiles( "test" )
public class AppTest {
@Test
public void contextLoads() {
}
}
TestConfig.java,提供TestHazelcastInstance
@TestConfiguration
@Profile( "test" )
@ConfigurationProperties( prefix = "hazelcast.server" )
public class TestConfig {
private Config config;
@Bean( "hazelcastInstance_TEST" )
public HazelcastInstance hazelcastInstance() {
return new TestHazelcastInstanceFactory( 1 ).newHazelcastInstance( config );
}
}