Skip to content

Commit

Permalink
debug AllTargetsArchivedRecordingsTable reading jvmId
Browse files Browse the repository at this point in the history
  • Loading branch information
aali309 committed Apr 18, 2024
1 parent 92bb13f commit 22b1b28
Show file tree
Hide file tree
Showing 6 changed files with 132 additions and 26 deletions.
4 changes: 2 additions & 2 deletions src/app/Archives/AllArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export const AllArchivedRecordingsTable: React.FC<AllArchivedRecordingsTableProp

const handleDirectoriesAndCounts = React.useCallback(
(directories: RecordingDirectory[]) => {
console.log("++API Response Data:", directories); // Log the fetched data to the console
//console.log("++API Response Data:", directories); // Log the fetched data to the console

setDirectories(directories.map((dir) => ({ ...dir, targetAsObs: of(getTargetFromDirectory(dir)) })));
setIsLoading(false);
Expand All @@ -97,7 +97,7 @@ export const AllArchivedRecordingsTable: React.FC<AllArchivedRecordingsTableProp

const handleError = React.useCallback(
(error) => {
console.error("++API Error:", error);
//console.error("++API Error:", error);

setIsLoading(false);
setErrorMessage(error.message);
Expand Down
12 changes: 11 additions & 1 deletion src/app/Archives/AllTargetsArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,15 +103,25 @@ export const AllTargetsArchivedRecordingsTable: React.FC<AllTargetsArchivedRecor
const handleNotification = React.useCallback(
(_: string, recording: ArchivedRecording, delta: number) => {
setArchivesForTargets((old) => {
console.log("+++recording", recording);
console.log("old2: ",JSON.stringify(old, null, 2));
const matchingTargets = old.filter(({ target }) => target.jvmId === recording.jvmId);
console.log("++Match2: ", matchingTargets);
console.log("+++target.jvmID2: ",target.jvmId);
console.log("+++recording.jvmID2: ",recording.jvmId);
for (const matchedTarget of matchingTargets) {
const targetIdx = old.findIndex(({ target }) => target.connectUrl === matchedTarget.target.connectUrl);
console.log("++Target: ",matchedTarget.target);

const targetIdx = old.findIndex(({ target }) => target.connectUrl === matchedTarget.target.connectUrl);
console.log("+++target.connectUrl2: ",matchedTarget.target.connectUrl);
console.log("+++recording.jvmID2: ",recording.jvmId);
const recordings = [...matchedTarget.recordings];
if (delta === 1) {
console.log("++ADDED2");
recordings.push(recording);
} else {
const recordingIdx = recordings.findIndex((r) => r.name === recording.name);
console.log("DELETED2");
recordings.splice(recordingIdx, 1);
}

Expand Down
20 changes: 19 additions & 1 deletion src/app/Recordings/ArchivedRecordingsTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,19 @@ export const ArchivedRecordingsTable: React.FC<ArchivedRecordingsTableProps> = (
const eventConnectUrlLabel = event.message.recording.metadata.labels.find(
(label) => label.key === 'connectUrl',
);

console.log("++delete current Target: ", currentTarget);
console.log("+++ delete event: ",event);
console.log("++delete event connect URL:", eventConnectUrlLabel);
const matchesUploadsUrlAndJvmId =
currentTarget?.connectUrl === 'uploads' && event.message.recording.jvmId === 'uploads';
console.log("++delete current TargetUrl: ", currentTarget?.connectUrl);
console.log("++ delete event Url: ", eventConnectUrlLabel?.value);

console.log("++ delete currentTarget jvmID: ", currentTarget.jvmId);
console.log("++ delete event jvmID: ", event.message.recording.jvmId);

if (isUploadsTable && matchesUploadsUrlAndJvmId) {
console.log("+++ is upload");
refreshRecordingList();
}
if (
Expand Down Expand Up @@ -371,6 +379,10 @@ export const ArchivedRecordingsTable: React.FC<ArchivedRecordingsTableProps> = (
propsTarget,
context.notificationChannel.messages(NotificationCategory.RecordingMetadataUpdated),
]).subscribe(([currentTarget, event]) => {
console.log("++current Target: ", currentTarget);
console.log("+++ event: ",event);
console.log("+++ event metadata labels: ", event.message.recording.metadata.labels);

const eventConnectUrlLabel = event.message.recording.metadata.labels.find(
(label) => label.key === 'connectUrl',
);
Expand All @@ -381,6 +393,12 @@ export const ArchivedRecordingsTable: React.FC<ArchivedRecordingsTableProps> = (
) {
return;
}
console.log("++current TargetUrl: ", currentTarget?.connectUrl);
console.log("++ event url: ", eventConnectUrlLabel?.value);

console.log("++ event jvmID: ", event.message.recording.jvmId);
console.log("++ currentTarget jvmID: ", currentTarget.jvmId);

setRecordings((oldRecordings) => {
return oldRecordings.map((recording) => {
if (recording.name === event.message.recording.name) {
Expand Down
64 changes: 60 additions & 4 deletions src/test/Archives/AllTargetsArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,12 @@ import { render, renderSnapshot } from '../utils';
const mockConnectUrl1 = 'service:jmx:rmi://someUrl1';
const mockAlias1 = 'fooTarget1';
const mockTarget1: Target = {
jvmId: 'foo',
connectUrl: mockConnectUrl1,
alias: mockAlias1,
jvmId: 'foo',
labels: [],
annotations: { cryostat: [], platform: [] },
recordings: [],
};
const mockConnectUrl2 = 'service:jmx:rmi://someUrl2';
const mockAlias2 = 'fooTarget2';
Expand All @@ -37,11 +38,12 @@ const mockAlias3 = 'fooTarget3';
const mockNewConnectUrl = 'service:jmx:rmi://someNewUrl';
const mockNewAlias = 'newTarget';
const mockNewTarget: Target = {
jvmId: 'foo',
connectUrl: mockNewConnectUrl,
alias: mockNewAlias,
jvmId: 'foo',
labels: [],
annotations: { cryostat: [], platform: [] },
recordings: [],
};
const mockCount1 = 1;
const mockCount2 = 3;
Expand All @@ -54,6 +56,20 @@ const mockTargetFoundNotification = {
},
} as NotificationMessage;

const mockRecording = {
jvmId: 'foo',
name: 'SampleRecording',
downloadUrl: 'http://downloadurl.com/sample',
reportUrl: 'http://reporturl.com/sample',
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
]
},
size: 1234,
archivedTime: 987654321
};

const mockTargetLostNotification = {
message: {
event: { kind: 'LOST', serviceRef: mockTarget1 },
Expand All @@ -62,7 +78,8 @@ const mockTargetLostNotification = {

const mockRecordingSavedNotification = {
message: {
target: mockConnectUrl3,
jvmId: mockConnectUrl3,
recording: mockRecording,
},
} as NotificationMessage;

Expand All @@ -79,7 +96,16 @@ const mockTargetsAndCountsResponse = {
target: {
alias: mockAlias1,
connectUrl: mockConnectUrl1,
jvmId: 'foo',
archivedRecordings: {
jvmId: 'foo',
name: 'fooRecording1',
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'connectUrl', value: 'service:jmx:rmi://someUrl1' }
]
},
aggregate: {
count: mockCount1,
},
Expand All @@ -90,7 +116,16 @@ const mockTargetsAndCountsResponse = {
target: {
alias: mockAlias2,
connectUrl: mockConnectUrl2,
jvmId: 'foo',
archivedRecordings: {
jvmId: 'foo',
name: 'fooRecording2',
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'connectUrl', value: 'service:jmx:rmi://someUrl2' }
]
},
aggregate: {
count: mockCount2,
},
Expand All @@ -101,7 +136,16 @@ const mockTargetsAndCountsResponse = {
target: {
alias: mockAlias3,
connectUrl: mockConnectUrl3,
jvmId: 'foo',
archivedRecordings: {
jvmId: 'foo',
name: 'fooRecording3',
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'connectUrl', value: 'service:jmx:rmi://someUrl3' }
]
},
aggregate: {
count: mockCount3,
},
Expand All @@ -111,13 +155,24 @@ const mockTargetsAndCountsResponse = {
],
},
};

console.log("++mock targets and count", JSON.stringify(mockTargetsAndCountsResponse, null, 2));
const mockNewTargetCountResponse = {
data: {
targetNodes: [
{
target: {
jvmId: 'foo',
connectUrl: mockNewConnectUrl,
alias: mockNewAlias,
archivedRecordings: {
jvmId: 'foo',
name: 'fooRecording1',
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'connectUrl', value: 'service:jmx:rmi://someUrl3' }
]
},
aggregate: {
count: mockNewCount,
},
Expand All @@ -127,6 +182,7 @@ const mockNewTargetCountResponse = {
],
},
};
console.log("++mock new target and count", JSON.stringify(mockNewTargetCountResponse, null, 2));

jest.mock('@app/Recordings/ArchivedRecordingsTable', () => {
return {
Expand Down
28 changes: 16 additions & 12 deletions src/test/RecordingMetadata/BulkEditLabels.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ const mockActiveRecording: ActiveRecording = {
const mockActiveLabelsNotification = {
message: {
target: mockConnectUrl,
recordingName: 'someActiveRecording',
jvmId: mockJvmId,
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'someNewLabel', value: 'someNewValue' },
recording: {
name: 'someActiveRecording',
jvmId: mockJvmId,
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'someNewLabel', value: 'someNewValue' },
],
},
},
},
} as NotificationMessage;

Expand All @@ -92,13 +94,15 @@ const mockActiveRecordingResponse = [mockActiveRecording];
const mockArchivedLabelsNotification = {
message: {
target: mockConnectUrl,
recordingName: 'someArchivedRecording_some_random',
jvmId: mockJvmId,
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'someNewLabel', value: 'someNewValue' },
recording: {
name: 'someArchivedRecording_some_random',
jvmId: mockJvmId,
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'someNewLabel', value: 'someNewValue' },
],
}
},
},
} as NotificationMessage;
Expand Down
30 changes: 24 additions & 6 deletions src/test/Recordings/ArchivedRecordingsTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,20 @@ mockMetadataFile.text = jest.fn(() =>

const mockRecording: ArchivedRecording = {
name: 'someRecording',
jvmId: mockJvmId,
downloadUrl: 'http://downloadUrl',
reportUrl: 'http://reportUrl',
metadata: { labels: mockRecordingLabels },
metadata: {
labels: [
{ key: 'someLabel', value: 'someValue' },
{ key: 'connectUrl', value: 'service:jmx:rmi://someUrl' }
]
},
size: 2048,
archivedTime: 2048,
};
console.log("++mockRecording", mockRecording);
console.log("++mockRecording Stringify", JSON.stringify(mockRecording, null, 2));

const mockArchivedRecordingsResponse = {
data: {
Expand All @@ -102,6 +110,7 @@ const mockArchivedRecordingsResponse = {
],
},
};
console.log("++mockRecording Response", mockArchivedRecordingsResponse);

const mockAllArchivedRecordingsResponse = {
data: {
Expand All @@ -114,6 +123,7 @@ const mockAllArchivedRecordingsResponse = {
},
},
};
console.log("++mockRecording All archived", mockAllArchivedRecordingsResponse);

const mockAnotherRecording = { ...mockRecording, name: 'anotherRecording' };
const mockCreateNotification = {
Expand All @@ -122,9 +132,11 @@ const mockCreateNotification = {
const mockLabelsNotification = {
message: {
target: mockConnectUrl,
recordingName: 'someRecording',
jvmId: mockJvmId,
metadata: { labels: [{ key: 'someLabel', value: 'someUpdatedValue' }] },
recording: {
name: 'someRecording',
jvmId: mockJvmId,
metadata: { labels: [{ key: 'someLabel', value: 'someUpdatedValue' }] },
}
},
} as NotificationMessage;
const mockDeleteNotification = {
Expand Down Expand Up @@ -276,11 +288,17 @@ describe('<ArchivedRecordingsTable />', () => {
expect(size).toBeInTheDocument();
expect(size).toBeVisible();

mockRecordingLabels.forEach((entry) => {
/* mockRecordingLabels.forEach((entry) => {
const label = screen.getByText(`${entry.key}: ${entry.value}`);
expect(label).toBeInTheDocument();
expect(label).toBeVisible();
});
}); */

for (const entry of mockRecordingLabels) {
const label = await screen.findByText(`${entry.key}: ${entry.value}`);
expect(label).toBeInTheDocument();
expect(label).toBeVisible();
}

const actionIcon = within(screen.getByLabelText(`${mockRecording.name}-actions`)).getByLabelText('Actions');
expect(actionIcon).toBeInTheDocument();
Expand Down

0 comments on commit 22b1b28

Please sign in to comment.