Skip to content

Commit

Permalink
fix recording tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mwangggg committed Oct 2, 2023
1 parent 1929840 commit 5b420e7
Showing 1 changed file with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,16 @@ void setup() {
lenient().when(notificationBuilder.message(Mockito.any())).thenReturn(notificationBuilder);
lenient().when(notificationBuilder.build()).thenReturn(notification);
lenient().when(vertx.setTimer(Mockito.anyLong(), Mockito.any())).thenReturn(1234L);
lenient()
.when(jvmIdHelper.jvmIdToSubdirectoryName(Mockito.anyString()))
.thenAnswer(
new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(0);
}
});

this.recordingTargetHelper =
new RecordingTargetHelper(
vertx,
Expand Down Expand Up @@ -199,6 +209,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}
});

Mockito.when(jvmIdHelper.getJvmId(Mockito.anyString())).thenReturn("id");
Mockito.when(connection.getService()).thenReturn(service);
IRecordingDescriptor descriptor = createDescriptor(recordingName);
Mockito.when(service.getAvailableRecordings()).thenReturn(List.of(descriptor));
Expand Down Expand Up @@ -227,7 +238,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingDeleted");
Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON);
Mockito.verify(notificationBuilder)
.message(Map.of("recording", linkedDesc, "target", "fooTarget"));
.message(Map.of("recording", linkedDesc, "target", "fooTarget", "jvmId", "id"));
Mockito.verify(notificationBuilder).build();
Mockito.verify(notification).send();
}
Expand All @@ -249,6 +260,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}
});

Mockito.when(jvmIdHelper.getJvmId(Mockito.anyString())).thenReturn("id");
Mockito.when(connection.getService()).thenReturn(service);
IRecordingDescriptor descriptor = createDescriptor(recordingName);
Mockito.when(service.getAvailableRecordings()).thenReturn(List.of(descriptor));
Expand Down Expand Up @@ -277,7 +289,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Mockito.verify(notificationBuilder).metaCategory("SnapshotDeleted");
Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON);
Mockito.verify(notificationBuilder)
.message(Map.of("recording", linkedDesc, "target", "fooTarget"));
.message(Map.of("recording", linkedDesc, "target", "fooTarget", "jvmId", "id"));
Mockito.verify(notificationBuilder).build();
Mockito.verify(notification).send();
}
Expand Down Expand Up @@ -314,6 +326,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}
});

Mockito.when(jvmIdHelper.getJvmId(Mockito.anyString())).thenReturn("id");
Mockito.when(connection.getService()).thenReturn(service);
IRecordingDescriptor descriptor = createDescriptor(recordingName);
Mockito.when(service.getAvailableRecordings()).thenReturn(List.of(descriptor));
Expand Down Expand Up @@ -351,6 +364,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
}
});

Mockito.when(jvmIdHelper.getJvmId(Mockito.anyString())).thenReturn("id");
Mockito.when(connection.getService()).thenReturn(service);
IRecordingDescriptor descriptor = createDescriptor(recordingName);
Mockito.when(service.getAvailableRecordings()).thenReturn(List.of(descriptor));
Expand Down Expand Up @@ -517,6 +531,7 @@ void shouldVerifySnapshotWithNotification() throws Exception {
new Random(123456).nextBytes(src);
InputStream snapshot = new ByteArrayInputStream(src);
Mockito.when(snapshotOptional.get()).thenReturn(snapshot);
Mockito.when(jvmIdHelper.getJvmId(Mockito.anyString())).thenReturn("id");

Mockito.when(targetConnectionManager.markConnectionInUse(connectionDescriptor))
.thenReturn(true);
Expand All @@ -537,7 +552,7 @@ void shouldVerifySnapshotWithNotification() throws Exception {
Mockito.verify(notificationBuilder).metaCategory("SnapshotCreated");
Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON);
Mockito.verify(notificationBuilder)
.message(Map.of("recording", snapshotDescriptor, "target", "fooTarget"));
.message(Map.of("recording", snapshotDescriptor, "target", "fooTarget", "jvmId", "id"));
Mockito.verify(notificationBuilder).build();
Mockito.verify(notification).send();

Expand Down Expand Up @@ -704,6 +719,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {

Mockito.when(recordingOptions.get(Mockito.any())).thenReturn(recordingName, duration);

Mockito.when(jvmIdHelper.getJvmId(targetId)).thenReturn("id");
Mockito.when(connection.getService()).thenReturn(service);
Mockito.when(service.getAvailableRecordings())
.thenReturn(Collections.emptyList(), List.of(recordingDescriptor));
Expand Down Expand Up @@ -856,6 +872,7 @@ void shouldCloseAndRecreateIfRecordingExistsAndIsRunning() throws Exception {
Metadata metadata =
new Metadata(Map.of("template.name", "Profiling", "template.type", "TARGET"));

Mockito.when(jvmIdHelper.getJvmId(targetId)).thenReturn("id");
Mockito.when(targetConnectionManager.executeConnectedTask(Mockito.any(), Mockito.any()))
.thenAnswer(
invocation -> {
Expand Down Expand Up @@ -910,6 +927,7 @@ void shouldRestartRecordingWhenRecordingExistsAndIsStopped() throws Exception {
Metadata metadata =
new Metadata(Map.of("template.name", "Profiling", "template.type", "TARGET"));

Mockito.when(jvmIdHelper.getJvmId(targetId)).thenReturn("id");
Mockito.when(targetConnectionManager.executeConnectedTask(Mockito.any(), Mockito.any()))
.thenAnswer(
invocation -> {
Expand Down Expand Up @@ -966,6 +984,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
return task.execute(connection);
}
});
Mockito.when(jvmIdHelper.getJvmId(Mockito.anyString())).thenReturn("id");
Mockito.when(connection.getService()).thenReturn(service);
IRecordingDescriptor descriptor = createDescriptor("someRecording");
Mockito.when(descriptor.getName()).thenReturn("someRecording");
Expand All @@ -984,7 +1003,7 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Mockito.verify(notificationBuilder).metaCategory("ActiveRecordingStopped");
Mockito.verify(notificationBuilder).metaType(HttpMimeType.JSON);
Mockito.verify(notificationBuilder)
.message(Map.of("recording", linkedDesc, "target", "fooTarget"));
.message(Map.of("recording", linkedDesc, "target", "fooTarget", "jvmId", "id"));
Mockito.verify(notificationBuilder).build();
Mockito.verify(notification).send();
}
Expand Down

0 comments on commit 5b420e7

Please sign in to comment.