use of org.apache.drill.test.OperatorFixture in project drill by apache.
the class TestPluginsMap method testIntrinsic.
public void testIntrinsic() throws Exception {
OperatorFixture.Builder builder = OperatorFixture.builder(dirTestWatcher);
try (OperatorFixture fixture = builder.build()) {
PluginRegistryContextFixture context = new PluginRegistryContextFixture(fixture);
ConnectorLocator locator = new SystemPluginLocator(context);
locator.init();
Collection<StoragePlugin> sysPlugins = locator.intrinsicPlugins();
assertTrue(!sysPlugins.isEmpty());
StoragePlugin sysPlugin = sysPlugins.iterator().next();
ConnectorHandle connector = ConnectorHandle.intrinsicConnector(locator, sysPlugin);
assertTrue(connector.isIntrinsic());
StoragePluginMap map = new StoragePluginMap();
PluginHandle sysEntry = new PluginHandle(sysPlugin, connector, PluginType.INTRINSIC);
assertNull(map.put(sysEntry));
assertSame(sysEntry, map.get(sysPlugin.getName()));
// Second request to put the same (system) plugin is ignored
assertNull(map.put(sysEntry));
// Attempt to overwrite a system plugin is forcefully denied.
// Users can make this mistake, so a UserException is thrown
StoragePluginFixtureConfig config1 = new StoragePluginFixtureConfig("ok1");
PluginHandle entry1 = new PluginHandle(sysPlugin.getName(), config1, connector);
try {
map.put(entry1);
fail();
} catch (UserException e) {
// Expected
}
assertSame(sysEntry, map.get(sysPlugin.getName()));
// putIfAbsent does not replace an existing plugin
assertSame(sysEntry, map.putIfAbsent(entry1));
assertSame(sysEntry, map.get(sysPlugin.getName()));
// is intrinsic.
try {
map.replace(sysEntry, entry1);
fail();
} catch (IllegalArgumentException e) {
// Expected
}
assertSame(sysEntry, map.get(sysPlugin.getName()));
// Remove by entry fails for the same reasons as above.
try {
map.remove(sysEntry.name());
fail();
} catch (PluginException e) {
// Expected
}
assertSame(sysEntry, map.get(sysPlugin.getName()));
// Request to remove by name is ignored
// Caller can't be expected to know the meaning of the name
// Request to remove an intrinsic plugin by name is treated the
// same as a request to remove a non-existent plugin
assertNull(map.remove(sysPlugin.getName()));
assertSame(sysEntry, map.get(sysPlugin.getName()));
// Request to remove by name and config fails
// as above.
assertNull(map.remove(sysPlugin.getName(), sysPlugin.getConfig()));
assertSame(sysEntry, map.get(sysPlugin.getName()));
// Close does close intrinsic plugins, but no way to check
// it without elaborate mocking
map.close();
}
}
use of org.apache.drill.test.OperatorFixture in project drill by apache.
the class AbstractGenericCopierTest method testAppendRecords.
@Test
public void testAppendRecords() throws Exception {
try (OperatorFixture operatorFixture = new OperatorFixture.Builder(baseDirTestWatcher).build()) {
final BufferAllocator allocator = operatorFixture.allocator();
final BatchSchema batchSchema = createTestSchema(BatchSchema.SelectionVectorMode.NONE);
final RowSet srcRowSet = createSrcRowSet(allocator);
final VectorContainer destContainer = new VectorContainer(allocator, batchSchema);
AbstractCopier.allocateOutgoing(destContainer, 3);
destContainer.setRecordCount(0);
final RowSet expectedRowSet = createExpectedRowset(allocator);
MockRecordBatch mockRecordBatch = null;
try {
mockRecordBatch = new MockRecordBatch.Builder().sendData(srcRowSet).build(operatorFixture.getFragmentContext());
mockRecordBatch.next();
final Copier copier = createCopier(mockRecordBatch, destContainer, null);
copier.appendRecord(0);
copier.appendRecords(1, 2);
new RowSetComparison(expectedRowSet).verify(DirectRowSet.fromContainer(destContainer));
} finally {
if (mockRecordBatch != null) {
mockRecordBatch.close();
}
srcRowSet.clear();
destContainer.clear();
expectedRowSet.clear();
}
}
}
use of org.apache.drill.test.OperatorFixture in project drill by apache.
the class TestSortEmitOutcome method testSpillNotSupportedWithEmitOutcome.
/**
* Verifies ExternalSortBatch behavior when it sees batches with EMIT outcome but has to spill to disk because of
* memory pressure. Expectation is currenlty spilling is not supported with EMIT outcome so while preparing the
* output batch that will be detected and Sort will throw UnsupportedOperationException
* @throws Exception
*/
@Test(expected = UnsupportedOperationException.class)
public void testSpillNotSupportedWithEmitOutcome() throws Exception {
final OperatorFixture.Builder builder = OperatorFixture.builder(dirTestWatcher);
// Configuration that forces Sort to spill after buffering 2 incoming batches with data
builder.configBuilder().put(ExecConstants.EXTERNAL_SORT_BATCH_LIMIT, 2);
final OperatorFixture fixture_local = builder.build();
final RowSet.SingleRowSet local_EmptyInputRowSet = fixture_local.rowSetBuilder(inputSchema).build();
final RowSet.SingleRowSet local_nonEmptyInputRowSet1 = fixture_local.rowSetBuilder(inputSchema).addRow(3, 30, "item3").addRow(2, 20, "item2").build();
final RowSet.SingleRowSet local_nonEmptyInputRowSet2 = fixture_local.rowSetBuilder(inputSchema).addRow(1, 10, "item1").build();
final RowSet.SingleRowSet local_nonEmptyInputRowSet3 = fixture_local.rowSetBuilder(inputSchema).addRow(4, 40, "item4").build();
inputContainer.add(local_EmptyInputRowSet.container());
inputContainer.add(local_nonEmptyInputRowSet1.container());
inputContainer.add(local_nonEmptyInputRowSet2.container());
inputContainer.add(local_nonEmptyInputRowSet3.container());
inputContainer.add(local_EmptyInputRowSet.container());
inputOutcomes.add(OK_NEW_SCHEMA);
inputOutcomes.add(OK);
inputOutcomes.add(OK);
inputOutcomes.add(OK);
inputOutcomes.add(EMIT);
final PhysicalOperator mockPopConfig_local = new MockStorePOP(null);
final OperatorContext opContext_local = fixture_local.getFragmentContext().newOperatorContext(mockPopConfig_local);
final MockRecordBatch mockInputBatch = new MockRecordBatch(fixture_local.getFragmentContext(), opContext_local, inputContainer, inputOutcomes, local_EmptyInputRowSet.container().getSchema());
final ExternalSortBatch sortBatch_local = new ExternalSortBatch(sortPopConfig, fixture_local.getFragmentContext(), mockInputBatch);
assertTrue(sortBatch_local.next() == OK_NEW_SCHEMA);
// Should throw the exception
sortBatch_local.next();
// Release memory for row sets
local_EmptyInputRowSet.clear();
local_nonEmptyInputRowSet1.clear();
local_nonEmptyInputRowSet2.clear();
local_nonEmptyInputRowSet3.clear();
sortBatch_local.close();
fixture_local.close();
}
use of org.apache.drill.test.OperatorFixture in project drill by apache.
the class TestSortImpl method testNullInput.
/**
* Test for null input (no input batches). Note that, in this case,
* we never see a schema.
*/
@Test
public void testNullInput() throws Exception {
try (OperatorFixture fixture = OperatorFixture.standardFixture(dirTestWatcher)) {
SortTestFixture sortTest = new SortTestFixture(fixture);
sortTest.run();
}
}
use of org.apache.drill.test.OperatorFixture in project drill by apache.
the class TestSortImpl method testSingleRow.
/**
* Degenerate case: single row in single batch.
*/
@Test
public void testSingleRow() throws Exception {
try (OperatorFixture fixture = OperatorFixture.standardFixture(dirTestWatcher)) {
TupleMetadata schema = SortTestUtilities.nonNullSchema();
SortTestFixture sortTest = new SortTestFixture(fixture);
sortTest.addInput(fixture.rowSetBuilder(schema).addRow(1, "first").build());
sortTest.addOutput(fixture.rowSetBuilder(schema).addRow(1, "first").build());
sortTest.run();
}
}
Aggregations