如何使用 jCache 和 HazelcastProvider 实现缓存单元测试?
目前我收到此错误:
Caused by: java.lang.IllegalStateException: Unable to connect to any address in the config! The following addresses were tried: [localhost/127.0.0.1:5701, localhost/127.0.0.1:5702, localhost/127.0.0.1:5703]
简化代码如下:
@RunWith(SpringJUnit4ClassRunner.class)
@TestPropertySource("classpath:provider.properties")
@ContextConfiguration(classes = {
CustomCacheConfiguration.class
})
我在 hazelcast.xml 文件中声明了缓存以及多播,所以我理解正确,我应该有一个嵌入式实例。
//编辑
这是 hazelcast.xml 文件:
<hazelcast xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.hazelcast.com/schema/config
http://www.hazelcast.com/schema/config/hazelcast-config-3.8.xsd"
xmlns="http://www.hazelcast.com/schema/config">
<group>
<name>test</name>
<password>test</password>
</group>
<network>
<join>
<multicast enabled="true"/>
</join>
</network>
<!-- cache definitions -->
</hazelcast>
这是日志:
Jun 28, 2017 10:55:45 AM com.hazelcast.client.config.XmlClientConfigLocator
INFO: Loading 'hazelcast-client-default.xml' from classpath.
Jun 28, 2017 10:55:45 AM com.hazelcast.client.config.XmlClientConfigLocator
INFO: Loading 'hazelcast-client-default.xml' from classpath.
Jun 28, 2017 10:55:45 AM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [dev] [3.8.2] HazelcastClient 3.8.2 (20170518 - a60f944) is STARTING
Jun 28, 2017 10:55:46 AM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [dev] [3.8.2] HazelcastClient 3.8.2 (20170518 - a60f944) is STARTED
Jun 28, 2017 10:55:46 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
INFO: hz.client_0 [dev] [3.8.2] Trying to connect to [127.0.0.1]:5701 as owner member
Jun 28, 2017 10:55:46 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
INFO: hz.client_0 [dev] [3.8.2] Trying to connect to [127.0.0.1]:5702 as owner member
Jun 28, 2017 10:55:46 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
INFO: hz.client_0 [dev] [3.8.2] Trying to connect to [127.0.0.1]:5703 as owner member
Jun 28, 2017 10:55:46 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
WARNING: hz.client_0 [dev] [3.8.2] Unable to get alive cluster connection, try in 2940 ms later, attempt 1 of 2.
Jun 28, 2017 10:55:49 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
INFO: hz.client_0 [dev] [3.8.2] Trying to connect to [127.0.0.1]:5703 as owner member
Jun 28, 2017 10:55:49 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
INFO: hz.client_0 [dev] [3.8.2] Trying to connect to [127.0.0.1]:5702 as owner member
Jun 28, 2017 10:55:49 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
INFO: hz.client_0 [dev] [3.8.2] Trying to connect to [127.0.0.1]:5701 as owner member
Jun 28, 2017 10:55:49 AM com.hazelcast.client.spi.impl.ClusterListenerSupport
WARNING: hz.client_0 [dev] [3.8.2] Unable to get alive cluster connection, try in 2996 ms later, attempt 2 of 2.
Jun 28, 2017 10:55:52 AM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [dev] [3.8.2] HazelcastClient 3.8.2 (20170518 - a60f944) is SHUTTING_DOWN
Jun 28, 2017 10:55:52 AM com.hazelcast.core.LifecycleService
INFO: hz.client_0 [dev] [3.8.2] HazelcastClient 3.8.2 (20170518 - a60f944) is SHUTDOWN