NonPooledDatasourceSystemListener implements IPentahoSystemListener { @VisibleForTesting protected boolean isPortUsedByServer( IDatabaseConnection databaseConnection ) { String connectionHostName = databaseConnection.getHostname(); InetAddress connectionAddress = null; try { connectionAddress = getAdressFromString( connectionHostName ); } catch ( UnknownHostException e ) { Logger.warn( this, Messages.getInstance().getErrorString( "DatasourceSystemListener.WARN_0001_UNABLE_TO_GET_CONNECTION_ADDRESS" ), e ); return false; } String stringConnectionPort = databaseConnection.getDatabasePort(); String fullyQualifiedServerURL = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL(); URL url = null; try { url = new URL( fullyQualifiedServerURL ); } catch ( MalformedURLException e ) { Logger.warn( this, Messages.getInstance().getErrorString( "DatasourceSystemListener.WARN_0002_UNABLE_TO_PARSE_SERVER_URL" ), e ); return false; } String hostNameUsedByServer = url.getHost(); InetAddress serverAddress = null; try { serverAddress = getAdressFromString( hostNameUsedByServer ); } catch ( UnknownHostException e ) { Logger.warn( this, Messages.getInstance().getErrorString( "DatasourceSystemListener.WARN_0003_UNABLE_TO_GET_SERVER_ADDRESS" ), e ); return false; } int portUsedByServer = url.getPort(); boolean isAddressesEquals = connectionAddress.equals( serverAddress ); boolean isPortsEquals = false; try { Integer connectionPort = Integer.valueOf( stringConnectionPort ); isPortsEquals = connectionPort.equals( portUsedByServer ); } catch ( NumberFormatException e ) { Logger.warn( this, Messages.getInstance().getErrorString( "DatasourceSystemListener.WARN_0004_UNABLE_TO_GET_PORT_NUMBER" ), e ); return false; } return isAddressesEquals && isPortsEquals; }  boolean startup( final IPentahoSession session ); void shutdown();  }
@Test public void testStartupJNDINotCalledIsPortUsedByServer() throws ObjectFactoryException, DatasourceMgmtServiceException { stubGetListOfDatabaseConnectionsMethod( DatabaseAccessType.JNDI ); stubIsPortUsedByServerMethod( false ); stubAddCacheRegionsMethod(); callRealSetupDataSourceForConnection(); callRealStartup(); callStartup(); verify( nonPooledDatasourceSystemListenerSpy, never() ).isPortUsedByServer( any( IDatabaseConnection.class ) ); }