How do you create a Hazelcast instance embedded in-process/in-memory, without networking?

后端 未结 6 732
深忆病人
深忆病人 2021-02-14 02:09

In my unit tests, I want to create an embedded (in-process/in-memory) Hazelcast instance that does not attempt to start or perform any networking operations at all.

How

6条回答
  •  旧巷少年郎
    2021-02-14 02:20

    FWIW I have created a test in Hazelcast 3.6.1 and programmatically disabled the network cluster using the following code in the constructor. This creates a standalone server for testing.

    It's not as quick as using a mock but it is faster than accepting the default config.

    Config config = new Config();
    config.setProperty("hazelcast.shutdownhook.enabled", "false");
    NetworkConfig network = config.getNetworkConfig();
    network.getJoin().getTcpIpConfig().setEnabled(false);
    network.getJoin().getMulticastConfig().setEnabled(false);
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
    

提交回复
热议问题