mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2026-01-29 14:44:22 +00:00
Compare commits
2 Commits
users/saks
...
copilot/su
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
131ffe643a | ||
|
|
9b2fb0c04e |
@@ -16,7 +16,7 @@ import {
|
|||||||
import { useIndexingPolicyStore } from "Explorer/Tabs/QueryTab/ResultsView";
|
import { useIndexingPolicyStore } from "Explorer/Tabs/QueryTab/ResultsView";
|
||||||
import { useDatabases } from "Explorer/useDatabases";
|
import { useDatabases } from "Explorer/useDatabases";
|
||||||
import { isFabricNative } from "Platform/Fabric/FabricUtil";
|
import { isFabricNative } from "Platform/Fabric/FabricUtil";
|
||||||
import { isCapabilityEnabled, isVectorSearchEnabled } from "Utils/CapabilityUtils";
|
import { isVectorSearchEnabled } from "Utils/CapabilityUtils";
|
||||||
import { isRunningOnPublicCloud } from "Utils/CloudUtils";
|
import { isRunningOnPublicCloud } from "Utils/CloudUtils";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import DiscardIcon from "../../../../images/discard.svg";
|
import DiscardIcon from "../../../../images/discard.svg";
|
||||||
@@ -70,6 +70,7 @@ import {
|
|||||||
getMongoNotification,
|
getMongoNotification,
|
||||||
getTabTitle,
|
getTabTitle,
|
||||||
hasDatabaseSharedThroughput,
|
hasDatabaseSharedThroughput,
|
||||||
|
isDataMaskingEnabled,
|
||||||
isDirty,
|
isDirty,
|
||||||
parseConflictResolutionMode,
|
parseConflictResolutionMode,
|
||||||
parseConflictResolutionProcedure,
|
parseConflictResolutionProcedure,
|
||||||
@@ -1073,8 +1074,8 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
|||||||
|
|
||||||
newCollection.fullTextPolicy = this.state.fullTextPolicy;
|
newCollection.fullTextPolicy = this.state.fullTextPolicy;
|
||||||
|
|
||||||
// Only send data masking policy if it was modified (dirty)
|
// Only send data masking policy if it was modified (dirty) and data masking is enabled
|
||||||
if (this.state.isDataMaskingDirty && isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking)) {
|
if (this.state.isDataMaskingDirty && isDataMaskingEnabled(this.collection.dataMaskingPolicy?.())) {
|
||||||
newCollection.dataMaskingPolicy = this.state.dataMaskingContent;
|
newCollection.dataMaskingPolicy = this.state.dataMaskingContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1463,15 +1464,7 @@ export class SettingsComponent extends React.Component<SettingsComponentProps, S
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if DDM should be enabled
|
if (isDataMaskingEnabled(this.collection.dataMaskingPolicy?.())) {
|
||||||
const shouldEnableDDM = (): boolean => {
|
|
||||||
const hasDataMaskingCapability = isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking);
|
|
||||||
const isSqlAccount = userContext.apiType === "SQL";
|
|
||||||
|
|
||||||
return isSqlAccount && hasDataMaskingCapability; // Only show for SQL accounts with DDM capability
|
|
||||||
};
|
|
||||||
|
|
||||||
if (shouldEnableDDM()) {
|
|
||||||
const dataMaskingComponentProps: DataMaskingComponentProps = {
|
const dataMaskingComponentProps: DataMaskingComponentProps = {
|
||||||
shouldDiscardDataMasking: this.state.shouldDiscardDataMasking,
|
shouldDiscardDataMasking: this.state.shouldDiscardDataMasking,
|
||||||
resetShouldDiscardDataMasking: this.resetShouldDiscardDataMasking,
|
resetShouldDiscardDataMasking: this.resetShouldDiscardDataMasking,
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
import { MessageBar, MessageBarType, Stack } from "@fluentui/react";
|
import { MessageBar, MessageBarType, Stack } from "@fluentui/react";
|
||||||
import * as monaco from "monaco-editor";
|
import * as monaco from "monaco-editor";
|
||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import * as Constants from "../../../../Common/Constants";
|
|
||||||
import * as DataModels from "../../../../Contracts/DataModels";
|
import * as DataModels from "../../../../Contracts/DataModels";
|
||||||
import { isCapabilityEnabled } from "../../../../Utils/CapabilityUtils";
|
|
||||||
import { loadMonaco } from "../../../LazyMonaco";
|
import { loadMonaco } from "../../../LazyMonaco";
|
||||||
import { titleAndInputStackProps, unsavedEditorWarningMessage } from "../SettingsRenderUtils";
|
import { titleAndInputStackProps, unsavedEditorWarningMessage } from "../SettingsRenderUtils";
|
||||||
import { isDirty as isContentDirty } from "../SettingsUtils";
|
import { isDataMaskingEnabled, isDirty as isContentDirty } from "../SettingsUtils";
|
||||||
|
|
||||||
export interface DataMaskingComponentProps {
|
export interface DataMaskingComponentProps {
|
||||||
shouldDiscardDataMasking: boolean;
|
shouldDiscardDataMasking: boolean;
|
||||||
@@ -140,7 +138,7 @@ export class DataMaskingComponent extends React.Component<DataMaskingComponentPr
|
|||||||
};
|
};
|
||||||
|
|
||||||
public render(): JSX.Element {
|
public render(): JSX.Element {
|
||||||
if (!isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking)) {
|
if (!isDataMaskingEnabled(this.props.dataMaskingContent)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import * as Constants from "../../../Common/Constants";
|
|||||||
import * as DataModels from "../../../Contracts/DataModels";
|
import * as DataModels from "../../../Contracts/DataModels";
|
||||||
import * as ViewModels from "../../../Contracts/ViewModels";
|
import * as ViewModels from "../../../Contracts/ViewModels";
|
||||||
import { isFabricNative } from "../../../Platform/Fabric/FabricUtil";
|
import { isFabricNative } from "../../../Platform/Fabric/FabricUtil";
|
||||||
|
import { userContext } from "../../../UserContext";
|
||||||
|
import { isCapabilityEnabled } from "../../../Utils/CapabilityUtils";
|
||||||
import { MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types";
|
import { MongoIndex } from "../../../Utils/arm/generatedClients/cosmos/types";
|
||||||
|
|
||||||
const zeroValue = 0;
|
const zeroValue = 0;
|
||||||
@@ -88,6 +90,19 @@ export const hasDatabaseSharedThroughput = (collection: ViewModels.Collection):
|
|||||||
return database?.isDatabaseShared() && !collection.offer();
|
return database?.isDatabaseShared() && !collection.offer();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const isDataMaskingEnabled = (dataMaskingPolicy?: DataModels.DataMaskingPolicy): boolean => {
|
||||||
|
const isSqlAccount = userContext.apiType === "SQL";
|
||||||
|
if (!isSqlAccount) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const hasDataMaskingCapability = isCapabilityEnabled(Constants.CapabilityNames.EnableDynamicDataMasking);
|
||||||
|
const hasDataMaskingPolicyFromCollection =
|
||||||
|
dataMaskingPolicy?.includedPaths?.length > 0 || dataMaskingPolicy?.excludedPaths?.length > 0;
|
||||||
|
|
||||||
|
return hasDataMaskingCapability || hasDataMaskingPolicyFromCollection;
|
||||||
|
};
|
||||||
|
|
||||||
export const parseConflictResolutionMode = (modeFromBackend: string): DataModels.ConflictResolutionMode => {
|
export const parseConflictResolutionMode = (modeFromBackend: string): DataModels.ConflictResolutionMode => {
|
||||||
// Backend can contain different casing as it does case-insensitive comparisson
|
// Backend can contain different casing as it does case-insensitive comparisson
|
||||||
if (!modeFromBackend) {
|
if (!modeFromBackend) {
|
||||||
|
|||||||
@@ -604,6 +604,60 @@ exports[`SettingsComponent renders 1`] = `
|
|||||||
/>
|
/>
|
||||||
</Stack>
|
</Stack>
|
||||||
</PivotItem>
|
</PivotItem>
|
||||||
|
<PivotItem
|
||||||
|
headerButtonProps={
|
||||||
|
{
|
||||||
|
"data-test": "settings-tab-header/DataMaskingTab",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
headerText="Masking Policy (preview)"
|
||||||
|
itemKey="DataMaskingTab"
|
||||||
|
key="DataMaskingTab"
|
||||||
|
style={
|
||||||
|
{
|
||||||
|
"backgroundColor": "var(--colorNeutralBackground1)",
|
||||||
|
"color": "var(--colorNeutralForeground1)",
|
||||||
|
"marginTop": 20,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<Stack
|
||||||
|
styles={
|
||||||
|
{
|
||||||
|
"root": {
|
||||||
|
"backgroundColor": "var(--colorNeutralBackground1)",
|
||||||
|
"color": "var(--colorNeutralForeground1)",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
>
|
||||||
|
<DataMaskingComponent
|
||||||
|
dataMaskingContent={
|
||||||
|
{
|
||||||
|
"excludedPaths": [
|
||||||
|
"/excludedPath",
|
||||||
|
],
|
||||||
|
"includedPaths": [],
|
||||||
|
"isPolicyEnabled": true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dataMaskingContentBaseline={
|
||||||
|
{
|
||||||
|
"excludedPaths": [
|
||||||
|
"/excludedPath",
|
||||||
|
],
|
||||||
|
"includedPaths": [],
|
||||||
|
"isPolicyEnabled": true,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onDataMaskingContentChange={[Function]}
|
||||||
|
onDataMaskingDirtyChange={[Function]}
|
||||||
|
resetShouldDiscardDataMasking={[Function]}
|
||||||
|
shouldDiscardDataMasking={false}
|
||||||
|
validationErrors={[]}
|
||||||
|
/>
|
||||||
|
</Stack>
|
||||||
|
</PivotItem>
|
||||||
<PivotItem
|
<PivotItem
|
||||||
headerButtonProps={
|
headerButtonProps={
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -58,9 +58,7 @@ export const defaultAccounts: Record<TestAccount, string> = {
|
|||||||
export const resourceGroupName = process.env.DE_TEST_RESOURCE_GROUP ?? "de-e2e-tests";
|
export const resourceGroupName = process.env.DE_TEST_RESOURCE_GROUP ?? "de-e2e-tests";
|
||||||
export const subscriptionId = process.env.DE_TEST_SUBSCRIPTION_ID ?? "69e02f2d-f059-4409-9eac-97e8a276ae2c";
|
export const subscriptionId = process.env.DE_TEST_SUBSCRIPTION_ID ?? "69e02f2d-f059-4409-9eac-97e8a276ae2c";
|
||||||
export const TEST_AUTOSCALE_THROUGHPUT_RU = 1000;
|
export const TEST_AUTOSCALE_THROUGHPUT_RU = 1000;
|
||||||
export const TEST_MANUAL_THROUGHPUT_RU = 800;
|
|
||||||
export const TEST_AUTOSCALE_MAX_THROUGHPUT_RU_2K = 2000;
|
export const TEST_AUTOSCALE_MAX_THROUGHPUT_RU_2K = 2000;
|
||||||
export const TEST_AUTOSCALE_MAX_THROUGHPUT_RU_4K = 4000;
|
|
||||||
export const TEST_MANUAL_THROUGHPUT_RU_2K = 2000;
|
export const TEST_MANUAL_THROUGHPUT_RU_2K = 2000;
|
||||||
export const ONE_MINUTE_MS: number = 60 * 1000;
|
export const ONE_MINUTE_MS: number = 60 * 1000;
|
||||||
|
|
||||||
|
|||||||
@@ -1,127 +0,0 @@
|
|||||||
import { expect, test, type Page } from "@playwright/test";
|
|
||||||
import { DataExplorer, TestAccount } from "../../fx";
|
|
||||||
import { createTestSQLContainer, TestContainerContext } from "../../testData";
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests for Dynamic Data Masking (DDM) feature.
|
|
||||||
*
|
|
||||||
* Prerequisites:
|
|
||||||
* - Test account must have the EnableDynamicDataMasking capability enabled
|
|
||||||
* - If the capability is not enabled, the DataMaskingTab will not be visible and tests will be skipped
|
|
||||||
*
|
|
||||||
* Important Notes:
|
|
||||||
* - Tests focus on enabling DDM and modifying the masking policy configuration
|
|
||||||
*/
|
|
||||||
|
|
||||||
let testContainer: TestContainerContext;
|
|
||||||
let DATABASE_ID: string;
|
|
||||||
let CONTAINER_ID: string;
|
|
||||||
|
|
||||||
test.beforeAll(async () => {
|
|
||||||
testContainer = await createTestSQLContainer();
|
|
||||||
DATABASE_ID = testContainer.database.id;
|
|
||||||
CONTAINER_ID = testContainer.container.id;
|
|
||||||
});
|
|
||||||
|
|
||||||
// Clean up test database after all tests
|
|
||||||
test.afterAll(async () => {
|
|
||||||
if (testContainer) {
|
|
||||||
await testContainer.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Helper function to navigate to Data Masking tab
|
|
||||||
async function navigateToDataMaskingTab(page: Page, explorer: DataExplorer): Promise<boolean> {
|
|
||||||
// Refresh the tree to see the newly created database
|
|
||||||
const refreshButton = explorer.frame.getByTestId("Sidebar/RefreshButton");
|
|
||||||
await refreshButton.click();
|
|
||||||
await page.waitForTimeout(3000);
|
|
||||||
|
|
||||||
// Expand database and container nodes
|
|
||||||
const databaseNode = await explorer.waitForNode(DATABASE_ID);
|
|
||||||
await databaseNode.expand();
|
|
||||||
await page.waitForTimeout(2000);
|
|
||||||
|
|
||||||
const containerNode = await explorer.waitForNode(`${DATABASE_ID}/${CONTAINER_ID}`);
|
|
||||||
await containerNode.expand();
|
|
||||||
await page.waitForTimeout(1000);
|
|
||||||
|
|
||||||
// Click Scale & Settings or Settings (depending on container type)
|
|
||||||
let settingsNode = explorer.frame.getByTestId(`TreeNode:${DATABASE_ID}/${CONTAINER_ID}/Scale & Settings`);
|
|
||||||
const isScaleAndSettings = await settingsNode.isVisible().catch(() => false);
|
|
||||||
|
|
||||||
if (!isScaleAndSettings) {
|
|
||||||
settingsNode = explorer.frame.getByTestId(`TreeNode:${DATABASE_ID}/${CONTAINER_ID}/Settings`);
|
|
||||||
}
|
|
||||||
|
|
||||||
await settingsNode.click();
|
|
||||||
await page.waitForTimeout(2000);
|
|
||||||
|
|
||||||
// Check if Data Masking tab is available
|
|
||||||
const dataMaskingTab = explorer.frame.getByTestId("settings-tab-header/DataMaskingTab");
|
|
||||||
const isTabVisible = await dataMaskingTab.isVisible().catch(() => false);
|
|
||||||
|
|
||||||
if (!isTabVisible) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await dataMaskingTab.click();
|
|
||||||
await page.waitForTimeout(1000);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
test.describe("Data Masking under Scale & Settings", () => {
|
|
||||||
test("Data Masking tab should be visible and show JSON editor", async ({ page }) => {
|
|
||||||
const explorer = await DataExplorer.open(page, TestAccount.SQL);
|
|
||||||
const isTabAvailable = await navigateToDataMaskingTab(page, explorer);
|
|
||||||
|
|
||||||
if (!isTabAvailable) {
|
|
||||||
test.skip(
|
|
||||||
true,
|
|
||||||
"Data Masking tab is not available. Test account may not have EnableDynamicDataMasking capability.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the Data Masking editor is visible
|
|
||||||
const dataMaskingEditor = explorer.frame.locator(".settingsV2Editor");
|
|
||||||
await expect(dataMaskingEditor).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Data Masking editor should contain default policy structure", async ({ page }) => {
|
|
||||||
const explorer = await DataExplorer.open(page, TestAccount.SQL);
|
|
||||||
const isTabAvailable = await navigateToDataMaskingTab(page, explorer);
|
|
||||||
|
|
||||||
if (!isTabAvailable) {
|
|
||||||
test.skip(
|
|
||||||
true,
|
|
||||||
"Data Masking tab is not available. Test account may not have EnableDynamicDataMasking capability.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify the editor contains the expected JSON structure fields
|
|
||||||
const editorContent = explorer.frame.locator(".settingsV2Editor");
|
|
||||||
await expect(editorContent).toBeVisible();
|
|
||||||
|
|
||||||
// Check that the editor contains key policy fields (default policy has empty arrays)
|
|
||||||
await expect(editorContent).toContainText("includedPaths");
|
|
||||||
await expect(editorContent).toContainText("excludedPaths");
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Data Masking editor should have correct default policy values", async ({ page }) => {
|
|
||||||
const explorer = await DataExplorer.open(page, TestAccount.SQL);
|
|
||||||
const isTabAvailable = await navigateToDataMaskingTab(page, explorer);
|
|
||||||
|
|
||||||
if (!isTabAvailable) {
|
|
||||||
test.skip(
|
|
||||||
true,
|
|
||||||
"Data Masking tab is not available. Test account may not have EnableDynamicDataMasking capability.",
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const editorContent = explorer.frame.locator(".settingsV2Editor");
|
|
||||||
await expect(editorContent).toBeVisible();
|
|
||||||
|
|
||||||
// Default policy should have empty includedPaths and excludedPaths arrays
|
|
||||||
await expect(editorContent).toContainText("[]");
|
|
||||||
});
|
|
||||||
});
|
|
||||||
@@ -1,229 +0,0 @@
|
|||||||
import { Locator, expect, test } from "@playwright/test";
|
|
||||||
import {
|
|
||||||
CommandBarButton,
|
|
||||||
DataExplorer,
|
|
||||||
ONE_MINUTE_MS,
|
|
||||||
TEST_AUTOSCALE_MAX_THROUGHPUT_RU_4K,
|
|
||||||
TEST_MANUAL_THROUGHPUT_RU,
|
|
||||||
TestAccount,
|
|
||||||
} from "../../fx";
|
|
||||||
import { TestDatabaseContext, createTestDB } from "../../testData";
|
|
||||||
|
|
||||||
test.describe("Database with Shared Throughput", () => {
|
|
||||||
let dbContext: TestDatabaseContext = null!;
|
|
||||||
let explorer: DataExplorer = null!;
|
|
||||||
const containerId = "sharedcontainer";
|
|
||||||
|
|
||||||
// Helper methods
|
|
||||||
const getThroughputInput = (type: "manual" | "autopilot"): Locator => {
|
|
||||||
return explorer.frame.getByTestId(`${type}-throughput-input`);
|
|
||||||
};
|
|
||||||
|
|
||||||
test.afterEach("Delete Test Database", async () => {
|
|
||||||
await dbContext?.dispose();
|
|
||||||
});
|
|
||||||
|
|
||||||
test.describe("Manual Throughput Tests", () => {
|
|
||||||
test.beforeEach(async ({ page }) => {
|
|
||||||
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Create database with shared manual throughput and verify Scale node in UI", async () => {
|
|
||||||
test.setTimeout(120000); // 2 minutes timeout
|
|
||||||
// Create database with shared manual throughput (400 RU/s)
|
|
||||||
dbContext = await createTestDB({ throughput: 400 });
|
|
||||||
|
|
||||||
// Verify database node appears in the tree
|
|
||||||
const databaseNode = await explorer.waitForNode(dbContext.database.id);
|
|
||||||
expect(databaseNode).toBeDefined();
|
|
||||||
|
|
||||||
// Expand the database node to see child nodes
|
|
||||||
await databaseNode.expand();
|
|
||||||
|
|
||||||
// Verify that "Scale" node appears under the database
|
|
||||||
const scaleNode = await explorer.waitForNode(`${dbContext.database.id}/Scale`);
|
|
||||||
expect(scaleNode).toBeDefined();
|
|
||||||
await expect(scaleNode.element).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Add container to shared database without dedicated throughput", async () => {
|
|
||||||
// Create database with shared manual throughput
|
|
||||||
dbContext = await createTestDB({ throughput: 400 });
|
|
||||||
|
|
||||||
// Wait for the database to appear in the tree
|
|
||||||
await explorer.waitForNode(dbContext.database.id);
|
|
||||||
|
|
||||||
// Add a container to the shared database via UI
|
|
||||||
const newContainerButton = await explorer.globalCommandButton("New Container");
|
|
||||||
await newContainerButton.click();
|
|
||||||
|
|
||||||
await explorer.whilePanelOpen(
|
|
||||||
"New Container",
|
|
||||||
async (panel, okButton) => {
|
|
||||||
// Select "Use existing" database
|
|
||||||
const useExistingRadio = panel.getByRole("radio", { name: /Use existing/i });
|
|
||||||
await useExistingRadio.click();
|
|
||||||
|
|
||||||
// Select the database from dropdown using the new data-testid
|
|
||||||
const databaseDropdown = panel.getByRole("combobox", { name: "Choose an existing database" });
|
|
||||||
await databaseDropdown.click();
|
|
||||||
|
|
||||||
await explorer.frame.getByRole("option", { name: dbContext.database.id }).click();
|
|
||||||
// Now you can target the specific database option by its data-testid
|
|
||||||
//await panel.getByTestId(`database-option-${dbContext.database.id}`).click();
|
|
||||||
// Fill container id
|
|
||||||
await panel.getByRole("textbox", { name: "Container id, Example Container1" }).fill(containerId);
|
|
||||||
|
|
||||||
// Fill partition key
|
|
||||||
await panel.getByRole("textbox", { name: "Partition key" }).fill("/pk");
|
|
||||||
|
|
||||||
// Ensure "Provision dedicated throughput" is NOT checked
|
|
||||||
const dedicatedThroughputCheckbox = panel.getByRole("checkbox", {
|
|
||||||
name: /Provision dedicated throughput for this container/i,
|
|
||||||
});
|
|
||||||
|
|
||||||
if (await dedicatedThroughputCheckbox.isVisible()) {
|
|
||||||
const isChecked = await dedicatedThroughputCheckbox.isChecked();
|
|
||||||
if (isChecked) {
|
|
||||||
await dedicatedThroughputCheckbox.uncheck();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
await okButton.click();
|
|
||||||
},
|
|
||||||
{ closeTimeout: 5 * ONE_MINUTE_MS },
|
|
||||||
);
|
|
||||||
|
|
||||||
// Verify container was created under the database
|
|
||||||
const containerNode = await explorer.waitForContainerNode(dbContext.database.id, containerId);
|
|
||||||
expect(containerNode).toBeDefined();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Scale shared database manual throughput", async () => {
|
|
||||||
// Create database with shared manual throughput (400 RU/s)
|
|
||||||
dbContext = await createTestDB({ throughput: 400 });
|
|
||||||
|
|
||||||
// Navigate to the scale settings by clicking the "Scale" node in the tree
|
|
||||||
const databaseNode = await explorer.waitForNode(dbContext.database.id);
|
|
||||||
await databaseNode.expand();
|
|
||||||
const scaleNode = await explorer.waitForNode(`${dbContext.database.id}/Scale`);
|
|
||||||
await scaleNode.element.click();
|
|
||||||
|
|
||||||
// Update manual throughput from 400 to 800
|
|
||||||
await getThroughputInput("manual").fill(TEST_MANUAL_THROUGHPUT_RU.toString());
|
|
||||||
|
|
||||||
// Save changes
|
|
||||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
|
||||||
|
|
||||||
// Verify success message
|
|
||||||
await expect(explorer.getConsoleHeaderStatus()).toContainText(
|
|
||||||
`Successfully updated offer for database ${dbContext.database.id}`,
|
|
||||||
{
|
|
||||||
timeout: 2 * ONE_MINUTE_MS,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Scale shared database from manual to autoscale", async () => {
|
|
||||||
// Create database with shared manual throughput (400 RU/s)
|
|
||||||
dbContext = await createTestDB({ throughput: 400 });
|
|
||||||
|
|
||||||
// Open database settings by clicking the "Scale" node
|
|
||||||
const databaseNode = await explorer.waitForNode(dbContext.database.id);
|
|
||||||
await databaseNode.expand();
|
|
||||||
const scaleNode = await explorer.waitForNode(`${dbContext.database.id}/Scale`);
|
|
||||||
await scaleNode.element.click();
|
|
||||||
|
|
||||||
// Switch to Autoscale
|
|
||||||
const autoscaleRadio = explorer.frame.getByText("Autoscale", { exact: true });
|
|
||||||
await autoscaleRadio.click();
|
|
||||||
|
|
||||||
// Set autoscale max throughput to 1000
|
|
||||||
//await getThroughputInput("autopilot").fill(TEST_AUTOSCALE_THROUGHPUT_RU.toString());
|
|
||||||
|
|
||||||
// Save changes
|
|
||||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
|
||||||
|
|
||||||
await expect(explorer.getConsoleHeaderStatus()).toContainText(
|
|
||||||
`Successfully updated offer for database ${dbContext.database.id}`,
|
|
||||||
{
|
|
||||||
timeout: 2 * ONE_MINUTE_MS,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test.describe("Autoscale Throughput Tests", () => {
|
|
||||||
test.beforeEach(async ({ page }) => {
|
|
||||||
explorer = await DataExplorer.open(page, TestAccount.SQL);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Create database with shared autoscale throughput and verify Scale node in UI", async () => {
|
|
||||||
test.setTimeout(120000); // 2 minutes timeout
|
|
||||||
|
|
||||||
// Create database with shared autoscale throughput (max 1000 RU/s)
|
|
||||||
dbContext = await createTestDB({ maxThroughput: 1000 });
|
|
||||||
|
|
||||||
// Verify database node appears
|
|
||||||
const databaseNode = await explorer.waitForNode(dbContext.database.id);
|
|
||||||
expect(databaseNode).toBeDefined();
|
|
||||||
|
|
||||||
// Expand the database node to see child nodes
|
|
||||||
await databaseNode.expand();
|
|
||||||
|
|
||||||
// Verify that "Scale" node appears under the database
|
|
||||||
const scaleNode = await explorer.waitForNode(`${dbContext.database.id}/Scale`);
|
|
||||||
expect(scaleNode).toBeDefined();
|
|
||||||
await expect(scaleNode.element).toBeVisible();
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Scale shared database autoscale throughput", async () => {
|
|
||||||
// Create database with shared autoscale throughput (max 1000 RU/s)
|
|
||||||
dbContext = await createTestDB({ maxThroughput: 1000 });
|
|
||||||
|
|
||||||
// Open database settings
|
|
||||||
const databaseNode = await explorer.waitForNode(dbContext.database.id);
|
|
||||||
await databaseNode.expand();
|
|
||||||
const scaleNode = await explorer.waitForNode(`${dbContext.database.id}/Scale`);
|
|
||||||
await scaleNode.element.click();
|
|
||||||
|
|
||||||
// Update autoscale max throughput from 1000 to 4000
|
|
||||||
await getThroughputInput("autopilot").fill(TEST_AUTOSCALE_MAX_THROUGHPUT_RU_4K.toString());
|
|
||||||
|
|
||||||
// Save changes
|
|
||||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
|
||||||
|
|
||||||
// Verify success message
|
|
||||||
await expect(explorer.getConsoleHeaderStatus()).toContainText(
|
|
||||||
`Successfully updated offer for database ${dbContext.database.id}`,
|
|
||||||
{
|
|
||||||
timeout: 2 * ONE_MINUTE_MS,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
test("Scale shared database from autoscale to manual", async () => {
|
|
||||||
// Create database with shared autoscale throughput (max 1000 RU/s)
|
|
||||||
dbContext = await createTestDB({ maxThroughput: 1000 });
|
|
||||||
|
|
||||||
// Open database settings
|
|
||||||
const databaseNode = await explorer.waitForNode(dbContext.database.id);
|
|
||||||
await databaseNode.expand();
|
|
||||||
const scaleNode = await explorer.waitForNode(`${dbContext.database.id}/Scale`);
|
|
||||||
await scaleNode.element.click();
|
|
||||||
|
|
||||||
// Switch to Manual
|
|
||||||
const manualRadio = explorer.frame.getByText("Manual", { exact: true });
|
|
||||||
await manualRadio.click();
|
|
||||||
|
|
||||||
// Save changes
|
|
||||||
await explorer.commandBarButton(CommandBarButton.Save).click();
|
|
||||||
|
|
||||||
// Verify success message
|
|
||||||
await expect(explorer.getConsoleHeaderStatus()).toContainText(
|
|
||||||
`Successfully updated offer for database ${dbContext.database.id}`,
|
|
||||||
{ timeout: 2 * ONE_MINUTE_MS },
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
121
test/testData.ts
121
test/testData.ts
@@ -82,75 +82,6 @@ export class TestContainerContext {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class TestDatabaseContext {
|
|
||||||
constructor(
|
|
||||||
public armClient: CosmosDBManagementClient,
|
|
||||||
public client: CosmosClient,
|
|
||||||
public database: Database,
|
|
||||||
) {}
|
|
||||||
|
|
||||||
async dispose() {
|
|
||||||
await this.database.delete();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export interface CreateTestDBOptions {
|
|
||||||
throughput?: number;
|
|
||||||
maxThroughput?: number; // For autoscale
|
|
||||||
}
|
|
||||||
|
|
||||||
// Helper function to create ARM client and Cosmos client for SQL account
|
|
||||||
async function createCosmosClientForSQLAccount(
|
|
||||||
accountType: TestAccount.SQL | TestAccount.SQLContainerCopyOnly = TestAccount.SQL,
|
|
||||||
): Promise<{ armClient: CosmosDBManagementClient; client: CosmosClient }> {
|
|
||||||
const credentials = getAzureCLICredentials();
|
|
||||||
const adaptedCredentials = new AzureIdentityCredentialAdapter(credentials);
|
|
||||||
const armClient = new CosmosDBManagementClient(adaptedCredentials, subscriptionId);
|
|
||||||
const accountName = getAccountName(accountType);
|
|
||||||
const account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
|
||||||
|
|
||||||
const clientOptions: CosmosClientOptions = {
|
|
||||||
endpoint: account.documentEndpoint!,
|
|
||||||
};
|
|
||||||
|
|
||||||
const rbacToken =
|
|
||||||
accountType === TestAccount.SQL
|
|
||||||
? process.env.NOSQL_TESTACCOUNT_TOKEN
|
|
||||||
: accountType === TestAccount.SQLContainerCopyOnly
|
|
||||||
? process.env.NOSQL_CONTAINERCOPY_TESTACCOUNT_TOKEN
|
|
||||||
: "";
|
|
||||||
|
|
||||||
if (rbacToken) {
|
|
||||||
clientOptions.tokenProvider = async (): Promise<string> => {
|
|
||||||
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`;
|
|
||||||
const authorizationToken = `${AUTH_PREFIX}${rbacToken}`;
|
|
||||||
return authorizationToken;
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
|
||||||
clientOptions.key = keys.primaryMasterKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
const client = new CosmosClient(clientOptions);
|
|
||||||
|
|
||||||
return { armClient, client };
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function createTestDB(options?: CreateTestDBOptions): Promise<TestDatabaseContext> {
|
|
||||||
const databaseId = generateUniqueName("db");
|
|
||||||
const { armClient, client } = await createCosmosClientForSQLAccount();
|
|
||||||
|
|
||||||
// Create database with provisioned throughput (shared throughput)
|
|
||||||
// This checks the "Provision database throughput" option
|
|
||||||
const { database } = await client.databases.create({
|
|
||||||
id: databaseId,
|
|
||||||
throughput: options?.throughput, // Manual throughput (e.g., 400)
|
|
||||||
maxThroughput: options?.maxThroughput, // Autoscale max throughput (e.g., 1000)
|
|
||||||
});
|
|
||||||
|
|
||||||
return new TestDatabaseContext(armClient, client, database);
|
|
||||||
}
|
|
||||||
|
|
||||||
type createTestSqlContainerConfig = {
|
type createTestSqlContainerConfig = {
|
||||||
includeTestData?: boolean;
|
includeTestData?: boolean;
|
||||||
partitionKey?: string;
|
partitionKey?: string;
|
||||||
@@ -173,7 +104,34 @@ export async function createMultipleTestContainers({
|
|||||||
const creationPromises: Promise<TestContainerContext>[] = [];
|
const creationPromises: Promise<TestContainerContext>[] = [];
|
||||||
|
|
||||||
const databaseId = databaseName ? databaseName : generateUniqueName("db");
|
const databaseId = databaseName ? databaseName : generateUniqueName("db");
|
||||||
const { armClient, client } = await createCosmosClientForSQLAccount(accountType);
|
const credentials = getAzureCLICredentials();
|
||||||
|
const adaptedCredentials = new AzureIdentityCredentialAdapter(credentials);
|
||||||
|
const armClient = new CosmosDBManagementClient(adaptedCredentials, subscriptionId);
|
||||||
|
const accountName = getAccountName(accountType);
|
||||||
|
const account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
||||||
|
|
||||||
|
const clientOptions: CosmosClientOptions = {
|
||||||
|
endpoint: account.documentEndpoint!,
|
||||||
|
};
|
||||||
|
|
||||||
|
const rbacToken =
|
||||||
|
accountType === TestAccount.SQL
|
||||||
|
? process.env.NOSQL_TESTACCOUNT_TOKEN
|
||||||
|
: accountType === TestAccount.SQLContainerCopyOnly
|
||||||
|
? process.env.NOSQL_CONTAINERCOPY_TESTACCOUNT_TOKEN
|
||||||
|
: "";
|
||||||
|
if (rbacToken) {
|
||||||
|
clientOptions.tokenProvider = async (): Promise<string> => {
|
||||||
|
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`;
|
||||||
|
const authorizationToken = `${AUTH_PREFIX}${rbacToken}`;
|
||||||
|
return authorizationToken;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
||||||
|
clientOptions.key = keys.primaryMasterKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new CosmosClient(clientOptions);
|
||||||
const { database } = await client.databases.createIfNotExists({ id: databaseId });
|
const { database } = await client.databases.createIfNotExists({ id: databaseId });
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -200,8 +158,29 @@ export async function createTestSQLContainer({
|
|||||||
}: createTestSqlContainerConfig = {}) {
|
}: createTestSqlContainerConfig = {}) {
|
||||||
const databaseId = databaseName ? databaseName : generateUniqueName("db");
|
const databaseId = databaseName ? databaseName : generateUniqueName("db");
|
||||||
const containerId = "testcontainer"; // A unique container name isn't needed because the database is unique
|
const containerId = "testcontainer"; // A unique container name isn't needed because the database is unique
|
||||||
const { armClient, client } = await createCosmosClientForSQLAccount();
|
const credentials = getAzureCLICredentials();
|
||||||
|
const adaptedCredentials = new AzureIdentityCredentialAdapter(credentials);
|
||||||
|
const armClient = new CosmosDBManagementClient(adaptedCredentials, subscriptionId);
|
||||||
|
const accountName = getAccountName(TestAccount.SQL);
|
||||||
|
const account = await armClient.databaseAccounts.get(resourceGroupName, accountName);
|
||||||
|
|
||||||
|
const clientOptions: CosmosClientOptions = {
|
||||||
|
endpoint: account.documentEndpoint!,
|
||||||
|
};
|
||||||
|
|
||||||
|
const nosqlAccountRbacToken = process.env.NOSQL_TESTACCOUNT_TOKEN;
|
||||||
|
if (nosqlAccountRbacToken) {
|
||||||
|
clientOptions.tokenProvider = async (): Promise<string> => {
|
||||||
|
const AUTH_PREFIX = `type=aad&ver=1.0&sig=`;
|
||||||
|
const authorizationToken = `${AUTH_PREFIX}${nosqlAccountRbacToken}`;
|
||||||
|
return authorizationToken;
|
||||||
|
};
|
||||||
|
} else {
|
||||||
|
const keys = await armClient.databaseAccounts.listKeys(resourceGroupName, accountName);
|
||||||
|
clientOptions.key = keys.primaryMasterKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
const client = new CosmosClient(clientOptions);
|
||||||
const { database } = await client.databases.createIfNotExists({ id: databaseId });
|
const { database } = await client.databases.createIfNotExists({ id: databaseId });
|
||||||
try {
|
try {
|
||||||
const { container } = await database.containers.createIfNotExists({
|
const { container } = await database.containers.createIfNotExists({
|
||||||
|
|||||||
Reference in New Issue
Block a user