@Test public void testExitIfConnectionFails() throws VantiqSQLException { assumeTrue(testDBUsername != null && testDBPassword != null && testDBURL != null && jdbcDriverLoc != null); jdbc.setupJDBC(testDBURL, testDBUsername, testDBPassword, false, 0); core.start(3); assertTrue("Should have succeeded", core.exitIfConnectionFails(core.client, 3)); assertFalse("Success means it shouldn't be closed", core.isClosed()); core.close(); core = new NoSendJDBCCore(sourceName, authToken, targetVantiqServer); FalseClient fc = new FalseClient(sourceName); core.client = core.fClient = fc; fc.initiateFullConnection(targetVantiqServer, authToken); fc.completeWebSocketConnection(true); fc.completeAuthentication(false); assertFalse("Should fail due to authentication failing", core.exitIfConnectionFails(core.client, 3)); assertFalse("Failure does not mean it should be closed", core.isClosed()); core.close(); core = new NoSendJDBCCore(sourceName, authToken, targetVantiqServer); fc = new FalseClient(sourceName); core.client = core.fClient = fc; fc.initiateFullConnection(targetVantiqServer, authToken); fc.completeWebSocketConnection(false); assertFalse("Should fail due to WebSocket failing", core.exitIfConnectionFails(core.client, 3)); assertFalse("Failure does not mean it should be closed", core.isClosed()); core.close(); core = new NoSendJDBCCore(sourceName, authToken, targetVantiqServer); fc = new FalseClient(sourceName); core.client = core.fClient = fc; fc.initiateFullConnection(targetVantiqServer, authToken); fc.completeWebSocketConnection(true); fc.completeAuthentication(true); assertFalse("Should fail due to timeout on source connection", core.exitIfConnectionFails(core.client, 3)); assertFalse("Failure does not mean it should be closed", core.isClosed()); }
public boolean exitIfConnectionFails(ExtensionWebSocketClient client, int timeout) { boolean sourcesSucceeded = false; try { sourcesSucceeded = client.getSourceConnectionFuture().get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { log.error("Timeout: full connection did not succeed within {} seconds: {}", timeout, e); } catch (Exception e) { log.error("Exception occurred while waiting for webSocket connection", e); } if (!sourcesSucceeded) { log.error("Failed to connect to all sources."); if (!client.isOpen()) { log.error("Failed to connect to server url '" + targetVantiqServer + "'."); } else if (!client.isAuthed()) { log.error("Failed to authenticate within " + timeout + " seconds using the given authentication data."); } else { log.error("Failed to connect within 10 seconds"); } return false; } return true; }
JDBCCore { public boolean exitIfConnectionFails(ExtensionWebSocketClient client, int timeout) { boolean sourcesSucceeded = false; try { sourcesSucceeded = client.getSourceConnectionFuture().get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { log.error("Timeout: full connection did not succeed within {} seconds: {}", timeout, e); } catch (Exception e) { log.error("Exception occurred while waiting for webSocket connection", e); } if (!sourcesSucceeded) { log.error("Failed to connect to all sources."); if (!client.isOpen()) { log.error("Failed to connect to server url '" + targetVantiqServer + "'."); } else if (!client.isAuthed()) { log.error("Failed to authenticate within " + timeout + " seconds using the given authentication data."); } else { log.error("Failed to connect within 10 seconds"); } return false; } return true; } }
JDBCCore { public boolean exitIfConnectionFails(ExtensionWebSocketClient client, int timeout) { boolean sourcesSucceeded = false; try { sourcesSucceeded = client.getSourceConnectionFuture().get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { log.error("Timeout: full connection did not succeed within {} seconds: {}", timeout, e); } catch (Exception e) { log.error("Exception occurred while waiting for webSocket connection", e); } if (!sourcesSucceeded) { log.error("Failed to connect to all sources."); if (!client.isOpen()) { log.error("Failed to connect to server url '" + targetVantiqServer + "'."); } else if (!client.isAuthed()) { log.error("Failed to authenticate within " + timeout + " seconds using the given authentication data."); } else { log.error("Failed to connect within 10 seconds"); } return false; } return true; } JDBCCore(String sourceName, String authToken, String targetVantiqServer); }
JDBCCore { public boolean exitIfConnectionFails(ExtensionWebSocketClient client, int timeout) { boolean sourcesSucceeded = false; try { sourcesSucceeded = client.getSourceConnectionFuture().get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { log.error("Timeout: full connection did not succeed within {} seconds: {}", timeout, e); } catch (Exception e) { log.error("Exception occurred while waiting for webSocket connection", e); } if (!sourcesSucceeded) { log.error("Failed to connect to all sources."); if (!client.isOpen()) { log.error("Failed to connect to server url '" + targetVantiqServer + "'."); } else if (!client.isAuthed()) { log.error("Failed to authenticate within " + timeout + " seconds using the given authentication data."); } else { log.error("Failed to connect within 10 seconds"); } return false; } return true; } JDBCCore(String sourceName, String authToken, String targetVantiqServer); String getSourceName(); boolean start(int timeout); void executeQuery(ExtensionServiceMessage message); void executePublish(ExtensionServiceMessage message); void executePolling(String pollQuery); void sendDataFromQuery(HashMap[] queryArray, ExtensionServiceMessage message); void close(); void stop(); boolean exitIfConnectionFails(ExtensionWebSocketClient client, int timeout); }
JDBCCore { public boolean exitIfConnectionFails(ExtensionWebSocketClient client, int timeout) { boolean sourcesSucceeded = false; try { sourcesSucceeded = client.getSourceConnectionFuture().get(timeout, TimeUnit.SECONDS); } catch (TimeoutException e) { log.error("Timeout: full connection did not succeed within {} seconds: {}", timeout, e); } catch (Exception e) { log.error("Exception occurred while waiting for webSocket connection", e); } if (!sourcesSucceeded) { log.error("Failed to connect to all sources."); if (!client.isOpen()) { log.error("Failed to connect to server url '" + targetVantiqServer + "'."); } else if (!client.isAuthed()) { log.error("Failed to authenticate within " + timeout + " seconds using the given authentication data."); } else { log.error("Failed to connect within 10 seconds"); } return false; } return true; } JDBCCore(String sourceName, String authToken, String targetVantiqServer); String getSourceName(); boolean start(int timeout); void executeQuery(ExtensionServiceMessage message); void executePublish(ExtensionServiceMessage message); void executePolling(String pollQuery); void sendDataFromQuery(HashMap[] queryArray, ExtensionServiceMessage message); void close(); void stop(); boolean exitIfConnectionFails(ExtensionWebSocketClient client, int timeout); public HashMap[] lastRowBundle; final Handler<ExtensionServiceMessage> reconnectHandler; final Handler<ExtensionWebSocketClient> closeHandler; }