Пример #1
0
  @Test
  public void testHeartbeatResumedEvent() throws InterruptedException {
    hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());
    final HazelcastInstance instance2 = hazelcastFactory.newHazelcastInstance();

    // make sure client is connected to instance2
    String keyOwnedByInstance2 = generateKeyOwnedBy(instance2);
    IMap<String, String> map = client.getMap(randomString());
    map.put(keyOwnedByInstance2, randomString());

    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    connectionManager.addConnectionHeartbeatListener(
        new ConnectionHeartbeatListener() {
          @Override
          public void heartbeatResumed(Connection connection) {
            assertEquals(
                instance2.getCluster().getLocalMember().getAddress(), connection.getEndPoint());
            countDownLatch.countDown();
          }

          @Override
          public void heartbeatStopped(Connection connection) {}
        });

    blockMessagesFromInstance(instance2, client);
    sleepMillis(HEARTBEAT_TIMEOUT_MILLIS * 2);
    unblockMessagesFromInstance(instance2, client);

    assertOpenEventually(countDownLatch);
  }
 public ClientInvocationServiceSupport(HazelcastClientInstanceImpl client) {
   this.client = client;
   this.connectionManager = client.getConnectionManager();
   this.executionService = client.getClientExecutionService();
   connectionManager.addConnectionListener(this);
   connectionManager.addConnectionHeartbeatListener(this);
   this.partitionService = client.getClientPartitionService();
   responseThread =
       new ResponseThread(
           client.getThreadGroup(),
           client.getName() + ".response-",
           client.getClientConfig().getClassLoader());
   responseThread.start();
 }
Пример #3
0
  @Test
  public void testHeartbeatStoppedEvent() throws InterruptedException {
    HazelcastInstance instance = hazelcastFactory.newHazelcastInstance();
    HazelcastInstance client = hazelcastFactory.newHazelcastClient(getClientConfig());

    HazelcastClientInstanceImpl clientImpl = getHazelcastClientInstanceImpl(client);
    ClientConnectionManager connectionManager = clientImpl.getConnectionManager();
    final CountDownLatch countDownLatch = new CountDownLatch(1);
    connectionManager.addConnectionHeartbeatListener(
        new ConnectionHeartbeatListener() {
          @Override
          public void heartbeatResumed(Connection connection) {}

          @Override
          public void heartbeatStopped(Connection connection) {
            countDownLatch.countDown();
          }
        });

    blockMessagesFromInstance(instance, client);
    assertOpenEventually(countDownLatch);
  }