You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ozone.apache.org by ch...@apache.org on 2026/10/16 15:29:28 UTC

(ozone) branch master updated: HDDS-9795. [Recon][UI][Test] Add tests for Disk Usage page (#11513)

This is an automated email from the ASF dual-hosted git repository.

chihsuan pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ozone.git


The following commit(s) were added to refs/heads/master by this push:
     new 3acb9805171 HDDS-9795. [Recon][UI][Test] Add tests for Disk Usage page (#11513)
3acb9805171 is described below

commit 3acb98051714be06317b822658ee336fb1bb5353
Author: sravani <14...@users.noreply.github.com>
AuthorDate: Fri Oct 16 20:59:21 2026 +0530

    HDDS-9795. [Recon][UI][Test] Add tests for Disk Usage page (#11513)
---
 .../namespaceUsageResponseMocks.ts                 | 223 +++++++++++++++++++
 .../namespaceUsageMocks/namespaceUsageServer.ts    | 100 +++++++++
 .../namespaceUsage/NamespaceUsage.test.tsx         | 235 +++++++++++++++++++++
 3 files changed, 558 insertions(+)

diff --git a/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/mocks/namespaceUsageMocks/namespaceUsageResponseMocks.ts b/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/mocks/namespaceUsageMocks/namespaceUsageResponseMocks.ts
new file mode 100644
index 00000000000..f954b4eac86
--- /dev/null
+++ b/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/mocks/namespaceUsageMocks/namespaceUsageResponseMocks.ts
@@ -0,0 +1,223 @@
+/*
+ * 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 { NUResponse } from '@/v2/types/namespaceUsage.types';
+
+export const RootNamespaceUsage: NUResponse = {
+  status: 'OK',
+  path: '/',
+  size: 10000,
+  sizeWithReplica: -1,
+  subPathCount: 2,
+  sizeDirectKey: -1,
+  subPaths: [
+    { path: '/vol1', size: 6000, sizeWithReplica: -1, isKey: false },
+    { path: '/vol2', size: 4000, sizeWithReplica: -1, isKey: false }
+  ]
+};
+
+export const Vol1NamespaceUsage: NUResponse = {
+  status: 'OK',
+  path: '/vol1',
+  size: 6000,
+  sizeWithReplica: -1,
+  subPathCount: 1,
+  sizeDirectKey: 0,
+  subPaths: [
+    { path: '/vol1/bucket1', size: 6000, sizeWithReplica: -1, isKey: false }
+  ]
+};
+
+export const Bucket1NamespaceUsage: NUResponse = {
+  status: 'OK',
+  path: '/vol1/bucket1',
+  size: 6000,
+  sizeWithReplica: -1,
+  subPathCount: 1,
+  sizeDirectKey: 3000,
+  subPaths: [
+    { path: '/vol1/bucket1/key1', size: 3000, sizeWithReplica: -1, isKey: true }
+  ]
+};
+
+export const Key1NamespaceUsage: NUResponse = {
+  status: 'OK',
+  path: '/vol1/bucket1/key1',
+  size: 3000,
+  sizeWithReplica: 9000,
+  subPathCount: 0,
+  sizeDirectKey: 3000,
+  subPaths: []
+};
+
+export const PathNotFoundUsage: NUResponse = {
+  status: 'PATH_NOT_FOUND',
+  path: '/missing',
+  size: 0,
+  sizeWithReplica: 0,
+  subPathCount: 0,
+  sizeDirectKey: 0,
+  subPaths: []
+};
+
+export const pathNotFoundUsage = (path: string): NUResponse => ({
+  ...PathNotFoundUsage,
+  path
+});
+
+export const InitializingUsage: NUResponse = {
+  status: 'INITIALIZING',
+  path: '/',
+  size: 0,
+  sizeWithReplica: 0,
+  subPathCount: 0,
+  sizeDirectKey: 0,
+  subPaths: []
+};
+
+export const InitializingSummaryResponse = {
+  status: 'INITIALIZING',
+  path: '/',
+  type: 'ROOT',
+  countStats: {
+    numVolume: 0,
+    numBucket: 0,
+    numDir: 0,
+    numKey: 0
+  },
+  objectInfo: {}
+};
+
+export const InitializingQuotaResponse = {
+  status: 'INITIALIZING'
+};
+
+export const RootSummaryResponse = {
+  status: 'OK',
+  path: '/',
+  type: 'ROOT',
+  countStats: {
+    numVolume: 2,
+    numBucket: 0,
+    numDir: 0,
+    numKey: 0
+  },
+  objectInfo: {}
+};
+
+export const Vol1SummaryResponse = {
+  status: 'OK',
+  path: '/vol1',
+  type: 'VOLUME',
+  countStats: {
+    numVolume: 0,
+    numBucket: 1,
+    numDir: 0,
+    numKey: 0
+  },
+  objectInfo: {
+    volumeName: 'vol1',
+    name: 'vol1'
+  }
+};
+
+export const Bucket1SummaryResponse = {
+  status: 'OK',
+  path: '/vol1/bucket1',
+  type: 'BUCKET',
+  countStats: {
+    numVolume: 0,
+    numBucket: 0,
+    numDir: 0,
+    numKey: 1
+  },
+  objectInfo: {
+    bucketName: 'bucket1',
+    volumeName: 'vol1',
+    name: 'bucket1',
+    bucketLayout: 'FILE_SYSTEM_OPTIMIZED',
+    owner: 'hdfs',
+    storageType: 'DISK',
+    usedNamespace: 1
+  }
+};
+
+export const Key1SummaryResponse = {
+  status: 'OK',
+  path: '/vol1/bucket1/key1',
+  type: 'KEY',
+  countStats: {
+    numVolume: 0,
+    numBucket: 0,
+    numDir: 0,
+    numKey: 0
+  },
+  objectInfo: {
+    keyName: 'key1',
+    fileName: 'key1',
+    bucketName: 'bucket1',
+    volumeName: 'vol1',
+    name: 'key1',
+    creationTime: 1673415921920,
+    modificationTime: 1673415921920
+  }
+};
+
+export const RootQuotaResponse = {
+  status: 'OK',
+  allowed: 10000,
+  used: 10000
+};
+
+export const Vol1QuotaResponse = {
+  status: 'OK',
+  allowed: 1073741824,
+  used: 6000
+};
+
+export const Bucket1QuotaResponse = {
+  status: 'OK',
+  allowed: 1073741824,
+  used: 6000
+};
+
+export const Key1QuotaResponse = {
+  status: 'TYPE_NOT_APPLICABLE'
+};
+
+export const PathNotFoundSummaryResponse = {
+  status: 'PATH_NOT_FOUND',
+  path: '/missing',
+  type: 'UNKNOWN',
+  countStats: {
+    numVolume: 0,
+    numBucket: 0,
+    numDir: 0,
+    numKey: 0
+  },
+  objectInfo: {}
+};
+
+export const PathNotFoundQuotaResponse = {
+  status: 'PATH_NOT_FOUND'
+};
+
+export const pathNotFoundSummary = (path: string) => ({
+  ...PathNotFoundSummaryResponse,
+  path
+});
diff --git a/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/mocks/namespaceUsageMocks/namespaceUsageServer.ts b/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/mocks/namespaceUsageMocks/namespaceUsageServer.ts
new file mode 100644
index 00000000000..c37a0a050cc
--- /dev/null
+++ b/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/mocks/namespaceUsageMocks/namespaceUsageServer.ts
@@ -0,0 +1,100 @@
+/*
+ * 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 { setupServer } from 'msw/node';
+import { http, HttpResponse } from 'msw';
+
+import * as mockResponses from './namespaceUsageResponseMocks';
+
+/** Paths from `path` query param on each intercepted usage request (for tests). */
+export const usagePathsRequested: string[] = [];
+
+export function resetNamespaceUsageRequestTracking(): void {
+  usagePathsRequested.length = 0;
+}
+
+const usageHandler = http.get('/api/v1/namespace/usage', ({ request }) => {
+  const url = new URL(request.url);
+  const path = url.searchParams.get('path') ?? '/';
+  usagePathsRequested.push(path);
+
+  if (path === '/missing') {
+    return HttpResponse.json(mockResponses.PathNotFoundUsage);
+  }
+  if (path === '/vol1/bucket1/key1') {
+    return HttpResponse.json(mockResponses.Key1NamespaceUsage);
+  }
+  if (path === '/vol1/bucket1') {
+    return HttpResponse.json(mockResponses.Bucket1NamespaceUsage);
+  }
+  if (path === '/vol1') {
+    return HttpResponse.json(mockResponses.Vol1NamespaceUsage);
+  }
+  if (path === '/') {
+    return HttpResponse.json(mockResponses.RootNamespaceUsage);
+  }
+  return HttpResponse.json(mockResponses.pathNotFoundUsage(path));
+});
+
+const summaryHandler = http.get('/api/v1/namespace/summary', ({ request }) => {
+  const url = new URL(request.url);
+  const path = url.searchParams.get('path') ?? '/';
+  if (path === '/missing') {
+    return HttpResponse.json(mockResponses.PathNotFoundSummaryResponse);
+  }
+  if (path === '/vol1/bucket1/key1') {
+    return HttpResponse.json(mockResponses.Key1SummaryResponse);
+  }
+  if (path === '/vol1/bucket1') {
+    return HttpResponse.json(mockResponses.Bucket1SummaryResponse);
+  }
+  if (path === '/vol1') {
+    return HttpResponse.json(mockResponses.Vol1SummaryResponse);
+  }
+  if (path === '/') {
+    return HttpResponse.json(mockResponses.RootSummaryResponse);
+  }
+  return HttpResponse.json(mockResponses.pathNotFoundSummary(path));
+});
+
+const quotaHandler = http.get('/api/v1/namespace/quota', ({ request }) => {
+  const url = new URL(request.url);
+  const path = url.searchParams.get('path') ?? '/';
+  if (path === '/missing') {
+    return HttpResponse.json(mockResponses.PathNotFoundQuotaResponse);
+  }
+  if (path === '/vol1/bucket1/key1') {
+    return HttpResponse.json(mockResponses.Key1QuotaResponse);
+  }
+  if (path === '/vol1/bucket1') {
+    return HttpResponse.json(mockResponses.Bucket1QuotaResponse);
+  }
+  if (path === '/vol1') {
+    return HttpResponse.json(mockResponses.Vol1QuotaResponse);
+  }
+  if (path === '/') {
+    return HttpResponse.json(mockResponses.RootQuotaResponse);
+  }
+  return HttpResponse.json(mockResponses.PathNotFoundQuotaResponse);
+});
+
+export const namespaceUsageServer = setupServer(
+  usageHandler,
+  summaryHandler,
+  quotaHandler
+);
diff --git a/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/namespaceUsage/NamespaceUsage.test.tsx b/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/namespaceUsage/NamespaceUsage.test.tsx
new file mode 100644
index 00000000000..f9d0d9e0c1d
--- /dev/null
+++ b/hadoop-ozone/recon/src/main/resources/webapps/recon/ozone-recon-web/src/__tests__/namespaceUsage/NamespaceUsage.test.tsx
@@ -0,0 +1,235 @@
+/*
+ * 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 React from 'react';
+import { fireEvent, render, screen, waitFor, within } from '@testing-library/react';
+import userEvent from '@testing-library/user-event';
+import { http, HttpResponse } from 'msw';
+import { vi } from 'vitest';
+
+import NamespaceUsage from '@/v2/pages/namespaceUsage/namespaceUsage';
+import * as commonUtils from '@/utils/common';
+import {
+  namespaceUsageServer,
+  resetNamespaceUsageRequestTracking,
+  usagePathsRequested
+} from '@tests/mocks/namespaceUsageMocks/namespaceUsageServer';
+import * as mockResponses from '@tests/mocks/namespaceUsageMocks/namespaceUsageResponseMocks';
+
+vi.spyOn(commonUtils, 'showDataFetchError');
+vi.spyOn(commonUtils, 'showInfoNotification');
+
+vi.mock('@/v2/components/eChart/eChart', () => ({
+  default: () => <div data-testid="nu-echart" />
+}));
+
+vi.mock('@/v2/hooks/useAPIData.hook', async (importOriginal) => {
+  const actual = await importOriginal<typeof import('@/v2/hooks/useAPIData.hook')>();
+  return {
+    ...actual,
+    useApiData: <T,>(url: string, defaultValue: T, options = {}) =>
+      actual.useApiData(url, defaultValue, {
+        ...options,
+        retryAttempts: 0,
+        retryDelay: 0
+      })
+  };
+});
+
+describe('Namespace Usage page (Disk Usage)', () => {
+  beforeAll(() => namespaceUsageServer.listen());
+
+  beforeEach(() => {
+    resetNamespaceUsageRequestTracking();
+    vi.mocked(commonUtils.showDataFetchError).mockClear();
+    vi.mocked(commonUtils.showInfoNotification).mockClear();
+  });
+
+  afterEach(() => namespaceUsageServer.resetHandlers());
+  afterAll(() => namespaceUsageServer.close());
+
+  const rootUsageRequestCount = () =>
+    usagePathsRequested.filter((path) => path === '/').length;
+
+  // Give any request fired on render/click a chance to reach the mock server before asserting none was sent.
+  const flushPendingRequests = () => new Promise((resolve) => setTimeout(resolve, 50));
+
+  const confirmRootLoad = async () => {
+    fireEvent.click(screen.getByRole('button', { name: 'Load usage' }));
+    expect(screen.getByText('Confirm Root Path Usage Load')).toBeInTheDocument();
+    const modal = document.querySelector('.ant-modal') as HTMLElement;
+    await userEvent.click(within(modal).getByRole('button', { name: /^ok$/i }));
+  };
+
+  const openBreadcrumbMenu = async () => {
+    const trigger = document.querySelector('.ant-breadcrumb-overlay-link') as HTMLElement;
+    await userEvent.click(trigger);
+  };
+
+  const waitForMetadataEntityType = async (entityType: string) => {
+    const metadataTable = screen.getByRole('table');
+    await waitFor(() => {
+      const entityTypeRow = within(metadataTable).getByText('Entity Type').closest('tr');
+      expect(entityTypeRow).toHaveTextContent(entityType);
+    });
+    return metadataTable;
+  };
+
+  const metadataValueCell = (table: HTMLElement, propertyLabel: string) => {
+    const row = within(table).getByText(propertyLabel).closest('tr');
+    expect(row).not.toBeNull();
+    return row!.querySelectorAll('td')[1];
+  };
+
+  const clickBreadcrumbSubmenuItem = async (label: string) => {
+    await openBreadcrumbMenu();
+    const menu = await screen.findByRole('menu');
+    await userEvent.click(within(menu).getByRole('menuitem', { name: label }));
+  };
+
+  const searchPathFromBreadcrumb = async (pathSegment: string) => {
+    await openBreadcrumbMenu();
+    const menu = await screen.findByRole('menu');
+    const searchInput = within(menu).getByPlaceholderText('Enter Path');
+    await userEvent.type(searchInput, pathSegment);
+    const searchButton = searchInput
+      .closest('.ant-input-search')
+      ?.querySelector('button.ant-input-search-button') as HTMLButtonElement;
+    await userEvent.click(searchButton);
+  };
+
+  test('does not fetch root usage until the user confirms load', async () => {
+    render(<NamespaceUsage />);
+
+    expect(screen.getByText('Namespace Usage')).toBeInTheDocument();
+    expect(screen.getByText(/Root path usage is not loaded by default/i)).toBeInTheDocument();
+
+    await flushPendingRequests();
+    expect(usagePathsRequested).toEqual([]);
+
+    await confirmRootLoad();
+
+    await waitFor(() => {
+      expect(rootUsageRequestCount()).toBe(1);
+    });
+    expect(usagePathsRequested).toContain('/');
+    await waitFor(() => {
+      expect(screen.queryByText(/Root path usage is not loaded by default/i)).not.toBeInTheDocument();
+    });
+
+    const metadataTable = await waitForMetadataEntityType('ROOT');
+    expect(metadataValueCell(metadataTable, 'Volumes')).toHaveTextContent(/^2$/);
+  });
+
+  test('navigates to a child path via breadcrumb submenu', async () => {
+    render(<NamespaceUsage />);
+    await confirmRootLoad();
+    await waitForMetadataEntityType('ROOT');
+
+    await clickBreadcrumbSubmenuItem('vol1');
+
+    await waitFor(() =>
+      expect(screen.queryByText(/Root path usage can be expensive/i)).not.toBeInTheDocument()
+    );
+    const metadataTable = await waitForMetadataEntityType('VOLUME');
+    const nameRow = within(metadataTable).getByText('Name').closest('tr');
+    expect(nameRow).toHaveTextContent('vol1');
+    const volumeNameRow = within(metadataTable).getByText('Volume Name').closest('tr');
+    expect(volumeNameRow).toHaveTextContent('vol1');
+    expect(metadataValueCell(metadataTable, 'Buckets')).toHaveTextContent(/^1$/);
+  });
+
+  test('navigates to a key path via breadcrumb search', async () => {
+    render(<NamespaceUsage />);
+    await confirmRootLoad();
+    await waitForMetadataEntityType('ROOT');
+
+    await clickBreadcrumbSubmenuItem('vol1');
+    await waitForMetadataEntityType('VOLUME');
+
+    await clickBreadcrumbSubmenuItem('bucket1');
+    await waitForMetadataEntityType('BUCKET');
+
+    await searchPathFromBreadcrumb('key1');
+
+    const keyMetadataTable = await waitForMetadataEntityType('KEY');
+    const fileSizeRow = within(keyMetadataTable).getByText('File Size').closest('tr');
+    expect(fileSizeRow).toHaveTextContent('2.93 KB');
+  });
+
+  test('prompts before reloading root from home and cancel does not refetch root usage', async () => {
+    render(<NamespaceUsage />);
+    await confirmRootLoad();
+    await clickBreadcrumbSubmenuItem('vol1');
+    await waitForMetadataEntityType('VOLUME');
+
+    const usagePathsBeforeHome = [...usagePathsRequested];
+    const rootUsageBeforeHome = rootUsageRequestCount();
+
+    await userEvent.click(
+      document.querySelector('#breadcrumb-container .anticon-home') as HTMLElement
+    );
+    expect(screen.getByText('Confirm Root Path Usage Load')).toBeInTheDocument();
+
+    const modal = document.querySelector('.ant-modal') as HTMLElement;
+    await userEvent.click(within(modal).getByRole('button', { name: /cancel/i }));
+
+    await flushPendingRequests();
+    expect(rootUsageRequestCount()).toBe(rootUsageBeforeHome);
+    expect(usagePathsRequested).toEqual(usagePathsBeforeHome);
+  });
+
+  test('shows error and clears metadata when path is not found', async () => {
+    render(<NamespaceUsage />);
+    await confirmRootLoad();
+    const metadataTable = await waitForMetadataEntityType('ROOT');
+    expect(within(metadataTable).getByText('Volumes')).toBeInTheDocument();
+
+    await searchPathFromBreadcrumb('missing');
+
+    await waitFor(() =>
+      expect(commonUtils.showDataFetchError).toHaveBeenCalledWith('Invalid Path: /missing')
+    );
+    await waitFor(() => {
+      const table = screen.getByRole('table');
+      expect(within(table).queryByText('Entity Type')).not.toBeInTheDocument();
+      expect(within(table).queryByText('Volumes')).not.toBeInTheDocument();
+    });
+  });
+
+  test('notifies when namespace summary is still initializing', async () => {
+    namespaceUsageServer.use(
+      http.get('/api/v1/namespace/usage', () =>
+        HttpResponse.json(mockResponses.InitializingUsage)),
+      http.get('/api/v1/namespace/summary', () =>
+        HttpResponse.json(mockResponses.InitializingSummaryResponse)),
+      http.get('/api/v1/namespace/quota', () =>
+        HttpResponse.json(mockResponses.InitializingQuotaResponse))
+    );
+
+    render(<NamespaceUsage />);
+    await confirmRootLoad();
+
+    await waitFor(() =>
+      expect(commonUtils.showInfoNotification).toHaveBeenCalledWith(
+        'Information being initialized',
+        expect.stringContaining('Namespace Summary is being initialized')
+      )
+    );
+  });
+});


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@ozone.apache.org
For additional commands, e-mail: commits-help@ozone.apache.org