2020-09-25 21:28:25 -04:00
|
|
|
/*
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import path from 'path';
|
2020-10-03 11:21:44 -04:00
|
|
|
import * as playwright from 'playwright-chromium';
|
2020-09-25 21:28:25 -04:00
|
|
|
|
|
|
|
import { CompactionConfig } from './component/datasources/compaction';
|
|
|
|
import { Datasource } from './component/datasources/datasource';
|
|
|
|
import { DatasourcesOverview } from './component/datasources/overview';
|
2020-10-01 18:14:41 -04:00
|
|
|
import { HashedPartitionsSpec } from './component/load-data/config/partition';
|
2020-09-25 21:28:25 -04:00
|
|
|
import { saveScreenshotIfError } from './util/debug';
|
2021-04-22 22:33:03 -04:00
|
|
|
import {
|
|
|
|
DRUID_EXAMPLES_QUICKSTART_TUTORIAL_DIR,
|
|
|
|
runIndexTask,
|
|
|
|
UNIFIED_CONSOLE_URL,
|
|
|
|
} from './util/druid';
|
|
|
|
import { createBrowser, createPage } from './util/playwright';
|
2020-09-25 21:28:25 -04:00
|
|
|
import { retryIfJestAssertionError } from './util/retry';
|
|
|
|
import { waitTillWebConsoleReady } from './util/setup';
|
|
|
|
|
|
|
|
jest.setTimeout(5 * 60 * 1000);
|
|
|
|
|
|
|
|
// The workflow in these tests is based on the compaction tutorial:
|
|
|
|
// https://druid.apache.org/docs/latest/tutorials/tutorial-compaction.html
|
|
|
|
describe('Auto-compaction', () => {
|
|
|
|
let browser: playwright.Browser;
|
|
|
|
let page: playwright.Page;
|
|
|
|
|
|
|
|
beforeAll(async () => {
|
|
|
|
await waitTillWebConsoleReady();
|
|
|
|
browser = await createBrowser();
|
|
|
|
});
|
|
|
|
|
|
|
|
beforeEach(async () => {
|
|
|
|
page = await createPage(browser);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterAll(async () => {
|
|
|
|
await browser.close();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('Compacts segments from dynamic to hash partitions', async () => {
|
2020-10-01 18:14:41 -04:00
|
|
|
const testName = 'autocompaction-dynamic-to-hash-';
|
|
|
|
const datasourceName = testName + new Date().toISOString();
|
2020-09-25 21:28:25 -04:00
|
|
|
loadInitialData(datasourceName);
|
|
|
|
|
2020-10-01 18:14:41 -04:00
|
|
|
await saveScreenshotIfError(testName, page, async () => {
|
2020-09-25 21:28:25 -04:00
|
|
|
const uncompactedNumSegment = 3;
|
|
|
|
const numRow = 1412;
|
|
|
|
await validateDatasourceStatus(page, datasourceName, uncompactedNumSegment, numRow);
|
|
|
|
|
|
|
|
const compactionConfig = new CompactionConfig({
|
|
|
|
skipOffsetFromLatest: 'PT0S',
|
2020-10-01 18:14:41 -04:00
|
|
|
partitionsSpec: new HashedPartitionsSpec({
|
2020-09-28 20:15:48 -04:00
|
|
|
numShards: null,
|
2020-09-25 21:28:25 -04:00
|
|
|
}),
|
|
|
|
});
|
|
|
|
await configureCompaction(page, datasourceName, compactionConfig);
|
|
|
|
|
|
|
|
// Depending on the number of configured tasks slots, autocompaction may
|
|
|
|
// need several iterations if several time chunks need compaction
|
|
|
|
let currNumSegment = uncompactedNumSegment;
|
|
|
|
await retryIfJestAssertionError(async () => {
|
2020-10-04 03:06:07 -04:00
|
|
|
await triggerCompaction(page);
|
2020-09-25 21:28:25 -04:00
|
|
|
currNumSegment = await waitForCompaction(page, datasourceName, currNumSegment);
|
|
|
|
|
|
|
|
const compactedNumSegment = 2;
|
|
|
|
expect(currNumSegment).toBe(compactedNumSegment);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
function loadInitialData(datasourceName: string) {
|
|
|
|
const ingestionSpec = path.join(
|
2020-10-01 18:14:41 -04:00
|
|
|
DRUID_EXAMPLES_QUICKSTART_TUTORIAL_DIR,
|
2020-09-25 21:28:25 -04:00
|
|
|
'compaction-init-index.json',
|
|
|
|
);
|
|
|
|
const setDatasourceName = `s/compaction-tutorial/${datasourceName}/`;
|
|
|
|
const setIntervals = 's|2015-09-12/2015-09-13|2015-09-12/2015-09-12T02:00|'; // shorten to reduce test duration
|
2020-10-01 18:14:41 -04:00
|
|
|
const sedCommands = [setDatasourceName, setIntervals];
|
|
|
|
runIndexTask(ingestionSpec, sedCommands);
|
2020-09-25 21:28:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function validateDatasourceStatus(
|
|
|
|
page: playwright.Page,
|
|
|
|
datasourceName: string,
|
|
|
|
expectedNumSegment: number,
|
|
|
|
expectedNumRow: number,
|
|
|
|
) {
|
|
|
|
await retryIfJestAssertionError(async () => {
|
|
|
|
const datasource = await getDatasource(page, datasourceName);
|
|
|
|
expect(datasource.availability).toMatch(`Fully available (${expectedNumSegment} segments)`);
|
|
|
|
expect(datasource.totalRows).toBe(expectedNumRow);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getDatasource(page: playwright.Page, datasourceName: string): Promise<Datasource> {
|
|
|
|
const datasourcesOverview = new DatasourcesOverview(page, UNIFIED_CONSOLE_URL);
|
|
|
|
const datasources = await datasourcesOverview.getDatasources();
|
|
|
|
const datasource = datasources.find(t => t.name === datasourceName);
|
|
|
|
expect(datasource).toBeDefined();
|
|
|
|
return datasource!;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function configureCompaction(
|
|
|
|
page: playwright.Page,
|
|
|
|
datasourceName: string,
|
|
|
|
compactionConfig: CompactionConfig,
|
|
|
|
) {
|
|
|
|
const datasourcesOverview = new DatasourcesOverview(page, UNIFIED_CONSOLE_URL);
|
|
|
|
await datasourcesOverview.setCompactionConfiguration(datasourceName, compactionConfig);
|
2020-10-02 02:59:21 -04:00
|
|
|
|
2020-10-04 03:06:07 -04:00
|
|
|
// Saving the compaction config is not instantaneous
|
|
|
|
await retryIfJestAssertionError(async () => {
|
|
|
|
const savedCompactionConfig = await datasourcesOverview.getCompactionConfiguration(
|
|
|
|
datasourceName,
|
|
|
|
);
|
|
|
|
expect(savedCompactionConfig).toEqual(compactionConfig);
|
|
|
|
});
|
2020-09-25 21:28:25 -04:00
|
|
|
}
|
|
|
|
|
2020-10-04 03:06:07 -04:00
|
|
|
async function triggerCompaction(page: playwright.Page) {
|
|
|
|
const datasourcesOverview = new DatasourcesOverview(page, UNIFIED_CONSOLE_URL);
|
|
|
|
await datasourcesOverview.triggerCompaction();
|
2020-09-25 21:28:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
async function waitForCompaction(
|
|
|
|
page: playwright.Page,
|
|
|
|
datasourceName: string,
|
|
|
|
prevNumSegment: number,
|
|
|
|
): Promise<number> {
|
|
|
|
await retryIfJestAssertionError(async () => {
|
|
|
|
const currNumSegment = await getNumSegment(page, datasourceName);
|
|
|
|
expect(currNumSegment).toBeLessThan(prevNumSegment);
|
|
|
|
});
|
|
|
|
|
|
|
|
return getNumSegment(page, datasourceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function getNumSegment(page: playwright.Page, datasourceName: string): Promise<number> {
|
|
|
|
const datasource = await getDatasource(page, datasourceName);
|
2021-04-22 22:33:03 -04:00
|
|
|
const currNumSegmentString = /(\d+)/.exec(datasource.availability)![0];
|
2020-09-25 21:28:25 -04:00
|
|
|
return Number(currNumSegmentString);
|
|
|
|
}
|