use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class BaseHiveExploreServiceTest method createNamespace.
/**
* Create a namespace because app fabric is not started in explore tests.
*/
protected static void createNamespace(NamespaceId namespaceId) throws Exception {
namespacePathLocator.get(namespaceId).mkdirs();
NamespaceMeta namespaceMeta = new NamespaceMeta.Builder().setName(namespaceId).build();
namespaceAdmin.create(namespaceMeta);
if (!NamespaceId.DEFAULT.equals(namespaceId)) {
QueryHandle handle = exploreService.createNamespace(namespaceMeta);
waitForCompletionStatus(handle, 50, TimeUnit.MILLISECONDS, 40);
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class HiveExploreServiceTestRun method previewResultsTest.
@Test
public void previewResultsTest() throws Exception {
DatasetId myTable2 = NAMESPACE_ID.dataset("my_table_2");
DatasetId myTable3 = NAMESPACE_ID.dataset("my_table_3");
DatasetId myTable4 = NAMESPACE_ID.dataset("my_table_4");
DatasetId myTable5 = NAMESPACE_ID.dataset("my_table_5");
DatasetId myTable6 = NAMESPACE_ID.dataset("my_table_6");
datasetFramework.addInstance("keyStructValueTable", myTable2, DatasetProperties.EMPTY);
datasetFramework.addInstance("keyStructValueTable", myTable3, DatasetProperties.EMPTY);
datasetFramework.addInstance("keyStructValueTable", myTable4, DatasetProperties.EMPTY);
datasetFramework.addInstance("keyStructValueTable", myTable5, DatasetProperties.EMPTY);
datasetFramework.addInstance("keyStructValueTable", myTable6, DatasetProperties.EMPTY);
try {
QueryHandle handle = exploreService.execute(NAMESPACE_ID, "show tables");
QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 50);
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
List<QueryResult> firstPreview = exploreService.previewResults(handle);
Assert.assertEquals(ImmutableList.of(new QueryResult(ImmutableList.<Object>of(MY_TABLE_NAME)), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable2))), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable3))), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable4))), new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable5)))), firstPreview);
// test that preview results do not change even when the query cursor is updated by nextResults
List<QueryResult> endResults = exploreService.nextResults(handle, 100);
Assert.assertEquals(ImmutableList.of(new QueryResult(ImmutableList.<Object>of(getDatasetHiveName(myTable6)))), endResults);
List<QueryResult> secondPreview = exploreService.previewResults(handle);
Assert.assertEquals(firstPreview, secondPreview);
Assert.assertEquals(ImmutableList.<QueryResult>of(), exploreService.nextResults(handle, 100));
try {
// All results are fetched, query should be inactive now
exploreService.previewResults(handle);
Assert.fail("HandleNotFoundException expected - query should be inactive.");
} catch (HandleNotFoundException e) {
Assert.assertTrue(e.isInactive());
// Expected exception
}
// now test preview on a query that doesn't return any results
handle = exploreService.execute(NAMESPACE_ID, "select * from " + getDatasetHiveName(myTable2));
status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 50);
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
Assert.assertTrue(exploreService.previewResults(handle).isEmpty());
// calling preview again should return the same thing. it should not throw an exception
Assert.assertTrue(exploreService.previewResults(handle).isEmpty());
} finally {
datasetFramework.deleteInstance(myTable2);
datasetFramework.deleteInstance(myTable3);
datasetFramework.deleteInstance(myTable4);
datasetFramework.deleteInstance(myTable5);
datasetFramework.deleteInstance(myTable6);
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class HiveExploreServiceTimeoutTest method testCloseQuery.
@Test
public void testCloseQuery() throws Exception {
QueryHandle handle = exploreService.execute(NAMESPACE_ID, "drop table if exists not_existing_table_name");
exploreService.close(handle);
try {
exploreService.getStatus(handle);
Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
} catch (HandleNotFoundException e) {
// Expected exception due to timeout
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class HiveExploreServiceTimeoutTest method testTimeoutNoResults.
@Test
public void testTimeoutNoResults() throws Exception {
Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
QueryHandle handle = exploreService.execute(NAMESPACE_ID, "drop table if exists not_existing_table_name");
Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
Assert.assertFalse(queryTxns.isEmpty());
QueryStatus status = waitForCompletionStatus(handle, 200, TimeUnit.MILLISECONDS, 20);
Assert.assertEquals(QueryStatus.OpStatus.FINISHED, status.getStatus());
Assert.assertFalse(status.hasResults());
List<ColumnDesc> schema = exploreService.getResultSchema(handle);
// Sleep for some time for txn to get closed
TimeUnit.SECONDS.sleep(1);
// Make sure that the transaction got closed
Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
// Check if calls using inactive handle still work
Assert.assertEquals(status, exploreService.getStatus(handle));
Assert.assertEquals(schema, exploreService.getResultSchema(handle));
exploreService.close(handle);
// Sleep for timeout to happen
TimeUnit.SECONDS.sleep(INACTIVE_OPERATION_TIMEOUT_SECS + 3);
try {
exploreService.getStatus(handle);
Assert.fail("Should throw HandleNotFoundException due to operation cleanup");
} catch (HandleNotFoundException e) {
// Expected exception due to timeout
}
}
use of io.cdap.cdap.proto.QueryHandle in project cdap by cdapio.
the class HiveExploreServiceTimeoutTest method testTimeoutRunning.
@Test
public void testTimeoutRunning() throws Exception {
Set<Long> beforeTxns = transactionManager.getCurrentState().getInProgress().keySet();
QueryHandle handle = exploreService.execute(NAMESPACE_ID, "select key, value from " + MY_TABLE_NAME);
Set<Long> queryTxns = Sets.difference(transactionManager.getCurrentState().getInProgress().keySet(), beforeTxns);
Assert.assertFalse(queryTxns.isEmpty());
// Sleep for timeout to happen
TimeUnit.SECONDS.sleep(ACTIVE_OPERATION_TIMEOUT_SECS + 3);
try {
exploreService.getStatus(handle);
Assert.fail("Should throw HandleNotFoundException due to operation timeout");
} catch (HandleNotFoundException e) {
// Expected exception due to timeout
}
// Make sure that the transaction got closed
Assert.assertEquals(ImmutableSet.<Long>of(), Sets.intersection(queryTxns, transactionManager.getCurrentState().getInProgress().keySet()).immutableCopy());
}
Aggregations