use of com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.
the class EdgeConnectorForKVSServiceTest method test_cleanUp_allCameras_happyCase.
@Test
public void test_cleanUp_allCameras_happyCase(@TempDir Path tempDir) throws IOException, InterruptedException {
// mock
List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
VideoRecorder videoRecorder = Mockito.mock(VideoRecorder.class);
VideoUploader videoUploader = Mockito.mock(VideoUploader.class);
PipedOutputStream pipedOutputStream = Mockito.mock(PipedOutputStream.class);
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).captureStartTime(START_TIME_NEVER).liveStreamingStartTime(START_TIME_NEVER).videoUploadRequestMqttTopic(VIDEO_UPLOAD_REQUEST_MQTT_TOPIC).videoRecordFolderPath(tempDir).recordingRequestsCount(0).liveStreamingRequestsCount(0).videoRecorder(videoRecorder).build();
edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
// Add another one
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration2 = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME + "RESTART_TEST").captureStartTime(START_TIME_NEVER).liveStreamingStartTime(START_TIME_NEVER).videoUploadRequestMqttTopic(VIDEO_UPLOAD_REQUEST_MQTT_TOPIC).videoRecordFolderPath(tempDir).recordingRequestsCount(0).liveStreamingRequestsCount(0).videoRecorder(videoRecorder).build();
edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration2);
// when
// Mock for initConfiguration
when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
// Mock for initSecretsManager
when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
doNothing().when(videoUploader).close();
doNothing().when(pipedOutputStream).flush();
doNothing().when(pipedOutputStream).close();
doNothing().when(videoRecorder).stopRecording();
when(videoRecorder.getStatus()).thenReturn(RecorderStatus.STOPPED);
doAnswer(invocationOnMock -> {
VideoUploadRequestEvent event = invocationOnMock.getArgument(1);
event.onStart(IS_LIVE_TRUE, EVENT_TIMESTAMP, START_TIME, END_TIME);
return null;
}).when(videoUploadRequestHandler).subscribeToMqttTopic(any(), any());
// then
edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration2);
Thread.sleep(3000);
assertEquals(1, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
assertEquals(1, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
assertEquals(1, edgeConnectorForKVSConfiguration2.getLiveStreamingRequestsCount());
assertEquals(1, edgeConnectorForKVSConfiguration2.getRecordingRequestsCount());
// This will clean up for all cameras
edgeConnectorForKVSService.cleanUpEdgeConnectorForKVSService(null);
// verify
assertEquals(0, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
assertEquals(0, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
assertEquals(0, edgeConnectorForKVSConfiguration2.getLiveStreamingRequestsCount());
assertEquals(0, edgeConnectorForKVSConfiguration2.getRecordingRequestsCount());
}
Aggregations