Search in sources :

Example 6 with VideoUploadRequestEvent

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());
}
Also used : VideoUploader(com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader) ArrayList(java.util.ArrayList) VideoUploadRequestEvent(com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) VideoRecorder(com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder) PipedOutputStream(java.io.PipedOutputStream) Test(org.junit.jupiter.api.Test)

Aggregations

VideoUploadRequestEvent (com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent)6 EdgeConnectorForKVSConfiguration (com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 VideoRecorder (com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder)2 VideoUploader (com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader)2 PipedOutputStream (java.io.PipedOutputStream)2 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)1 EdgeConnectorForKVSUnrecoverableException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSUnrecoverableException)1 IOException (java.io.IOException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1