Search in sources :

Example 56 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by axbaretto.

the class TestDrillbitResilience method assertExceptionMessage.

/**
 * Check that the injected exception is what we were expecting.
 *
 * @param throwable      the throwable that was caught (by the test)
 * @param exceptionClass the expected exception class
 * @param desc           the expected exception site description
 */
private static void assertExceptionMessage(final Throwable throwable, final Class<? extends Throwable> exceptionClass, final String desc) {
    assertTrue("Throwable was not of UserException type.", throwable instanceof UserException);
    final ExceptionWrapper cause = ((UserException) throwable).getOrCreatePBError(false).getException();
    assertEquals("Exception class names should match.", exceptionClass.getName(), cause.getExceptionClass());
    assertEquals("Exception sites should match.", desc, cause.getMessage());
}
Also used : UserException(org.apache.drill.common.exceptions.UserException) ExceptionWrapper(org.apache.drill.exec.proto.UserBitShared.ExceptionWrapper)

Example 57 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestPluginRegistry method testBadPlugin.

/**
 * Test to illustrate problems discussed in DRILL-7624
 */
@Test
public void testBadPlugin() throws Exception {
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher);
    builder.configBuilder().put(ExecConstants.PRIVATE_CONNECTORS, Collections.singletonList(StoragePluginFixture.class.getName()));
    try (ClusterFixture cluster = builder.build()) {
        StoragePluginRegistry registry = cluster.storageRegistry();
        // Create a config that causes a crash because the plugin
        // is not created on update.
        StoragePluginFixtureConfig badConfig = new StoragePluginFixtureConfig("crash-ctor");
        badConfig.setEnabled(true);
        // instantiating the plugin.
        try {
            registry.validatedPut("bad", badConfig);
            fail();
        } catch (PluginException e) {
        // Expected
        }
        assertNull(registry.getStoredConfig("bad"));
        assertFalse(registry.availablePlugins().contains("bad"));
        // Try the same with JSON
        String json = registry.encode(badConfig);
        try {
            registry.putJson("bad", json);
            fail();
        } catch (PluginException e) {
        // Expected
        }
        assertFalse(registry.availablePlugins().contains("bad"));
        // Now, lets pretend the plugin was valid when we did the above,
        // but later the external system failed.
        registry.put("bad", badConfig);
        assertEquals(badConfig, registry.getStoredConfig("bad"));
        assertTrue(registry.availablePlugins().contains("bad"));
        // Ask for the actual plugin. Now will fail.
        try {
            registry.getPlugin("bad");
            fail();
        } catch (UserException e) {
            assertTrue(e.getMessage().contains("bad"));
        }
        assertTrue(registry.availablePlugins().contains("bad"));
        // No plugin created. Will fail the next time also.
        try {
            registry.getPlugin("bad");
            fail();
        } catch (UserException e) {
        // Expected
        }
        assertTrue(registry.availablePlugins().contains("bad"));
        // The iterator used to find planning rules will skip the failed
        // plugin. (That the planner uses all rules is, itself, a bug.)
        int n = registry.availablePlugins().size();
        int count = 0;
        for (@SuppressWarnings("unused") Entry<String, StoragePlugin> entry : registry) {
            count++;
        }
        assertEquals(n - 1, count);
        // Reset to known good state
        registry.remove("bad");
        // Get tricky. Create a good plugin, then replace with
        // a disabled bad one.
        StoragePluginFixtureConfig goodConfig = new StoragePluginFixtureConfig("ok");
        goodConfig.setEnabled(true);
        json = registry.encode(goodConfig);
        registry.putJson("test", json);
        assertTrue(registry.availablePlugins().contains("test"));
        assertEquals(goodConfig, registry.getPlugin("test").getConfig());
        // Replace with a disabled bad plugin
        badConfig = new StoragePluginFixtureConfig("crash-ctor");
        badConfig.setEnabled(false);
        json = registry.encode(badConfig);
        registry.putJson("test", json);
        assertFalse(registry.availablePlugins().contains("test"));
        assertNull(registry.getPlugin("test"));
        assertNotNull(registry.getStoredConfig("test"));
        assertEquals(badConfig, registry.getStoredConfig("test"));
        // Attempt to disable a disabled plugin. Should be OK.
        registry.setEnabled("test", false);
        // system, fix that system first.)
        try {
            registry.setEnabled("test", true);
            fail();
        } catch (PluginException e) {
        // Expected
        }
        assertFalse(registry.availablePlugins().contains("test"));
    }
}
Also used : ClusterFixture(org.apache.drill.test.ClusterFixture) PluginException(org.apache.drill.exec.store.StoragePluginRegistry.PluginException) ClusterFixtureBuilder(org.apache.drill.test.ClusterFixtureBuilder) StoragePluginFixtureConfig(org.apache.drill.exec.store.BasePluginRegistryTest.StoragePluginFixtureConfig) UserException(org.apache.drill.common.exceptions.UserException) BaseTest(org.apache.drill.test.BaseTest) Test(org.junit.Test)

Example 58 with UserException

