TestHazelcastFactory客户端模拟无法正常工作

时间:2016-11-03 12:56:38

标签: java distributed-computing hazelcast

我正在尝试使用TestHazelcastFactory使Mocked hazelcast客户端连接到Mocked HazelCast intance.Here是我试过的代码

服务器

TestHazelcastFactory factory = new TestHazelcastFactory();
 HazelcastInstance instance= factory.newHazelcastInstance(config);

客户端

TestHazelcastFactory factory = new TestHazelcastFactory();
HazelcastInstance instance= factory.newHazelcastClient(clientConfig);

但它无法连接到模拟的Hazelcast实例。

1 个答案:

答案 0 :(得分:2)

首先,您需要hazelcast-tests.jarshazelcast-client-tests.jar

testCompile "com.hazelcast:hazelcast:$HZ_VERSION:tests" testCompile "com.hazelcast:hazelcast-client:$HZ_VERSION:tests"

接下来,您需要使用相同的TestHazelcastFactory清除成员和客户的HazelcastInstance

检查此代码段

    TestHazelcastFactory testHazelcastFactory = new TestHazelcastFactory();

    HazelcastInstance member = testHazelcastFactory.newHazelcastInstance();
    IMap<Object, Object> testMap1 = member.getMap("test");
    testMap1.put(1, "test");

    HazelcastInstance client = testHazelcastFactory.newHazelcastClient();
    IMap<Object, Object> testMap2 = client.getMap("test");
    Object o = testMap2.get(1);
    System.out.println("o = " + o);

如果您有任何问题,请与我们联系。

干杯,

维克