Search in sources :

Example 6 with LogFixtureBuilder

use of org.apache.drill.test.LogFixture.LogFixtureBuilder in project drill by apache.

the class ExampleTest method fourthTest.

/**
 * Example using custom logging. Here we run a sort with trace logging enabled
 * for just the sort class, and with logging displayed to the console.
 * <p>
 * This example also shows setting up a realistic set of options prior to
 * running a query. Note that we pass in normal Java values (don't have to
 * encode the values as a string.)
 * <p>
 * Finally, also shows defining your own ad-hoc local file workspace to
 * point to a sample data file.
 * <p>
 * Unlike the other tests, don't actually run this one. It points to
 * a location on a local machine. And, the query itself takes 23 minutes
 * to run if you had the right data file...
 *
 * @throws Exception if anything goes wrong
 */
@Test
public void fourthTest() throws Exception {
    LogFixtureBuilder logBuilder = LogFixture.builder().toConsole().logger("org.apache.drill.exec.physical.impl.xsort", Level.DEBUG).logger(ExternalSortBatch.class, Level.TRACE);
    ClusterFixtureBuilder builder = ClusterFixture.builder(dirTestWatcher).maxParallelization(1).sessionOption(ExecConstants.MAX_QUERY_MEMORY_PER_NODE_KEY, 2L * 1024 * 1024 * 1024).sessionOption(PlannerSettings.EXCHANGE.getOptionName(), true).sessionOption(PlannerSettings.HASHAGG.getOptionName(), false);
    try (LogFixture logs = logBuilder.build();
        ClusterFixture cluster = builder.build();
        ClientFixture client = cluster.clientFixture()) {
        setupFile();
        cluster.defineWorkspace("dfs", "data", "/tmp/drill-test", "psv");
        String sql = "select * from `dfs.data`.`example.tbl` order by columns[0]";
        QuerySummary results = client.queryBuilder().sql(sql).run();
        assertEquals(2, results.recordCount());
    }
}
Also used : QuerySummary(org.apache.drill.test.QueryBuilder.QuerySummary) LogFixtureBuilder(org.apache.drill.test.LogFixture.LogFixtureBuilder) Test(org.junit.Test)

Example 7 with LogFixtureBuilder

use of org.apache.drill.test.LogFixture.LogFixtureBuilder in project drill by apache.

the class TestLenientAllocation method testLenientLimit.

@Test
public void testLenientLimit() {
    LogFixtureBuilder logBuilder = LogFixture.builder().logger(Accountant.class, Level.WARN);
    try (LogFixture logFixture = logBuilder.build()) {
        // Test can't run without assertions
        assertTrue(AssertionUtil.isAssertionsEnabled());
        // Create a child allocator
        BufferAllocator allocator = fixture.allocator().newChildAllocator("test", 10 * ONE_MEG, 128 * ONE_MEG);
        ((Accountant) allocator).forceLenient();
        // Allocate most of the available memory
        DrillBuf buf1 = allocator.buffer(64 * ONE_MEG);
        // Oops, we did our math wrong; allocate too large a buffer.
        DrillBuf buf2 = allocator.buffer(128 * ONE_MEG);
        try {
            allocator.buffer(64 * ONE_MEG);
            fail();
        } catch (OutOfMemoryException e) {
        // Expected
        }
        // Clean up
        buf1.close();
        buf2.close();
        allocator.close();
    }
}
Also used : LogFixture(org.apache.drill.test.LogFixture) Accountant(org.apache.drill.exec.memory.Accountant) LogFixtureBuilder(org.apache.drill.test.LogFixture.LogFixtureBuilder) OutOfMemoryException(org.apache.drill.exec.exception.OutOfMemoryException) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) DrillBuf(io.netty.buffer.DrillBuf) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Example 8 with LogFixtureBuilder

use of org.apache.drill.test.LogFixture.LogFixtureBuilder in project drill by apache.

the class TestLenientAllocation method testStrict.

/**
 * Test that the allocator is normally strict in debug mode.
 */
@Test
public void testStrict() {
    LogFixtureBuilder logBuilder = LogFixture.builder().logger(Accountant.class, Level.WARN);
    try (LogFixture logFixture = logBuilder.build()) {
        // Test can't run without assertions
        assertTrue(AssertionUtil.isAssertionsEnabled());
        // Create a child allocator
        BufferAllocator allocator = fixture.allocator().newChildAllocator("test", 10 * 1024, 128 * 1024);
        // Allocate most of the available memory
        DrillBuf buf1 = allocator.buffer(64 * 1024);
        try {
            allocator.buffer(128 * 1024);
            fail();
        } catch (OutOfMemoryException e) {
        // Expected
        }
        // Clean up
        buf1.close();
        allocator.close();
    }
}
Also used : LogFixture(org.apache.drill.test.LogFixture) LogFixtureBuilder(org.apache.drill.test.LogFixture.LogFixtureBuilder) OutOfMemoryException(org.apache.drill.exec.exception.OutOfMemoryException) BufferAllocator(org.apache.drill.exec.memory.BufferAllocator) DrillBuf(io.netty.buffer.DrillBuf) SubOperatorTest(org.apache.drill.test.SubOperatorTest) Test(org.junit.Test)

Aggregations

LogFixtureBuilder (org.apache.drill.test.LogFixture.LogFixtureBuilder)8 Test (org.junit.Test)8 DrillBuf (io.netty.buffer.DrillBuf)6 OutOfMemoryException (org.apache.drill.exec.exception.OutOfMemoryException)6 BufferAllocator (org.apache.drill.exec.memory.BufferAllocator)6 LogFixture (org.apache.drill.test.LogFixture)6 SubOperatorTest (org.apache.drill.test.SubOperatorTest)6 Accountant (org.apache.drill.exec.memory.Accountant)4 QuerySummary (org.apache.drill.test.QueryBuilder.QuerySummary)2