SPQRNodeServer extends Application<SPQRNodeServerConfiguration> { protected String registerProcessingNode(final String protocol, final String host, final int servicePort, final int adminPort, final SPQRResourceManagerClient client) throws RequiredInputMissingException, RemoteClientConnectionFailedException, IOException { if(StringUtils.isBlank(protocol)) throw new RequiredInputMissingException("Missing require communication protocol used by resource manager for accessing this node. See 'protocol' property in config file."); if(StringUtils.isBlank(host)) throw new RequiredInputMissingException("Missing required host name used by resource manager for accessing this node. See 'host' property in config file."); if(servicePort < 1) throw new RequiredInputMissingException("Missing required service port used by resource manager for accessing this node. See 'servicePort' property in config file."); if(adminPort < 1) throw new RequiredInputMissingException("Missing required admin port used by resource manager for accessing this node. See 'adminPort' property in config file."); final NodeRegistrationResponse registrationResponse = client.registerNode(protocol, host, servicePort, adminPort); if(registrationResponse == null) throw new RemoteClientConnectionFailedException("Failed to connect with resource manager. Error: no response received"); if(registrationResponse.getState() != NodeRegistrationState.OK) throw new RemoteClientConnectionFailedException("Failed to register processing node with resource manage. Reason: " + registrationResponse.getState() + ". Message: " + registrationResponse.getMessage()); return registrationResponse.getId(); }  void run(SPQRNodeServerConfiguration configuration, Environment environment); static void main(String[] args);  }
@Test public void testRegisterProcessingNode_withEmptyProtocol() throws Exception { try { new SPQRNodeServer().registerProcessingNode("", "localhost", 8080, 8081, Mockito.mock(SPQRResourceManagerClient.class)); Assert.fail("Invalid input"); } catch(RequiredInputMissingException e) { } }
@Test public void testRegisterProcessingNode_withEmptyHost() throws Exception { try { new SPQRNodeServer().registerProcessingNode("http", "", 8080, 8081, Mockito.mock(SPQRResourceManagerClient.class)); Assert.fail("Invalid input"); } catch(RequiredInputMissingException e) { } }
@Test public void testRegisterProcessingNode_withInvalidServicePort() throws Exception { try { new SPQRNodeServer().registerProcessingNode("http", "localhost", -1, 8081, Mockito.mock(SPQRResourceManagerClient.class)); Assert.fail("Invalid input"); } catch(RequiredInputMissingException e) { } }
@Test public void testRegisterProcessingNode_withInvalidAdminPort() throws Exception { try { new SPQRNodeServer().registerProcessingNode("http", "localhost", 8080, -1, Mockito.mock(SPQRResourceManagerClient.class)); Assert.fail("Invalid input"); } catch(RequiredInputMissingException e) { } }
@Test public void testRegisterProcessingNode_withNullReturnedByClient() throws Exception { SPQRResourceManagerClient mockClient = Mockito.mock(SPQRResourceManagerClient.class); Mockito.when(mockClient.registerNode("http", "localhost", 8080, 8081)).thenReturn(null); try { new SPQRNodeServer().registerProcessingNode("http", "localhost", 8080, 8081, mockClient); Assert.fail("Client returned null"); } catch(RemoteClientConnectionFailedException e) { } Mockito.verify(mockClient).registerNode("http", "localhost", 8080, 8081); }
@Test public void testRegisterProcessingNode_withErrorReturnedByClient() throws Exception { SPQRResourceManagerClient mockClient = Mockito.mock(SPQRResourceManagerClient.class); Mockito.when(mockClient.registerNode("http", "localhost", 8080, 8081)).thenReturn(new NodeRegistrationResponse("test", NodeRegistrationState.NODE_ID_COMPUTATION_FAILED)); try { new SPQRNodeServer().registerProcessingNode("http", "localhost", 8080, 8081, mockClient); Assert.fail("Client returned null"); } catch(RemoteClientConnectionFailedException e) { } Mockito.verify(mockClient).registerNode("http", "localhost", 8080, 8081); }
@Test public void testRegisterProcessingNode_withValidIdReturnedByClient() throws Exception { SPQRResourceManagerClient mockClient = Mockito.mock(SPQRResourceManagerClient.class); Mockito.when(mockClient.registerNode("http", "localhost", 8080, 8081)).thenReturn(new NodeRegistrationResponse("test-id", NodeRegistrationState.OK)); Assert.assertEquals("The identifier must be as expected", "test-id", new SPQRNodeServer().registerProcessingNode("http", "localhost", 8080, 8081, mockClient)); Mockito.verify(mockClient).registerNode("http", "localhost", 8080, 8081); }