Skip to content

Commit

Permalink
test fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewazores committed Feb 8, 2022
1 parent 9aeb3c9 commit 59b5126
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
30 changes: 16 additions & 14 deletions src/main/java/io/cryostat/recordings/RecordingTargetHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,20 +263,22 @@ public Future<Void> deleteRecording(
CompletableFuture<Void> future = new CompletableFuture<>();
try {
String targetId = connectionDescriptor.getTargetId();
Void v = targetConnectionManager.executeConnectedTask(
connectionDescriptor,
connection -> {
Optional<IRecordingDescriptor> descriptor =
getDescriptorByName(connection, recordingName);
if (descriptor.isPresent()) {
connection.getService().close(descriptor.get());
reportService.delete(connectionDescriptor, recordingName);
this.cancelScheduledNotificationIfExists(targetId, recordingName);
} else {
throw new RecordingNotFoundException(targetId, recordingName);
}
return null;
});
Void v =
targetConnectionManager.executeConnectedTask(
connectionDescriptor,
connection -> {
Optional<IRecordingDescriptor> descriptor =
getDescriptorByName(connection, recordingName);
if (descriptor.isPresent()) {
connection.getService().close(descriptor.get());
reportService.delete(connectionDescriptor, recordingName);
this.cancelScheduledNotificationIfExists(
targetId, recordingName);
} else {
throw new RecordingNotFoundException(targetId, recordingName);
}
return null;
});
future.complete(v);
} catch (Exception e) {
future.completeExceptionally(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import io.cryostat.messaging.notifications.NotificationFactory;
import io.cryostat.net.ConnectionDescriptor;
import io.cryostat.net.web.http.HttpMimeType;
import io.cryostat.net.ConnectionDescriptor;
import io.cryostat.recordings.RecordingNotFoundException;
import io.cryostat.recordings.RecordingTargetHelper;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.openjdk.jmc.flightrecorder.configuration.recording.RecordingOptionsBuilder;
import org.openjdk.jmc.rjmx.services.jfr.IFlightRecorderService;
import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor;
import org.openjdk.jmc.rjmx.services.jfr.IRecordingDescriptor.RecordingState;

import io.cryostat.core.log.Logger;
import io.cryostat.core.net.JFRConnection;
Expand Down Expand Up @@ -516,11 +517,10 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Mockito.when(connection.getService()).thenReturn(service);
IRecordingDescriptor descriptor = Mockito.mock(IRecordingDescriptor.class);
Mockito.when(descriptor.getName()).thenReturn("someRecording");
Mockito.when(descriptor.getState()).thenReturn(RecordingState.RUNNING);
Mockito.when(service.getAvailableRecordings()).thenReturn(List.of(descriptor));

recordingTargetHelper
.stopRecording(new ConnectionDescriptor("fooTarget"), "someRecording")
.get();
recordingTargetHelper.stopRecording(new ConnectionDescriptor("fooTarget"), "someRecording");

Mockito.verify(service).stop(descriptor);
}
Expand All @@ -541,17 +541,15 @@ public Object answer(InvocationOnMock invocation) throws Throwable {
Mockito.when(connection.getService()).thenReturn(service);
Mockito.when(service.getAvailableRecordings()).thenReturn(List.of());

ExecutionException ee =
RecordingNotFoundException rnfe =
Assertions.assertThrows(
ExecutionException.class,
RecordingNotFoundException.class,
() ->
recordingTargetHelper
.stopRecording(
new ConnectionDescriptor("fooTarget"),
"someRecording")
.get());
recordingTargetHelper.stopRecording(
new ConnectionDescriptor("fooTarget"), "someRecording"));
MatcherAssert.assertThat(
ee.getCause(), Matchers.instanceOf(RecordingNotFoundException.class));
rnfe.getMessage(),
Matchers.equalTo("Recording someRecording not found in target fooTarget"));
}

private static IRecordingDescriptor createDescriptor(String name)
Expand Down

0 comments on commit 59b5126

Please sign in to comment.