private ClientConnectionResponse pickServer(ClientConnectionRequest clientRequest) { ServerLocation location = loadSnapshot.getServerForConnection(clientRequest.getServerGroup(), clientRequest.getExcludedServers()); return new ClientConnectionResponse(location); }
@Override public ServerLocation findServer(Set<ServerLocation> excludedServers, String serverGroup) { security.authorize(CLUSTER, READ, ALL, ALL); InternalLocator internalLocator = (InternalLocator) locator; // In order to ensure that proper checks are performed on the request we will use // the locator's processRequest() API. We assume that all servers have Protobuf // enabled. ClientConnectionRequest clientConnectionRequest = new ClientConnectionRequest(excludedServers, serverGroup); ClientConnectionResponse connectionResponse = (ClientConnectionResponse) internalLocator .getServerLocatorAdvisee().processRequest(clientConnectionRequest); ServerLocation serverLocation = null; if (connectionResponse != null && connectionResponse.hasResult()) { serverLocation = connectionResponse.getServer(); } return serverLocation; } }
@Override public String toString() { return "ClientConnectionResponse{server=" + getServer() + "}"; }
@Override public ServerLocation findServer(Set excludedServers) { if (PoolImpl.TEST_DURABLE_IS_NET_DOWN) { return null; } ClientConnectionRequest request = new ClientConnectionRequest(excludedServers, serverGroup); ClientConnectionResponse response = (ClientConnectionResponse) queryLocators(request); if (response == null) { throw new NoAvailableLocatorsException( "Unable to connect to any locators in the list " + locators); } return response.getServer(); }
private ClientConnectionResponse pickReplacementServer(ClientReplacementRequest clientRequest) { ServerLocation location = loadSnapshot.getReplacementServerForConnection(clientRequest.getCurrentServer(), clientRequest.getServerGroup(), clientRequest.getExcludedServers()); return new ClientConnectionResponse(location); }
@Override public ServerLocation findReplacementServer(ServerLocation currentServer, Set/* <ServerLocation> */ excludedServers) { if (PoolImpl.TEST_DURABLE_IS_NET_DOWN) { return null; } ClientReplacementRequest request = new ClientReplacementRequest(currentServer, excludedServers, serverGroup); ClientConnectionResponse response = (ClientConnectionResponse) queryLocators(request); if (response == null) { throw new NoAvailableLocatorsException( "Unable to connect to any locators in the list " + locators); } return response.getServer(); }
@Test public void testServerReturnedFromHandler() throws Exception { when(serverLocatorAdviseeMock.processRequest(any(Object.class))) .thenReturn(new ClientConnectionResponse(new ServerLocation(HOSTNAME, PORT))); LocatorAPI.GetServerRequest getServerRequest = ProtobufRequestUtilities.createGetServerRequest(); Result operationHandlerResult = getOperationHandlerResult(getServerRequest); assertTrue(operationHandlerResult instanceof Success); validateGetServerResponse((GetServerResponse) operationHandlerResult.getMessage()); }
@Test public void testServerReturnedForExistentGroup() throws Exception { when( serverLocatorAdviseeMock.processRequest(new ClientConnectionRequest(any(), EXISTENT_GROUP))) .thenReturn(new ClientConnectionResponse(new ServerLocation(HOSTNAME, PORT))); LocatorAPI.GetServerRequest getServerRequest = ProtobufRequestUtilities.createGetServerRequest(EXISTENT_GROUP); Result operationHandlerResult = getOperationHandlerResult(getServerRequest); assertTrue(operationHandlerResult instanceof Success); validateGetServerResponse((GetServerResponse) operationHandlerResult.getMessage()); }
@Test public void testErrorReturnedForNonexistentGroup() throws Exception { when(serverLocatorAdviseeMock .processRequest(new ClientConnectionRequest(any(), NONEXISTENT_GROUP))) .thenReturn(new ClientConnectionResponse(null)); LocatorAPI.GetServerRequest getServerRequest = ProtobufRequestUtilities.createGetServerRequest(NONEXISTENT_GROUP); Result operationHandlerResult = getOperationHandlerResult(getServerRequest); assertTrue(operationHandlerResult instanceof Failure); Failure failure = (Failure) operationHandlerResult; ClientProtocol.ErrorResponse errorResponse = failure.getErrorMessage(); assertEquals(NO_AVAILABLE_SERVER, errorResponse.getError().getErrorCode()); assertTrue(errorResponse.getError().getMessage().contains(NONEXISTENT_GROUP)); }