@Test public void acquireLease() { LeaseState leaseState = mock(LeaseState.class); ClientDescriptor clientDescriptor = mock(ClientDescriptor.class); when(leaseState.acquireLease(clientDescriptor, 1000L)).thenReturn(true); LeaseServiceImpl leaseService = new LeaseServiceImpl(new LeaseConfiguration(1000), leaseState); LeaseResult leaseResult = leaseService.acquireLease(clientDescriptor); assertTrue(leaseResult.isLeaseGranted()); assertEquals(1000L, leaseResult.getLeaseLength()); }
@Override public LeaseResult acquireLease(ClientDescriptor clientDescriptor) { LOGGER.debug("Client requested lease: " + clientDescriptor); long currentLeaseLength = getLeaseLength(); boolean acquiredLease = leaseState.acquireLease(clientDescriptor, currentLeaseLength); if (acquiredLease) { LOGGER.debug("Client acquired lease: " + clientDescriptor); return LeaseResult.leaseGranted(currentLeaseLength); } else { LOGGER.debug("Client lease request rejected because connection is closing: " + clientDescriptor); return LeaseResult.leaseNotGranted(); } }
LeaseServiceImpl implements LeaseService { @Override public LeaseResult acquireLease(ClientDescriptor clientDescriptor) { LOGGER.debug("Client requested lease: " + clientDescriptor); long currentLeaseLength = getLeaseLength(); boolean acquiredLease = leaseState.acquireLease(clientDescriptor, currentLeaseLength); if (acquiredLease) { LOGGER.debug("Client acquired lease: " + clientDescriptor); return LeaseResult.leaseGranted(currentLeaseLength); } else { LOGGER.debug("Client lease request rejected because connection is closing: " + clientDescriptor); return LeaseResult.leaseNotGranted(); } } }
LeaseServiceImpl implements LeaseService { @Override public LeaseResult acquireLease(ClientDescriptor clientDescriptor) { LOGGER.debug("Client requested lease: " + clientDescriptor); long currentLeaseLength = getLeaseLength(); boolean acquiredLease = leaseState.acquireLease(clientDescriptor, currentLeaseLength); if (acquiredLease) { LOGGER.debug("Client acquired lease: " + clientDescriptor); return LeaseResult.leaseGranted(currentLeaseLength); } else { LOGGER.debug("Client lease request rejected because connection is closing: " + clientDescriptor); return LeaseResult.leaseNotGranted(); } } LeaseServiceImpl(LeaseConfiguration leaseConfiguration, LeaseState leaseState); }
LeaseServiceImpl implements LeaseService { @Override public LeaseResult acquireLease(ClientDescriptor clientDescriptor) { LOGGER.debug("Client requested lease: " + clientDescriptor); long currentLeaseLength = getLeaseLength(); boolean acquiredLease = leaseState.acquireLease(clientDescriptor, currentLeaseLength); if (acquiredLease) { LOGGER.debug("Client acquired lease: " + clientDescriptor); return LeaseResult.leaseGranted(currentLeaseLength); } else { LOGGER.debug("Client lease request rejected because connection is closing: " + clientDescriptor); return LeaseResult.leaseNotGranted(); } } LeaseServiceImpl(LeaseConfiguration leaseConfiguration, LeaseState leaseState); @Override LeaseResult acquireLease(ClientDescriptor clientDescriptor); @Override void disconnected(ClientDescriptor clientDescriptor); @Override void reconnecting(ClientDescriptor clientDescriptor); @Override void reconnected(ClientDescriptor clientDescriptor); }
LeaseServiceImpl implements LeaseService { @Override public LeaseResult acquireLease(ClientDescriptor clientDescriptor) { LOGGER.debug("Client requested lease: " + clientDescriptor); long currentLeaseLength = getLeaseLength(); boolean acquiredLease = leaseState.acquireLease(clientDescriptor, currentLeaseLength); if (acquiredLease) { LOGGER.debug("Client acquired lease: " + clientDescriptor); return LeaseResult.leaseGranted(currentLeaseLength); } else { LOGGER.debug("Client lease request rejected because connection is closing: " + clientDescriptor); return LeaseResult.leaseNotGranted(); } } LeaseServiceImpl(LeaseConfiguration leaseConfiguration, LeaseState leaseState); @Override LeaseResult acquireLease(ClientDescriptor clientDescriptor); @Override void disconnected(ClientDescriptor clientDescriptor); @Override void reconnecting(ClientDescriptor clientDescriptor); @Override void reconnected(ClientDescriptor clientDescriptor);  }