use of org.apache.drill.common.exceptions.UserException 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 59 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestHeaderBuilder method testEmptyHeader.

@Test
public void testEmptyHeader() {
    Path dummyPath = new Path("file:/dummy.csv");
    HeaderBuilder hb = new HeaderBuilder(dummyPath);
    try {
        hb.finishRecord();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("must define at least one header"));
    }
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "");
    try {
        hb.finishRecord();
    } catch (UserException e) {
        assertTrue(e.getMessage().contains("must define at least one header"));
    }
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "   ");
    validateHeader(hb, new String[] { "column_1" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, ",");
    validateHeader(hb, new String[] { "column_1", "column_2" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, " , ");
    validateHeader(hb, new String[] { "column_1", "column_2" });
    hb = new HeaderBuilder(dummyPath);
    parse(hb, "a,   ");
    validateHeader(hb, new String[] { "a", "column_2" });
}
Also used : Path(org.apache.hadoop.fs.Path) HeaderBuilder(org.apache.drill.exec.store.easy.text.reader.HeaderBuilder) UserException(org.apache.drill.common.exceptions.UserException) Test(org.junit.Test) DrillTest(org.apache.drill.test.DrillTest)

Example 60 with UserException

use of org.apache.drill.common.exceptions.UserException in project drill by apache.

the class TestGracefulShutdown method testDrillbitTempDir.

// DRILL-7056
@Test
public void testDrillbitTempDir() throws Exception {
    File originalDrillbitTempDir;
    ClusterFixtureBuilder fixtureBuilder = ClusterFixture.builder(dirTestWatcher).withLocalZk().configProperty(ExecConstants.ALLOW_LOOPBACK_ADDRESS_BINDING, true).configProperty(ExecConstants.INITIAL_USER_PORT, QueryTestUtil.getFreePortNumber(31170, 300)).configProperty(ExecConstants.INITIAL_BIT_PORT, QueryTestUtil.getFreePortNumber(31180, 300));
    try (ClusterFixture fixture = fixtureBuilder.build();
        Drillbit twinDrillbitOnSamePort = new Drillbit(fixture.config(), fixtureBuilder.configBuilder().getDefinitions(), fixture.serviceSet())) {
        // Assert preconditions :
        // 1. First drillbit instance should be started normally
        // 2. Second instance startup should fail, because ports are occupied by the first one
        Drillbit originalDrillbit = fixture.drillbit();
        assertNotNull("First drillbit instance should be initialized", originalDrillbit);
        originalDrillbitTempDir = getWebServerTempDirPath(originalDrillbit);
        assertTrue("First drillbit instance should have a temporary Javascript dir initialized", originalDrillbitTempDir.exists());
        try {
            twinDrillbitOnSamePort.run();
            fail("Invocation of 'twinDrillbitOnSamePort.run()' should throw UserException");
        } catch (UserException userEx) {
            assertThat(userEx.getMessage(), containsString("RESOURCE ERROR: Drillbit could not bind to port"));
        }
    }
    // Verify deletion
    assertFalse("First drillbit instance should have a temporary Javascript dir deleted", originalDrillbitTempDir.exists());
}
Also used : Drillbit(org.apache.drill.exec.server.Drillbit) UserException(org.apache.drill.common.exceptions.UserException) File(java.io.File) SlowTest(org.apache.drill.categories.SlowTest) Test(org.junit.Test)

Aggregations

UserException (org.apache.drill.common.exceptions.UserException)102 Test (org.junit.Test)76 EvfTest (org.apache.drill.categories.EvfTest)39 TupleMetadata (org.apache.drill.exec.record.metadata.TupleMetadata)30 SubOperatorTest (org.apache.drill.test.SubOperatorTest)30 SchemaBuilder (org.apache.drill.exec.record.metadata.SchemaBuilder)28 RowBatchReader (org.apache.drill.exec.physical.impl.scan.RowBatchReader)12 ManagedReader (org.apache.drill.exec.physical.impl.scan.v3.ManagedReader)12 ScanLifecycleBuilder (org.apache.drill.exec.physical.impl.scan.v3.ScanLifecycleBuilder)11 SchemaNegotiator (org.apache.drill.exec.physical.impl.scan.v3.SchemaNegotiator)11 ScanOperatorExec (org.apache.drill.exec.physical.impl.scan.ScanOperatorExec)9 ScanFixture (org.apache.drill.exec.physical.impl.scan.ScanTestUtils.ScanFixture)9 SchemaPath (org.apache.drill.common.expression.SchemaPath)8 ResultSetOptions (org.apache.drill.exec.physical.resultSet.impl.ResultSetLoaderImpl.ResultSetOptions)8 RowSet (org.apache.drill.exec.physical.rowSet.RowSet)8 MockRecordBatch (org.apache.drill.exec.physical.impl.MockRecordBatch)6 ArrayList (java.util.ArrayList)5 OperatorTest (org.apache.drill.categories.OperatorTest)5 DrillException (org.apache.drill.common.exceptions.DrillException)5 BaseTest (org.apache.drill.test.BaseTest)5