use of org.apache.drill.exec.ops.QueryContext in project drill by apache.
the class TestExceptionInjection method checkedInjection.
@SuppressWarnings("static-method")
@Test
public void checkedInjection() {
// set the injection via the parsing POJOs
final String controls = Controls.newBuilder().addException(DummyClass.class, DummyClass.THROWS_IOEXCEPTION, IOException.class, 0, 1).build();
ControlsInjectionUtil.setControls(session, controls);
final QueryContext context = new QueryContext(session, bits[0].getContext(), QueryId.getDefaultInstance());
// test that the expected exception (checked) gets thrown
final DummyClass dummyClass = new DummyClass(context);
try {
dummyClass.throwsIOException();
fail(NO_THROW_FAIL);
} catch (IOException e) {
assertEquals(DummyClass.THROWS_IOEXCEPTION, e.getMessage());
}
try {
context.close();
} catch (Exception e) {
fail();
}
}
use of org.apache.drill.exec.ops.QueryContext in project drill by apache.
the class TestCountDownLatchInjection method latchInjected.
// test would hang if the correct init, wait and countdowns did not happen, and the test timeout mechanism will
@Test
public // catch that case
void latchInjected() {
final int threads = 10;
final ExtendedLatch trigger = new ExtendedLatch(1);
final Pointer<Long> countingDownTime = new Pointer<>();
final String controls = Controls.newBuilder().addLatch(DummyClass.class, DummyClass.LATCH_NAME).build();
ControlsInjectionUtil.setControls(session, controls);
final QueryContext queryContext = new QueryContext(session, bits[0].getContext(), QueryId.getDefaultInstance());
final DummyClass dummyClass = new DummyClass(queryContext, trigger, threads);
(new ThreadCreator(dummyClass, trigger, threads, countingDownTime)).start();
final long timeSpentWaiting;
try {
timeSpentWaiting = dummyClass.initAndWait();
} catch (final InterruptedException e) {
fail("Thread should not be interrupted; there is no deliberate attempt.");
return;
}
assertTrue(timeSpentWaiting >= countingDownTime.value);
try {
queryContext.close();
} catch (final Exception e) {
fail("Failed to close query context: " + e);
}
}
use of org.apache.drill.exec.ops.QueryContext in project drill by apache.
the class PlanSplitter method planFragments.
/**
* Method to plan the query and return list of fragments
* it will return query plan "as is" or split plans based on the req setting: split_plan
* @param dContext
* @param queryId
* @param req
* @param connection
* @return
*/
public QueryPlanFragments planFragments(DrillbitContext dContext, QueryId queryId, GetQueryPlanFragments req, UserClientConnection connection) {
QueryPlanFragments.Builder responseBuilder = QueryPlanFragments.newBuilder();
QueryContext queryContext = new QueryContext(connection.getSession(), dContext, queryId);
responseBuilder.setQueryId(queryId);
try {
responseBuilder.addAllFragments(getFragments(dContext, req, queryContext, queryId));
responseBuilder.setStatus(QueryState.COMPLETED);
} catch (Exception e) {
final String errorMessage = String.format("Failed to produce PlanFragments for query id \"%s\" with " + "request to %s plan", queryId, (req.getSplitPlan() ? "split" : "no split"));
DrillPBError error = DrillPBError.newBuilder().setMessage(errorMessage).setErrorType(DrillPBError.ErrorType.PLAN).build();
responseBuilder.setStatus(QueryState.FAILED);
responseBuilder.setError(error);
}
return responseBuilder.build();
}
use of org.apache.drill.exec.ops.QueryContext in project drill by apache.
the class TestOptiqPlans method doLogicalTest.
private SimpleRootExec doLogicalTest(final BootStrapContext context, UserClientConnection connection, String file, ClusterCoordinator coord, DataConnectionCreator com, Controller controller, WorkEventBus workBus) throws Exception {
new NonStrictExpectations() {
{
context.getMetrics();
result = new MetricRegistry();
context.getAllocator();
result = RootAllocatorFactory.newRoot(config);
context.getConfig();
result = config;
}
};
final RemoteServiceSet lss = RemoteServiceSet.getLocalServiceSet();
final DrillbitContext bitContext = new DrillbitContext(DrillbitEndpoint.getDefaultInstance(), context, coord, controller, com, workBus, new LocalPersistentStoreProvider(config));
final QueryContext qc = new QueryContext(UserSession.Builder.newBuilder().setSupportComplexTypes(true).build(), bitContext, QueryId.getDefaultInstance());
final PhysicalPlanReader reader = bitContext.getPlanReader();
final LogicalPlan plan = reader.readLogicalPlan(Files.toString(FileUtils.getResourceAsFile(file), Charsets.UTF_8));
final PhysicalPlan pp = new BasicOptimizer(qc, connection).optimize(new BasicOptimizer.BasicOptimizationContext(qc), plan);
final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(config);
final FragmentContext fctxt = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(fctxt, (FragmentRoot) pp.getSortedOperators(false).iterator().next()));
return exec;
}
use of org.apache.drill.exec.ops.QueryContext in project drill by apache.
the class TestExceptionInjection method uncheckedInjection.
@SuppressWarnings("static-method")
@Test
public void uncheckedInjection() {
// set exceptions via a string
final String exceptionDesc = "<<injected from descPassthroughMethod()>>";
final String exceptionClassName = "java.lang.RuntimeException";
final String jsonString = "{\"injections\":[{" + "\"type\":\"exception\"," + "\"siteClass\":\"org.apache.drill.exec.testing.TestExceptionInjection$DummyClass\"," + "\"desc\":\"" + exceptionDesc + "\"," + "\"nSkip\":0," + "\"nFire\":1," + "\"exceptionClass\":\"" + exceptionClassName + "\"" + "}]}";
ControlsInjectionUtil.setControls(session, jsonString);
final QueryContext context = new QueryContext(session, bits[0].getContext(), QueryId.getDefaultInstance());
// test that the exception gets thrown
final DummyClass dummyClass = new DummyClass(context);
assertPassthroughThrows(dummyClass, exceptionClassName, exceptionDesc);
try {
context.close();
} catch (Exception e) {
fail();
}
}
Aggregations