Search in sources :

Example 31 with OperatorFixture

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();
    }
}
Also used : PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) OperatorFixture(org.apache.drill.test.OperatorFixture) UserException(org.apache.drill.common.exceptions.UserException)

Example 32 with OperatorFixture

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();
        }
    }
}
Also used : RowSetComparison(org.apache.drill.test.rowSet.RowSetComparison) BatchSchema(org.apache.drill.exec.record.BatchSchema) DirectRowSet(org.apache.drill.exec.physical.rowSet.DirectRowSet) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) OperatorFixture(org.apache.drill.test.OperatorFixture) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) VectorContainer(org.apache.drill.exec.record.VectorContainer) Test(org.junit.Test) BaseTest(org.apache.drill.test.BaseTest)

Example 33 with OperatorFixture

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();
}
Also used : PhysicalOperator(org.apache.drill.exec.physical.base.PhysicalOperator) MockStorePOP(org.apache.drill.exec.store.mock.MockStorePOP) OperatorContext(org.apache.drill.exec.ops.OperatorContext) RowSet(org.apache.drill.exec.physical.rowSet.RowSet) OperatorFixture(org.apache.drill.test.OperatorFixture) MockRecordBatch(org.apache.drill.exec.physical.impl.MockRecordBatch) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 34 with OperatorFixture

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();
    }
}
Also used : OperatorFixture(org.apache.drill.test.OperatorFixture) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Example 35 with OperatorFixture

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();
    }
}
Also used : TupleMetadata(org.apache.drill.exec.record.metadata.TupleMetadata) OperatorFixture(org.apache.drill.test.OperatorFixture) DrillTest(org.apache.drill.test.DrillTest) OperatorTest(org.apache.drill.categories.OperatorTest) Test(org.junit.Test)

Aggregations

OperatorFixture (org.apache.drill.test.OperatorFixture)39 Test (org.junit.Test)36 DrillTest (org.apache.drill.test.DrillTest)20 OperatorTest (org.apache.drill.categories.OperatorTest)14 OptionManager (org.apache.drill.exec.server.options.OptionManager)8 StoragePlugins (org.apache.drill.exec.planner.logical.StoragePlugins)7 BatchSchema (org.apache.drill.exec.record.BatchSchema)7 StoragePluginConfig (org.apache.drill.common.logical.StoragePluginConfig)6 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)5 FileSystemConfig (org.apache.drill.exec.store.dfs.FileSystemConfig)5 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)4 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)4 IOException (java.io.IOException)2 AbstractSecuredStoragePluginConfig (org.apache.drill.common.logical.AbstractSecuredStoragePluginConfig)2 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)2 OperatorContext (org.apache.drill.exec.ops.OperatorContext)2 PhysicalOperator (org.apache.drill.exec.physical.base.PhysicalOperator)2 DirectRowSet (org.apache.drill.exec.physical.rowSet.DirectRowSet)2 VectorContainer (org.apache.drill.exec.record.VectorContainer)2 MockStorePOP (org.apache.drill.exec.store.mock.MockStorePOP)2