@Test public void testFinishWithoutTimeout() throws Exception { DefaultEnvironmentEdge myClock = Mockito.mock(DefaultEnvironmentEdge.class); Mockito.when(myClock.currentTime()).thenReturn(0L); EnvironmentEdgeManager.injectEdge(myClock); try { Mockito.when(mockQuery.getTimeoutDuration()).thenReturn(1000L); Mockito.when(mockQuery.getExpectedAggregateRowCount()).thenReturn(1L); MultiThreadedRunner mtr = new MultiThreadedRunner("test", mockQuery, mockDMR, mockTT, 10L, 1000L, true, mockRA, mockScenario, mockWE, mockParser); Mockito.when(mockRS.next()).thenReturn(true, false); Mockito.when(mockRS.getLong(1)).thenReturn(1L); Pair<Long, Long> results = mtr.getResults(mockRS, "test_iteration", false, 0L); assertFalse(results.getSecond() > mockQuery.getTimeoutDuration()); } finally { EnvironmentEdgeManager.reset(); } }
@VisibleForTesting Pair<Long, Long> getResults(ResultSet rs, String queryIteration, boolean isSelectCountStatement, Long queryStartTime) throws Exception { Long resultRowCount = 0L; while (rs.next()) { if (null != query.getExpectedAggregateRowCount()) { if (rs.getLong(1) != query.getExpectedAggregateRowCount()) throw new RuntimeException( "Aggregate count " + rs.getLong(1) + " does not match expected " + query.getExpectedAggregateRowCount()); } if (isSelectCountStatement) { resultRowCount = rs.getLong(1); } else { resultRowCount++; } long queryElapsedTime = EnvironmentEdgeManager.currentTimeMillis() - queryStartTime; if (queryElapsedTime >= query.getTimeoutDuration()) { LOGGER.error("Query " + queryIteration + " exceeded timeout of " + query.getTimeoutDuration() + " ms at " + queryElapsedTime + " ms."); return new Pair(resultRowCount, queryElapsedTime); } } return new Pair(resultRowCount, EnvironmentEdgeManager.currentTimeMillis() - queryStartTime); }
MultiThreadedRunner implements Callable<Void> { @VisibleForTesting Pair<Long, Long> getResults(ResultSet rs, String queryIteration, boolean isSelectCountStatement, Long queryStartTime) throws Exception { Long resultRowCount = 0L; while (rs.next()) { if (null != query.getExpectedAggregateRowCount()) { if (rs.getLong(1) != query.getExpectedAggregateRowCount()) throw new RuntimeException( "Aggregate count " + rs.getLong(1) + " does not match expected " + query.getExpectedAggregateRowCount()); } if (isSelectCountStatement) { resultRowCount = rs.getLong(1); } else { resultRowCount++; } long queryElapsedTime = EnvironmentEdgeManager.currentTimeMillis() - queryStartTime; if (queryElapsedTime >= query.getTimeoutDuration()) { LOGGER.error("Query " + queryIteration + " exceeded timeout of " + query.getTimeoutDuration() + " ms at " + queryElapsedTime + " ms."); return new Pair(resultRowCount, queryElapsedTime); } } return new Pair(resultRowCount, EnvironmentEdgeManager.currentTimeMillis() - queryStartTime); } }
MultiThreadedRunner implements Callable<Void> { @VisibleForTesting Pair<Long, Long> getResults(ResultSet rs, String queryIteration, boolean isSelectCountStatement, Long queryStartTime) throws Exception { Long resultRowCount = 0L; while (rs.next()) { if (null != query.getExpectedAggregateRowCount()) { if (rs.getLong(1) != query.getExpectedAggregateRowCount()) throw new RuntimeException( "Aggregate count " + rs.getLong(1) + " does not match expected " + query.getExpectedAggregateRowCount()); } if (isSelectCountStatement) { resultRowCount = rs.getLong(1); } else { resultRowCount++; } long queryElapsedTime = EnvironmentEdgeManager.currentTimeMillis() - queryStartTime; if (queryElapsedTime >= query.getTimeoutDuration()) { LOGGER.error("Query " + queryIteration + " exceeded timeout of " + query.getTimeoutDuration() + " ms at " + queryElapsedTime + " ms."); return new Pair(resultRowCount, queryElapsedTime); } } return new Pair(resultRowCount, EnvironmentEdgeManager.currentTimeMillis() - queryStartTime); } MultiThreadedRunner(String threadName, Query query, DataModelResult dataModelResult,
            ThreadTime threadTime, long numberOfExecutions, long executionDurationInMs, boolean writeRuntimeResults, RulesApplier ruleApplier, Scenario scenario, WorkloadExecutor workloadExecutor, XMLConfigParser parser); }
MultiThreadedRunner implements Callable<Void> { @VisibleForTesting Pair<Long, Long> getResults(ResultSet rs, String queryIteration, boolean isSelectCountStatement, Long queryStartTime) throws Exception { Long resultRowCount = 0L; while (rs.next()) { if (null != query.getExpectedAggregateRowCount()) { if (rs.getLong(1) != query.getExpectedAggregateRowCount()) throw new RuntimeException( "Aggregate count " + rs.getLong(1) + " does not match expected " + query.getExpectedAggregateRowCount()); } if (isSelectCountStatement) { resultRowCount = rs.getLong(1); } else { resultRowCount++; } long queryElapsedTime = EnvironmentEdgeManager.currentTimeMillis() - queryStartTime; if (queryElapsedTime >= query.getTimeoutDuration()) { LOGGER.error("Query " + queryIteration + " exceeded timeout of " + query.getTimeoutDuration() + " ms at " + queryElapsedTime + " ms."); return new Pair(resultRowCount, queryElapsedTime); } } return new Pair(resultRowCount, EnvironmentEdgeManager.currentTimeMillis() - queryStartTime); } MultiThreadedRunner(String threadName, Query query, DataModelResult dataModelResult,
            ThreadTime threadTime, long numberOfExecutions, long executionDurationInMs, boolean writeRuntimeResults, RulesApplier ruleApplier, Scenario scenario, WorkloadExecutor workloadExecutor, XMLConfigParser parser); @Override Void call(); }
MultiThreadedRunner implements Callable<Void> { @VisibleForTesting Pair<Long, Long> getResults(ResultSet rs, String queryIteration, boolean isSelectCountStatement, Long queryStartTime) throws Exception { Long resultRowCount = 0L; while (rs.next()) { if (null != query.getExpectedAggregateRowCount()) { if (rs.getLong(1) != query.getExpectedAggregateRowCount()) throw new RuntimeException( "Aggregate count " + rs.getLong(1) + " does not match expected " + query.getExpectedAggregateRowCount()); } if (isSelectCountStatement) { resultRowCount = rs.getLong(1); } else { resultRowCount++; } long queryElapsedTime = EnvironmentEdgeManager.currentTimeMillis() - queryStartTime; if (queryElapsedTime >= query.getTimeoutDuration()) { LOGGER.error("Query " + queryIteration + " exceeded timeout of " + query.getTimeoutDuration() + " ms at " + queryElapsedTime + " ms."); return new Pair(resultRowCount, queryElapsedTime); } } return new Pair(resultRowCount, EnvironmentEdgeManager.currentTimeMillis() - queryStartTime); } MultiThreadedRunner(String threadName, Query query, DataModelResult dataModelResult,
            ThreadTime threadTime, long numberOfExecutions, long executionDurationInMs, boolean writeRuntimeResults, RulesApplier ruleApplier, Scenario scenario, WorkloadExecutor workloadExecutor, XMLConfigParser parser); @Override Void call();  }