Hazelcast客户端连接到模拟的Hazelcast实例

时间:2016-11-03 08:41:08

标签: java hazelcast

有没有办法让HazelcastClient实例可以连接到Mocked Hazelcast Instance.Am Mocking Hazelcast Instance如下所示

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

但是客户端实例无法连接到上面创建的实例。像下面那样处理客户端

HazelcastInstance instance = HazelcastClient.newHazelcastClient(clientConfig);

有没有办法让我甚至可以模拟客户端实例

2 个答案:

答案 0 :(得分:1)

您是否尝试将5700作为初始端口传递给构造函数?检查https://github.com/hazelcast/hazelcast/blob/master/hazelcast/src/test/java/com/hazelcast/test/TestHazelcastInstanceFactory.java

上的不同选项

答案 1 :(得分:0)

你试过com.hazelcast.client.test.TestHazelcastFactory吗?它有newHazelcastClient(ClientConfig config)。这个简单的样本适合我:

 @org.junit.Before
    public void setUp() throws Exception {
        server = hazelcastFactory.newHazelcastInstance(new Config());
        client = hazelcastFactory.newHazelcastClient();
    }

    @Test
    public void testDistributedMapOps() {
        IMap map = client.getMap("map1");
        map.put("key", "value");
        System.out.println("Map Size: "+map.size());
    }

    @org.junit.After
    public void tearDown() throws Exception {
        client.shutdown();
        server.shutdown();
    }