LeaseMaintainerFactory { public static LeaseMaintainer createLeaseMaintainer(Connection connection) { LOGGER.info("Creating LeaseMaintainer for connection: " + connection); ProxyLeaseReconnectListener leaseReconnectListener = new ProxyLeaseReconnectListener(); LeaseAcquirer leaseAcquirer = getLeaseAcquirer(connection, leaseReconnectListener); LeaseMaintainerImpl leaseMaintainer = new LeaseMaintainerImpl(leaseAcquirer); leaseReconnectListener.setUnderlying(leaseMaintainer); LeaseMaintenanceThread leaseMaintenanceThread = new LeaseMaintenanceThread(leaseMaintainer); LeaseExpiryConnectionKillingThread leaseExpiryConnectionKillingThread = new LeaseExpiryConnectionKillingThread(leaseMaintainer, connection); leaseMaintenanceThread.start(); leaseExpiryConnectionKillingThread.start(); return new CleaningLeaseMaintainer(leaseMaintainer, connection, leaseMaintenanceThread, leaseExpiryConnectionKillingThread); }  static LeaseMaintainer createLeaseMaintainer(Connection connection);  }
@Test public void objectsWiredTogetherCorrectly() throws Exception { LeaseMaintainer leaseMaintainer = LeaseMaintainerFactory.createLeaseMaintainer(connection); verify(timeSource, timeout(1000L).times(1)).sleep(2000L); verify(leaseAcquirer, times(1)).acquireLease(); verify(leaseAcquirer, times(0)).close(); timeSource.tickMillis(5000L); verify(timeSource, timeout(1000L).times(2)).sleep(2000L); verify(leaseAcquirer, times(2)).acquireLease(); verify(leaseAcquirer, times(0)).close(); leaseMaintainer.close(); timeSource.tickMillis(5000L); verify(timeSource, timeout(1000L).times(2)).sleep(2000L); verify(leaseAcquirer, times(2)).acquireLease(); verify(leaseAcquirer, times(1)).close(); }