2016-11-03 96 views
1

我試圖用TestHazelcastFactory使嘲笑hazelcast客戶端連接到嘲笑HazelCast intance.Here是我曾嘗試TestHazelcastFactory客戶端模擬不工作

服務器

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

代碼客戶端

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

但它無法連接t o嘲諷的Hazelcast實例。

+0

請分享會員和客戶端的配置 –

+0

的配置也不過只是用戶名和password.Its亙古不具有任何其他細節 – pppavan

+0

親愛@pppavan,請查看我的答案,如果接受你沒有進一步的問題。 –

回答

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); 

讓我知道如果您有任何問題。

乾杯,

維克