Integration testing using Hazelcast Enterprise Client

200 views
Skip to first unread message

ulrich...@gmail.com

unread,
Nov 6, 2018, 9:53:29 AM11/6/18
to Hazelcast
In an application I am developing, I am using the Hazelcast Enterprise client to connect to a Hazelcast Enterprise cluster we are running in our organization.

I now want to unit test some code that uses the client but instead of mocking, I want to actually create a HazelcastInstance that my client code can use.

Doing that is easy but of course it is using the HazelcastInstance from the hazelcast-enterprise module which requires a license key. Changing the dependency to hazelcast will allow me to run the tests, but using the HazelcastClient from the open source module and not the enterprise module we are using for production.

Is there any way - within the same build - to either
  • Start an open source HazelcastInstance and connect with the Enterprise client
  • Start an Enterprise HazelcastInstance using some "testing" license key and connect with the Enterprise client
  • Another option achieving the same?
Cheers,

Uli

oxy...@gmail.com

unread,
Nov 6, 2018, 10:05:28 AM11/6/18
to Hazelcast
We do something similar, but we don't have the enterprise edition, both client and instance are an instanceof HazelcastInstance
Here is how we do it, some code removed for security reasons:

static final Future<HazelcastInstance> HAZELCAST_INSTANCE=CompletableFuture.supplyAsync(() -> {
    if(SHOULD_START_OWN_HZ_SERVER){
      final Config config=new Config()
         .setProperty("hazelcast.shutdownhook.enabled","false")
         .setProperty("hazelcast.logging.type","log4j")
         .addQueueConfig(new QueueConfig("*"))
         .addMapConfig(new MapConfig("*")
            .setBackupCount(1)
            .setMaxIdleSeconds(0)
            .setEvictionPolicy(NONE)
            .setMergePolicyConfig(new MergePolicyConfig().setPolicy(LatestUpdateMapMergePolicy.class.getName())));
      config.getGroupConfig()
         .setName(HAZELCAST_USERNAME)
         .setPassword(HAZELCAST_PASSWORD);
      final NetworkConfig networkConfig=config.getNetworkConfig()
         .setPublicAddress(Startup.getFQDNHostname())
         .setPortAutoIncrement(false).setPort(5702).setReuseAddress(true);
      final JoinConfig join=networkConfig.getJoin();
      join.getMulticastConfig().setEnabled(false);
      join.getTcpIpConfig().setMembers(STATIC_HAZELCAST_MEMBERS).setEnabled(true);
      HazelcastSerializers.register(config.getSerializationConfig());
      return Hazelcast.newHazelcastInstance(config);
    }else{
      final ClientConfig config=new ClientConfig()
         .setProperty("hazelcast.shutdownhook.enabled","false")
         .setProperty("hazelcast.logging.type","log4j");
      config.getGroupConfig()
         .setName(HAZELCAST_USERNAME)
         .setPassword(HAZELCAST_PASSWORD);
      config.getNetworkConfig()
         .setAddresses(STATIC_HAZELCAST_MEMBERS)
         .setRedoOperation(true)
         .setConnectionAttemptLimit(Math.max(2,STATIC_HAZELCAST_MEMBERS.size()-1));
      HazelcastSerializers.register(config.getSerializationConfig());
      return HazelcastClient.newHazelcastClient(config);
    }
  }).exceptionally(e -> {
    ...
    ...
    return null;
  });


ulrich...@gmail.com

unread,
Nov 6, 2018, 10:16:27 AM11/6/18
to Hazelcast
Thanks, this is basically how I do it myself. But it is completely missing the point of being able to test using the hazelcast-enterprise-client.

Cheers,

Uli

oxy...@gmail.com

unread,
Nov 6, 2018, 10:22:30 AM11/6/18
to Hazelcast
I understand, we have it like this so dev environment start their own HZ server, tests and production connects to their own cluster.
You could probably use it like that and have maven profiles to test in some environment that has access to the license like a build server for example.
Reply all
Reply to author
Forward
0 new messages