@Test public void testGroupByQuery() throws Exception { Table table = dataContext.getDefaultSchema().getTableByName(peopleIndexType); Query q = new Query(); q.from(table); q.groupBy(table.getColumnByName("gender")); q.select( new SelectItem(table.getColumnByName("gender")), new SelectItem(FunctionType.MAX, table.getColumnByName("age")), new SelectItem(FunctionType.MIN, table.getColumnByName("age")), new SelectItem(FunctionType.COUNT, "*", "total"), new SelectItem(FunctionType.MIN, table.getColumnByName("id")).setAlias("firstId")); q.orderBy("gender"); DataSet data = dataContext.executeQuery(q); assertEquals( "[peopletype.gender, MAX(peopletype.age), MIN(peopletype.age), COUNT(*) AS total, MIN(peopletype.id) AS firstId]", Arrays.toString(data.getSelectItems())); assertTrue(data.next()); assertEquals("Row[values=[female, 20, 17, 5, 5]]", data.getRow().toString()); assertTrue(data.next()); assertEquals("Row[values=[male, 19, 17, 4, 1]]", data.getRow().toString()); assertFalse(data.next()); }
public void testSplitJoinQuery() throws Exception { Connection con = getTestDbConnection(); DataContext dc = new JdbcDataContext(con); Schema schema = dc.getDefaultSchema(); Table productsTable = schema.getTableByName("PRODUCTS"); Relationship[] relationships = productsTable.getRelationships(); Relationship relationship = relationships[0]; assertEquals( "Relationship[primaryTable=PRODUCTS,primaryColumns=[PRODUCTCODE],foreignTable=ORDERFACT,foreignColumns=[PRODUCTCODE]]", relationship.toString()); Query q = new Query() .from(new FromItem(JoinType.LEFT, relationship)) .select(relationship.getForeignColumns()) .select(relationship.getPrimaryColumns()); assertEquals( "SELECT _ORDERFACT_._PRODUCTCODE_, _PRODUCTS_._PRODUCTCODE_ FROM PUBLIC._PRODUCTS_ LEFT JOIN PUBLIC._ORDERFACT_ ON _PRODUCTS_._PRODUCTCODE_ = _ORDERFACT_._PRODUCTCODE_", q.toString().replace('\"', '_')); QuerySplitter qs = new QuerySplitter(dc, q); assertEquals(2997, qs.getRowCount()); List<Query> splitQueries = qs.setMaxRows(1500).splitQuery(); assertSameCount(dc, qs, splitQueries); assertEquals(3, splitQueries.size()); assertEquals("[1415, 902, 680]", Arrays.toString(getCounts(dc, splitQueries))); }
@Test public void testMaxRows() throws Exception { Table table = dataContext.getDefaultSchema().getTableByName(peopleIndexType); Query query = new Query().from(table).select(table.getColumns()).setMaxRows(5); DataSet dataSet = dataContext.executeQuery(query); TableModel tableModel = new DataSetTableModel(dataSet); assertEquals(5, tableModel.getRowCount()); }
@Test public void testDocumentIdAsPrimaryKey() throws Exception { Table table = dataContext.getDefaultSchema().getTableByName("tweet2"); Column[] pks = table.getPrimaryKeys(); assertEquals(1, pks.length); assertEquals("_id", pks[0].getName()); try (DataSet ds = dataContext.query().from(table).select("user", "_id").orderBy("_id").asc().execute()) { assertTrue(ds.next()); assertEquals("Row[values=[user1, tweet_tweet2_1]]", ds.getRow().toString()); } }
public void testSplitSubQuery() throws Exception { Connection con = getTestDbConnection(); DataContext dc = new JdbcDataContext(con); Schema schema = dc.getDefaultSchema(); Table employeesTable = schema.getTableByName("EMPLOYEES"); Table customersTable = schema.getTableByName("CUSTOMERS"); Query sq = new Query().from(employeesTable, "e").from(customersTable, "c"); SelectItem empSelectItem = new SelectItem(employeesTable.getColumns()[0]); SelectItem custSelectItem = new SelectItem(customersTable.getColumns()[0]); sq.select(empSelectItem, custSelectItem); assertEquals( "SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c", sq.toString().replace('\"', '_')); Query q = new Query(); FromItem sqItem = new FromItem(sq).setAlias("sq"); custSelectItem.setAlias("c_num"); empSelectItem.setAlias("e_num"); q.from(sqItem); q.select(new SelectItem(custSelectItem, sqItem), new SelectItem(empSelectItem, sqItem)); assertEquals( "SELECT sq.c_num, sq.e_num FROM (SELECT e._EMPLOYEENUMBER_ AS e_num, c._CUSTOMERNUMBER_ AS c_num FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c) sq", q.toString().replace('\"', '_')); QuerySplitter qs = new QuerySplitter(dc, q); assertEquals(2806, qs.getRowCount()); List<Query> splitQueries = qs.setMaxRows(1000).splitQuery(); assertSameCount(dc, qs, splitQueries); assertEquals(5, splitQueries.size()); assertEquals("[793, 610, 366, 714, 323]", Arrays.toString(getCounts(dc, splitQueries))); splitQueries = qs.setMaxRows(2000).splitQuery(); assertSameCount(dc, qs, splitQueries); assertEquals(2, splitQueries.size()); assertEquals("[1403, 1403]", Arrays.toString(getCounts(dc, splitQueries))); DataSet data = qs.executeQueries(); int count = 0; while (data.next()) { if (count == 2) { assertEquals("Row[values=[114, 1002]]", data.getRow().toString()); } count++; } data.close(); assertEquals(2806, count); }
@Test public void testNumberIsHandledAsNumber() throws Exception { Table table = dataContext.getDefaultSchema().getTableByName(peopleIndexType); Column column = table.getColumnByName("age"); ColumnType type = column.getType(); assertEquals(ColumnType.BIGINT, type); DataSet dataSet = dataContext.query().from(table).select(column).execute(); while (dataSet.next()) { Object value = dataSet.getRow().getValue(column); assertTrue( "Got class: " + value.getClass() + ", expected Number (or subclass)", value instanceof Number); } }
@Test public void testDateIsHandledAsDate() throws Exception { Table table = dataContext.getDefaultSchema().getTableByName("tweet1"); Column column = table.getColumnByName("postDate"); ColumnType type = column.getType(); assertEquals(ColumnType.DATE, type); DataSet dataSet = dataContext.query().from(table).select(column).execute(); while (dataSet.next()) { Object value = dataSet.getRow().getValue(column); assertTrue( "Got class: " + value.getClass() + ", expected Date (or subclass)", value instanceof Date); } }
@Override protected Number executeCountQuery( Table table, List<FilterItem> whereItems, boolean functionApproximationAllowed) { final String query; try { final StringBuilder sb = new StringBuilder(); sb.append("SELECT COUNT() FROM "); sb.append(table.getName()); boolean firstWhere = true; for (FilterItem filterItem : whereItems) { if (firstWhere) { sb.append(" WHERE "); firstWhere = false; } else { sb.append(" AND "); } rewriteFilterItem(sb, filterItem); } query = sb.toString(); } catch (UnsupportedOperationException e) { logger.debug("Failed to rewrite count query, falling back to client side counting", e); // unable to rewrite to SOQL, counting will be done client side. return null; } final QueryResult queryResult = executeSoqlQuery(query); assert queryResult.isDone(); return queryResult.getSize(); }
@Test public void testCreateTableInsertQueryAndDrop() throws Exception { final Schema schema = dataContext.getDefaultSchema(); final CreateTable createTable = new CreateTable(schema, "testCreateTable"); createTable.withColumn("foo").ofType(ColumnType.STRING); createTable.withColumn("bar").ofType(ColumnType.NUMBER); dataContext.executeUpdate(createTable); final Table table = schema.getTableByName("testCreateTable"); assertEquals( "[" + ElasticSearchDataContext.FIELD_ID + ", foo, bar]", Arrays.toString(table.getColumnNames())); final Column fooColumn = table.getColumnByName("foo"); final Column idColumn = table.getPrimaryKeys()[0]; assertEquals( "Column[name=_id,columnNumber=0,type=STRING,nullable=null,nativeType=null,columnSize=null]", idColumn.toString()); dataContext.executeUpdate( new UpdateScript() { @Override public void run(UpdateCallback callback) { callback.insertInto(table).value("foo", "hello").value("bar", 42).execute(); callback.insertInto(table).value("foo", "world").value("bar", 43).execute(); } }); dataContext.refreshSchemas(); try (DataSet ds = dataContext.query().from(table).selectAll().orderBy("bar").execute()) { assertTrue(ds.next()); assertEquals("hello", ds.getRow().getValue(fooColumn).toString()); assertNotNull(ds.getRow().getValue(idColumn)); assertTrue(ds.next()); assertEquals("world", ds.getRow().getValue(fooColumn).toString()); assertNotNull(ds.getRow().getValue(idColumn)); assertFalse(ds.next()); } dataContext.executeUpdate(new DropTable(table)); dataContext.refreshSchemas(); assertNull(dataContext.getTableByQualifiedLabel(table.getName())); }
@Test public void testExecutePrimaryKeyLookupQuery() throws Exception { Table table = dataContext.getDefaultSchema().getTableByName("tweet2"); Column[] pks = table.getPrimaryKeys(); try (DataSet ds = dataContext.query().from(table).selectAll().where(pks[0]).eq("tweet_tweet2_1").execute()) { assertTrue(ds.next()); Object dateValue = ds.getRow().getValue(2); assertEquals( "Row[values=[tweet_tweet2_1, 1, " + dateValue + ", user1]]", ds.getRow().toString()); assertFalse(ds.next()); assertEquals(InMemoryDataSet.class, ds.getClass()); } }
@Test public void testSimpleQuery() throws Exception { assertEquals( "[bulktype, peopletype, tweet1, tweet2]", Arrays.toString(dataContext.getDefaultSchema().getTableNames())); Table table = dataContext.getDefaultSchema().getTableByName("tweet1"); assertEquals("[_id, message, postDate, user]", Arrays.toString(table.getColumnNames())); assertEquals(ColumnType.STRING, table.getColumnByName("user").getType()); assertEquals(ColumnType.DATE, table.getColumnByName("postDate").getType()); assertEquals(ColumnType.BIGINT, table.getColumnByName("message").getType()); try (DataSet ds = dataContext.query().from(indexType1).select("user").and("message").execute()) { assertEquals(ElasticSearchDataSet.class, ds.getClass()); assertTrue(ds.next()); assertEquals("Row[values=[user1, 1]]", ds.getRow().toString()); } }
public void testGroupByQuery() throws Exception { Connection con = getTestDbConnection(); DataContext dc = new JdbcDataContext(con); Schema schema = dc.getDefaultSchema(); Table employeesTable = schema.getTableByName("EMPLOYEES"); Table orderDetailsTable = schema.getTableByName("ORDERDETAILS"); Query q = new Query().from(employeesTable, "e").from(orderDetailsTable, "c"); q.select(orderDetailsTable.getColumns()[0]) .select(new SelectItem(FunctionType.MAX, employeesTable.getColumns()[0])); q.groupBy(orderDetailsTable.getColumns()[0]); assertEquals( "SELECT c._ORDERNUMBER_, MAX(e._EMPLOYEENUMBER_) FROM PUBLIC._EMPLOYEES_ e, PUBLIC._ORDERDETAILS_ c GROUP BY c._ORDERNUMBER_", q.toString().replace('\"', '_')); QuerySplitter qs = new QuerySplitter(dc, q); assertEquals(326, qs.getRowCount()); List<Query> splitQueries = qs.setMaxRows(250).splitQuery(); assertEquals( "[SELECT c._ORDERNUMBER_, MAX(e._EMPLOYEENUMBER_) FROM PUBLIC._EMPLOYEES_ e, PUBLIC._ORDERDETAILS_ c WHERE (c._ORDERNUMBER_ < 10262 OR c._ORDERNUMBER_ IS NULL) GROUP BY c._ORDERNUMBER_, SELECT c._ORDERNUMBER_, MAX(e._EMPLOYEENUMBER_) FROM PUBLIC._EMPLOYEES_ e, PUBLIC._ORDERDETAILS_ c WHERE (c._ORDERNUMBER_ > 10262 OR c._ORDERNUMBER_ = 10262) GROUP BY c._ORDERNUMBER_]", Arrays.toString(splitQueries.toArray()).replace('\"', '_')); assertSameCount(dc, qs, splitQueries); assertEquals(2, splitQueries.size()); assertEquals("[162, 164]", Arrays.toString(getCounts(dc, splitQueries))); DataSet data = qs.executeQueries(); int count = 0; while (data.next()) { if (count == 2) { assertEquals("Row[values=[10102, 1702]]", data.getRow().toString()); } count++; } data.close(); assertEquals(326, count); }
public void testSimpleQuerySplit() throws Exception { Connection con = getTestDbConnection(); DataContext dc = new JdbcDataContext(con); Schema schema = dc.getSchemaByName("PUBLIC"); Table employeesTable = schema.getTableByName("EMPLOYEES"); Table customersTable = schema.getTableByName("CUSTOMERS"); Query q = new Query().from(employeesTable, "e").from(customersTable, "c"); q.select(employeesTable.getColumns()[0], customersTable.getColumns()[0]); assertEquals( "SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c", q.toString().replace('\"', '_')); QuerySplitter qs = new QuerySplitter(dc, q); long rowCount = qs.getRowCount(); assertEquals(2806, rowCount); qs.setMaxRows(1000); List<Query> splitQueries = qs.splitQuery(); assertEquals("[793, 610, 366, 714, 323]", Arrays.toString(getCounts(dc, splitQueries))); assertEquals( "[SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ < 299 OR c._CUSTOMERNUMBER_ IS NULL) AND (e._EMPLOYEENUMBER_ < 1352 OR e._EMPLOYEENUMBER_ IS NULL), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ < 299 OR c._CUSTOMERNUMBER_ IS NULL) AND (e._EMPLOYEENUMBER_ > 1352 OR e._EMPLOYEENUMBER_ = 1352), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ > 299 OR c._CUSTOMERNUMBER_ = 299) AND (e._REPORTSTO_ < 1072 OR e._REPORTSTO_ IS NULL), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ > 299 OR c._CUSTOMERNUMBER_ = 299) AND (e._REPORTSTO_ > 1072 OR e._REPORTSTO_ = 1072) AND (c._SALESREPEMPLOYEENUMBER_ < 1433 OR c._SALESREPEMPLOYEENUMBER_ IS NULL), SELECT e._EMPLOYEENUMBER_, c._CUSTOMERNUMBER_ FROM PUBLIC._EMPLOYEES_ e, PUBLIC._CUSTOMERS_ c WHERE (c._CUSTOMERNUMBER_ > 299 OR c._CUSTOMERNUMBER_ = 299) AND (e._REPORTSTO_ > 1072 OR e._REPORTSTO_ = 1072) AND (c._SALESREPEMPLOYEENUMBER_ > 1433 OR c._SALESREPEMPLOYEENUMBER_ = 1433)]", Arrays.toString(splitQueries.toArray()).replace('\"', '_')); assertSameCount(dc, qs, splitQueries); assertEquals(5, splitQueries.size()); splitQueries = qs.setMaxRows(300).splitQuery(); assertSameCount(dc, qs, splitQueries); assertEquals( "[299, 221, 170, 299, 276, 253, 102, 289, 253, 138, 368, 138]", Arrays.toString(getCounts(dc, splitQueries))); splitQueries = qs.setMaxRows(5000).splitQuery(); assertEquals(1, splitQueries.size()); assertSame(q, splitQueries.get(0)); }
@Override protected DataSet materializeMainSchemaTable(Table table, Column[] columns, int maxRows) { final StringBuilder sb = new StringBuilder(); sb.append("SELECT "); for (int i = 0; i < columns.length; i++) { if (i != 0) { sb.append(','); } sb.append(columns[i].getName()); } sb.append(" FROM "); sb.append(table.getName()); if (maxRows > 0) { sb.append(" LIMIT " + maxRows); } final QueryResult queryResult = executeSoqlQuery(sb.toString()); return new SalesforceDataSet(columns, queryResult, _connection); }
public void testProductTable() throws Exception { Schema schema = dc.getDefaultSchema(); assertEquals("developers.mdb", schema.getName()); Table table = schema.getTableByName("product"); assertEquals("[id, name, version, founder_developer]", Arrays.toString(table.getColumnNames())); Column idCol = table.getColumnByName("id"); assertEquals( "Column[name=id,columnNumber=0,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]", idCol.toString()); Column nameCol = table.getColumnByName("name"); assertEquals( "Column[name=name,columnNumber=1,type=VARCHAR,nullable=null,nativeType=TEXT,columnSize=100]", nameCol.toString()); Column versionCol = table.getColumnByName("version"); assertEquals( "Column[name=version,columnNumber=2,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]", versionCol.toString()); Column founderCol = table.getColumnByName("founder_developer"); assertEquals( "Column[name=founder_developer,columnNumber=3,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]", founderCol.toString()); DataSet ds; ds = dc.executeQuery(new Query().select(nameCol, versionCol, founderCol).from(table)); assertTrue(ds.next()); assertEquals("Anthons Algorithms", ds.getRow().getValue(nameCol).toString()); assertEquals(11, ds.getRow().getValue(versionCol)); assertEquals(1, ds.getRow().getValue(founderCol)); assertTrue(ds.next()); assertEquals("Barbaras Basic Bundle", ds.getRow().getValue(nameCol).toString()); assertEquals(2, ds.getRow().getValue(versionCol)); assertEquals(2, ds.getRow().getValue(founderCol)); assertFalse(ds.next()); ds.close(); ds = dc.query().from(table).selectCount().execute(); assertTrue(ds.next()); assertEquals("Row[values=[2]]", ds.getRow().toString()); assertFalse(ds.next()); ds.close(); }
public void testDeveloperTable() throws Exception { Schema schema = dc.getDefaultSchema(); assertEquals("developers.mdb", schema.getName()); assertEquals("[developer, product]", Arrays.toString(schema.getTableNames())); Table table = schema.getTableByName("developer"); assertEquals( "[id, name, email, male, developer_since]", Arrays.toString(table.getColumnNames())); Column[] primaryKeys = table.getPrimaryKeys(); assertEquals( "[Column[name=id,columnNumber=0,type=INTEGER,nullable=null,nativeType=LONG,columnSize=4]]", Arrays.toString(primaryKeys)); Column nameCol = table.getColumnByName("name"); assertEquals( "Column[name=name,columnNumber=1,type=VARCHAR,nullable=null,nativeType=TEXT,columnSize=100]", nameCol.toString()); Column maleCol = table.getColumnByName("male"); assertEquals( "Column[name=male,columnNumber=3,type=BOOLEAN,nullable=null,nativeType=BOOLEAN,columnSize=1]", maleCol.toString()); Column developerSinceCol = table.getColumnByName("developer_since"); assertEquals( "Column[name=developer_since,columnNumber=4,type=TIMESTAMP,nullable=null,nativeType=SHORT_DATE_TIME,columnSize=8]", developerSinceCol.toString()); DataSet ds = dc.executeQuery(new Query().select(nameCol, maleCol, developerSinceCol).from(table)); while (ds.next()) { Row row = ds.getRow(); assertEquals(3, row.getValues().length); Object value = row.getValue(0); assertEquals(String.class, value.getClass()); value = row.getValue(1); assertEquals(Boolean.class, value.getClass()); value = row.getValue(2); assertTrue(value instanceof Date); } }
@Override public DataSet executeQuery(Query query) { final List<FromItem> fromItems = query.getFromClause().getItems(); if (fromItems.size() != 1) { // not a simple SELECT ... FROM [table] ... query, we need to use // query post processing. return super.executeQuery(query); } final Table table = fromItems.get(0).getTable(); if (table == null) { return super.executeQuery(query); } if (!query.getGroupByClause().isEmpty()) { return super.executeQuery(query); } if (!query.getHavingClause().isEmpty()) { return super.executeQuery(query); } final List<SelectItem> selectItems = query.getSelectClause().getItems(); final StringBuilder sb = new StringBuilder(); try { sb.append("SELECT "); int i = 0; final Column[] columns = new Column[selectItems.size()]; for (SelectItem selectItem : selectItems) { validateSoqlSupportedSelectItem(selectItem); columns[i] = selectItem.getColumn(); if (i != 0) { sb.append(", "); } sb.append(columns[i].getName()); i++; } sb.append(" FROM "); sb.append(table.getName()); boolean firstWhere = true; for (FilterItem filterItem : query.getWhereClause().getItems()) { if (firstWhere) { sb.append(" WHERE "); firstWhere = false; } else { sb.append(" AND "); } rewriteFilterItem(sb, filterItem); } i = 0; final List<OrderByItem> items = query.getOrderByClause().getItems(); for (OrderByItem orderByItem : items) { if (i == 0) { sb.append(" ORDER BY "); } else { sb.append(", "); } final SelectItem selectItem = orderByItem.getSelectItem(); validateSoqlSupportedSelectItem(selectItem); final Column column = selectItem.getColumn(); sb.append(column.getName()); sb.append(' '); sb.append(orderByItem.getDirection()); i++; } final Integer firstRow = query.getFirstRow(); final Integer maxRows = query.getMaxRows(); if (maxRows != null && maxRows > 0) { if (firstRow != null) { // add first row / offset to avoid missing some records. sb.append(" LIMIT " + (maxRows + firstRow - 1)); } else { sb.append(" LIMIT " + maxRows); } } final QueryResult result = executeSoqlQuery(sb.toString()); DataSet dataSet = new SalesforceDataSet(columns, result, _connection); if (firstRow != null) { // OFFSET is still only a developer preview feature of SFDC. See // http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_calls_soql_select_offset.htm dataSet = new FirstRowDataSet(dataSet, firstRow.intValue()); } return dataSet; } catch (UnsupportedOperationException e) { logger.debug( "Failed to rewrite query to SOQL, falling back to regular query post-processing", e); return super.executeQuery(query); } }
public void runScenario() { MultiThreadedTaskRunner taskRunner = TestEnvironment.getMultiThreadedTaskRunner(); ThreadPoolExecutor executorService = (ThreadPoolExecutor) taskRunner.getExecutorService(); assertEquals(TestEnvironment.THREAD_COUNT, executorService.getMaximumPoolSize()); assertEquals(0, executorService.getActiveCount()); DataCleanerConfiguration configuration = new DataCleanerConfigurationImpl() .withEnvironment(new DataCleanerEnvironmentImpl().withTaskRunner(taskRunner)); AnalysisRunner runner = new AnalysisRunnerImpl(configuration); Datastore ds = TestHelper.createSampleDatabaseDatastore("foobar"); try (DatastoreConnection con = ds.openConnection()) { AnalysisJob job; try (AnalysisJobBuilder analysisJobBuilder = new AnalysisJobBuilder(configuration)) { analysisJobBuilder.setDatastore(ds); Table table = con.getDataContext().getDefaultSchema().getTableByName("ORDERFACT"); assertNotNull(table); Column statusColumn = table.getColumnByName("STATUS"); Column commentsColumn = table.getColumnByName("COMMENTS"); analysisJobBuilder.addSourceColumns(statusColumn, commentsColumn); analysisJobBuilder .addAnalyzer(AnalyzerMock.class) .addInputColumns(analysisJobBuilder.getSourceColumns()); job = analysisJobBuilder.toAnalysisJob(); } AnalysisResultFuture resultFuture = runner.run(job); try { Thread.sleep(550); } catch (InterruptedException e) { e.printStackTrace(); fail("Interrupted! " + e.getMessage()); } resultFuture.cancel(); assertFalse(resultFuture.isSuccessful()); assertTrue(resultFuture.isCancelled()); assertTrue(resultFuture.isErrornous()); try { Thread.sleep(400); } catch (InterruptedException e) { e.printStackTrace(); fail("Interrupted! " + e.getMessage()); } assertEquals(TestEnvironment.THREAD_COUNT, executorService.getMaximumPoolSize()); long completedTaskCount = executorService.getCompletedTaskCount(); assertTrue("completedTaskCount was: " + completedTaskCount, completedTaskCount > 3); int largestPoolSize = executorService.getLargestPoolSize(); assertTrue("largestPoolSize was: " + largestPoolSize, largestPoolSize > 5); assertEquals(0, executorService.getActiveCount()); } taskRunner.shutdown(); }