在本地计算机上进行Hazelcast单元测试,无法使用127.0.0.1创建集群

时间:2012-10-01 06:12:06

标签: java distributed-caching hazelcast

我有一个带有hazelcast版本的spring-hibernate Web应用程序:1.9.4.8 我使用默认的hazelcast配置而不是spring集成。我使用JUnit非事务测试进行单元测试。我使用@Before在第一时间关闭所有Hazelcast实例。同样@After清理。

由于我的计算机在我公司的网络中,我正在配置hazelcast tcp-ip,其中各自的IP将在其本地测试和使用该应用程序。

但是,每当我将IP从网络IP更改为127.0.0.1时,我就无法加入多个成员。但之前,当ip的conf。仿佛是:            192.168.24.27
  

我需要将它从特定的ip地址更改为标准版127.0.0.1,以便让不同的开发人员也可以在自己的计算机上进行测试...

以下是我的样本单元测试的一部分:

  ///
        LOG.info("test is begining");
        Map map;
        int memberSize = 0;
        Config config = new Config();
        // Hazelcast cluster member 1
        final HazelcastInstance customInstance1 = Hazelcast.newHazelcastInstance(null);  
        assertEquals(2, clusterListener.getMemberSize());   
        getApplicationMap().put("member2", 2);  

        // shutdown member 1
        customInstance1.getLifecycleService().shutdown(); 

        // Hazelcast cluster new member 1
        final HazelcastInstance customInstance2 = Hazelcast.newHazelcastInstance(null); 
        assertEquals(2, clusterListener.getMemberSize());   
        getApplicationMap().put("member2_new", 2);  

        assertEquals(3, getApplicationMap().size()); 

        LOG.info("\n\n *** Hazelcast test is OK. *** \n");
  ///

以下是我的问题的hazelcast配置的简短但相关的部分: ...

<port auto-increment="true">5701</port>
    <join>
        <multicast enabled="false">
            <multicast-group>224.2.2.3</multicast-group>
            <multicast-port>54327</multicast-port>
        </multicast>
        <tcp-ip enabled="true">
            <interface>127.0.0.1</interface>  // it was 192.168.24.27 before and was working
        </tcp-ip>
    </join>
    <interfaces enabled="true">
            <interface>127.0.0.*</interface> 
    </interfaces>

...

这里的相关日志: ...

Members [1] {
Member [127.0.0.1:5701] this
}


28.Eyl.2012 16:01:40 com.hazelcast.impl.management.ManagementCenterService
INFO: /127.0.0.1:5701 [elekCluster] Hazelcast Management Center started at port 5801.
28.Eyl.2012 16:01:40 com.hazelcast.impl.LifecycleServiceImpl
INFO: /127.0.0.1:5701 [elekCluster] Address[127.0.0.1:5701] is STARTED
16:01:40,149  INFO HazelcastTest:35 - test is begining
28.Eyl.2012 16:01:40 com.hazelcast.config.XmlConfigBuilder
INFO: Looking for hazelcast.xml config file in classpath.
28.Eyl.2012 16:01:40 com.hazelcast.config.XmlConfigBuilder
INFO: Using configuration file /C:/dev/WORKSPACE_Myeclipse/elek_workspace/elek/elek_core_service/target/test-classes/hazelcast.xml in the classpath.
28.Eyl.2012 16:01:40 com.hazelcast.system
INFO: /127.0.0.1:5702 [elekCluster] Hazelcast 1.9.4.8 (20120209) starting at Address[127.0.0.1:5702]
28.Eyl.2012 16:01:40 com.hazelcast.system
INFO: /127.0.0.1:5702 [elekCluster] Copyright (C) 2008-2011 Hazelcast.com
28.Eyl.2012 16:01:40 com.hazelcast.impl.LifecycleServiceImpl
INFO: /127.0.0.1:5702 [elekCluster] Address[127.0.0.1:5702] is STARTING
28.Eyl.2012 16:01:40 com.hazelcast.impl.TcpIpJoiner
INFO: /127.0.0.1:5702 [elekCluster] connecting to Address[127.0.0.1:5703]
28.Eyl.2012 16:01:40 com.hazelcast.impl.TcpIpJoiner
INFO: /127.0.0.1:5702 [elekCluster] connecting to Address[127.0.0.1:5701]
28.Eyl.2012 16:01:40 com.hazelcast.nio.InSelector
INFO: /127.0.0.1:5701 [elekCluster] 5701 is accepting socket connection from /127.0.0.1:63486
28.Eyl.2012 16:01:40 com.hazelcast.nio.InSelector
INFO: /127.0.0.1:5701 [elekCluster] 5701 accepted socket connection from /127.0.0.1:63486
28.Eyl.2012 16:01:40 com.hazelcast.nio.ConnectionManager
WARNING: /127.0.0.1:5701 [elekCluster] Two connections from the same endpoint Address[127.0.0.1:5702], acceptTypeConnection=true,  now accept=false
28.Eyl.2012 16:01:40 com.hazelcast.nio.InSelector
INFO: /127.0.0.1:5702 [elekCluster] 5702 is accepting socket connection from /127.0.0.1:63479
28.Eyl.2012 16:01:40 com.hazelcast.nio.InSelector
INFO: /127.0.0.1:5702 [elekCluster] 5702 accepted socket connection from /127.0.0.1:63479
28.Eyl.2012 16:01:40 com.hazelcast.cluster.ClusterManager
INFO: /127.0.0.1:5702 [elekCluster] Removing Address Address[127.0.0.1:5701]
28.Eyl.2012 16:01:45 com.hazelcast.impl.TcpIpJoiner
INFO: /127.0.0.1:5702 [elekCluster] 


Members [1] {
    Member [127.0.0.1:5702] this
}
...

我希望得到任何帮助,在此先感谢..

2 个答案:

答案 0 :(得分:0)

请参阅邮件组中的相关mail thread

答案 1 :(得分:0)

当我将hazelcast的版本从1.9.4.8升级到2.3.1时,问题就消失了。