@Override public String toString() { return "ClientConnectionRequest{group=" + getServerGroup() + ", excluded=" + getExcludedServers() + "}"; }
@Override public void toData(DataOutput out) throws IOException { super.toData(out); InternalDataSerializer.invokeToData(this.currentServer, out); }
@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(); }
@Override public void fromData(DataInput in) throws IOException, ClassNotFoundException { super.fromData(in); this.currentServer = new ServerLocation(); InternalDataSerializer.invokeFromData(this.currentServer, in); }
@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; } }
@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()); }
private ClientConnectionResponse pickServer(ClientConnectionRequest clientRequest) { ServerLocation location = loadSnapshot.getServerForConnection(clientRequest.getServerGroup(), clientRequest.getExcludedServers()); return new ClientConnectionResponse(location); }
@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)); }