diff options
author | Paul Rogers <progers@cloudera.com> | 2018-04-17 17:43:02 -0700 |
---|---|---|
committer | Vitalii Diravka <vitalii.diravka@gmail.com> | 2018-04-29 23:20:55 +0300 |
commit | 883c8d94b0021a83059fa79563dd516c4299b70a (patch) | |
tree | 11504186c50b06de38923afb6b4dc99b702d8132 /docs/dev/OperatorFixture.md | |
parent | f8d7acc8274da20a7cd0c44aafdf3f84cc4927aa (diff) |
DRILL-6328: Adding unit testing docs.
closes #1220
Diffstat (limited to 'docs/dev/OperatorFixture.md')
-rw-r--r-- | docs/dev/OperatorFixture.md | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/docs/dev/OperatorFixture.md b/docs/dev/OperatorFixture.md new file mode 100644 index 000000000..76e19e3d9 --- /dev/null +++ b/docs/dev/OperatorFixture.md @@ -0,0 +1,33 @@ +# OperatorFixture + +Drill provides a simple way to test internal components without a full Drill server (assuming, of course, that the component is structured in a way that allows such testing; something that only a few parts of the code allow at the moment.) + +Testing is based on the `OperatorFixture` which sets up the basic internal mechanisms: + +* Memory allocator +* Operator context +* Fragment context (but without the server-related `DrillbitContext`) + +Here is a very simple example to allow testing a UDF that uses VarChar holders, which in turn use DrillBuf, which requires access to a memory allocator: + +``` + @Test + public void testDupItFn() throws Exception { + try (OperatorFixture fixture = OperatorFixture.standardFixture()) { + OperatorContext context = fixture.operatorContext(null); + try { + // Test code goes here + } finally { + context.close(); + } + } + } +``` + +In the above, we simply create an instance of the `OperatorFixture` in a try-with-resources block so we can be sure that the memory allocator shuts down, even if the test fails. + +Then, since this test needs an `OperatorContext`, we go ahead and create one of those. Since it isn't auto-closeable, we run tests in a try/finally block so we can be sure it is closed. + +Then, our code that run tests (in this case, that allocates a buffer using the managed allocator) goes in the test block. + +Tests that don't need an operator context are even simpler. See Drill code for examples. |