ActiveLeaseAcquirer implements ActiveServerEntity<LeaseMessage, LeaseResponse> { @Override public LeaseResponse invokeActive(ActiveInvokeContext<LeaseResponse> context, LeaseMessage leaseMessage) { LeaseMessageType messageType = leaseMessage.getType(); switch (messageType) { case LEASE_REQUEST: return handleLeaseRequest(context, (LeaseRequest) leaseMessage); case LEASE_RECONNECT_FINISHED: return handleReconnectFinished((LeaseReconnectFinished) leaseMessage); default: throw new AssertionError("Unexpected type of LeaseMessage: " + messageType); } } ActiveLeaseAcquirer(LeaseService leaseService, ClientCommunicator clientCommunicator, IEntityMessenger<LeaseMessage, LeaseResponse> entityMessenger); @Override void connected(ClientDescriptor clientDescriptor); @Override void disconnected(ClientDescriptor clientDescriptor); @Override LeaseResponse invokeActive(ActiveInvokeContext<LeaseResponse> context, LeaseMessage leaseMessage); @Override ActiveServerEntity.ReconnectHandler startReconnect(); @Override void loadExisting(); @Override void createNew(); @Override void synchronizeKeyToPassive(PassiveSynchronizationChannel<LeaseMessage> passiveSynchronizationChannel, int concurrencyKey); @Override void destroy();  }
@Test public void usesServiceToHandleInvokeSuccess() throws Exception { when(leaseService.acquireLease(clientDescriptor)).thenReturn(leaseResult); when(leaseResult.isLeaseGranted()).thenReturn(true); when(leaseResult.getLeaseLength()).thenReturn(300L); ActiveLeaseAcquirer leaseAcquirer = new ActiveLeaseAcquirer(leaseService, clientCommunicator, entityMessenger); LeaseRequestResult response = (LeaseRequestResult) leaseAcquirer.invokeActive(context, new LeaseRequest(0)); assertTrue(response.isConnectionGood()); assertTrue(response.isLeaseGranted()); assertEquals(300L, response.getLeaseLength()); }
@Test public void usesServiceToHandleInvokeFail() throws Exception { when(leaseService.acquireLease(clientDescriptor)).thenReturn(leaseResult); when(leaseResult.isLeaseGranted()).thenReturn(false); ActiveLeaseAcquirer leaseAcquirer = new ActiveLeaseAcquirer(leaseService, clientCommunicator, entityMessenger); LeaseRequestResult response = (LeaseRequestResult) leaseAcquirer.invokeActive(context, new LeaseRequest(0)); assertTrue(response.isConnectionGood()); assertFalse(response.isLeaseGranted()); }