Search in sources :

Example 6 with VideoUploader

use of com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class EdgeConnectorForKVSServiceTest method test_cleanUp_singleCamera_happyCase.

@Test
public void test_cleanUp_singleCamera_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);
    // 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);
    Thread.sleep(3000);
    assertEquals(1, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
    assertEquals(1, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
    edgeConnectorForKVSService.cleanUpEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
    // verify
    assertEquals(0, edgeConnectorForKVSConfiguration.getLiveStreamingRequestsCount());
    assertEquals(0, edgeConnectorForKVSConfiguration.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)

Example 7 with VideoUploader

use of com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class EdgeConnectorForKVSServiceTest method testInitVideoUploaders.

@Test
public void testInitVideoUploaders(@TempDir Path tempDir) throws IOException, InterruptedException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    VideoRecorder videoRecorder = Mockito.mock(VideoRecorder.class);
    VideoUploader videoUploader = Mockito.mock(VideoUploader.class);
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = Mockito.spy(EdgeConnectorForKVSConfiguration.class);
    when(edgeConnectorForKVSConfiguration.getKinesisVideoStreamName()).thenReturn(MOCK_KINESIS_VIDEO_STREAM_NAME);
    when(edgeConnectorForKVSConfiguration.getLiveStreamingStartTime()).thenReturn(START_TIME_ALWAYS);
    when(edgeConnectorForKVSConfiguration.getCaptureStartTime()).thenReturn("");
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoRecorder(any());
    when(edgeConnectorForKVSConfiguration.getVideoRecordFolderPath()).thenReturn(tempDir);
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoUploader(any());
    when(edgeConnectorForKVSConfiguration.getVideoRecorder()).thenReturn(videoRecorder);
    when(edgeConnectorForKVSConfiguration.getVideoUploader()).thenReturn(videoUploader);
    when(edgeConnectorForKVSConfiguration.getRecordingRequestsCount()).thenReturn(2);
    edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
    doThrow(new RuntimeException()).when(videoUploader).uploadStream(any(), any(), any(), any());
    // Mock for initConfiguration
    when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
    // Mock for initSecretsManager
    when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
    // then
    edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
    edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
    Thread.sleep(2000);
    // verify
    verify(videoUploader, atLeastOnce()).uploadStream(any(), any(), any(), any());
}
Also used : VideoUploader(com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader) ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) VideoRecorder(com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder) Test(org.junit.jupiter.api.Test)

Example 8 with VideoUploader

use of com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader 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)

Example 9 with VideoUploader

use of com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class EdgeConnectorForKVSServiceTest method testInitVideoUploaders_ThrowKvsStreamingException.

@Test
public void testInitVideoUploaders_ThrowKvsStreamingException(@TempDir Path tempDir) throws IOException, InterruptedException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    VideoRecorder videoRecorder = Mockito.mock(VideoRecorder.class);
    VideoUploader videoUploader = Mockito.mock(VideoUploader.class);
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = Mockito.spy(EdgeConnectorForKVSConfiguration.class);
    when(edgeConnectorForKVSConfiguration.getKinesisVideoStreamName()).thenReturn(MOCK_KINESIS_VIDEO_STREAM_NAME);
    when(edgeConnectorForKVSConfiguration.getLiveStreamingStartTime()).thenReturn(START_TIME_ALWAYS);
    when(edgeConnectorForKVSConfiguration.getCaptureStartTime()).thenReturn("");
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoRecorder(any());
    when(edgeConnectorForKVSConfiguration.getVideoRecordFolderPath()).thenReturn(tempDir);
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoUploader(any());
    when(edgeConnectorForKVSConfiguration.getVideoRecorder()).thenReturn(videoRecorder);
    when(edgeConnectorForKVSConfiguration.getVideoUploader()).thenReturn(videoUploader);
    when(edgeConnectorForKVSConfiguration.getRecordingRequestsCount()).thenReturn(2);
    edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
    doThrow(new KvsStreamingException("")).doThrow(new RuntimeException()).when(videoUploader).uploadStream(any(), any(), any(), any());
    // Mock for initConfiguration
    when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
    // Mock for initSecretsManager
    when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
    EdgeConnectorForKVSService service = EdgeConnectorForKVSService.builder().regionName(MOCK_REGION_NAME).siteWiseClient(siteWiseClient).siteWiseManager(siteWiseManager).secretsClient(secretsClient).kvsClient(kvsClient).awsCredentialsProviderV1(awsCredentialsProvider).videoRecordingRootPath(tempDir.toString()).streamManagerBuilder(streamManagerBuilder).videoUploadRequestHandler(videoUploadRequestHandler).retryOnFail(false).build();
    // then
    service.setUpSharedEdgeConnectorForKVSService();
    service.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
    Thread.sleep(2000);
    // verify
    verify(videoUploader, atLeast(1)).uploadStream(any(), any(), any(), any());
}
Also used : KvsStreamingException(com.aws.iot.edgeconnectorforkvs.videouploader.model.exceptions.KvsStreamingException) VideoUploader(com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader) ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) VideoRecorder(com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder) Test(org.junit.jupiter.api.Test)

Example 10 with VideoUploader

use of com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class EdgeConnectorForKVSServiceTest method test_StopLiveVideoStreaming_JobStop.

@Test
public void test_StopLiveVideoStreaming_JobStop(@TempDir Path tempDir) throws IOException, InterruptedException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    VideoRecorder videoRecorder = Mockito.mock(VideoRecorder.class);
    VideoUploader videoUploader = Mockito.mock(VideoUploader.class);
    PipedInputStream pipedInputStream = Mockito.mock(PipedInputStream.class);
    PipedOutputStream pipedOutputStream = Mockito.mock(PipedOutputStream.class);
    doNothing().when(videoUploader).close();
    doNothing().when(pipedOutputStream).flush();
    doNothing().when(pipedOutputStream).close();
    doNothing().when(pipedInputStream).close();
    doNothing().when(videoRecorder).stopRecording();
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = Mockito.spy(EdgeConnectorForKVSConfiguration.class);
    when(edgeConnectorForKVSConfiguration.getKinesisVideoStreamName()).thenReturn(MOCK_KINESIS_VIDEO_STREAM_NAME);
    when(edgeConnectorForKVSConfiguration.getLiveStreamingStartTime()).thenReturn(START_TIME_ALWAYS);
    when(edgeConnectorForKVSConfiguration.getCaptureStartTime()).thenReturn(START_TIME_ALWAYS);
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoRecorder(any());
    when(edgeConnectorForKVSConfiguration.getVideoRecorder()).thenReturn(videoRecorder);
    when(edgeConnectorForKVSConfiguration.getVideoRecordFolderPath()).thenReturn(tempDir);
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoUploader(any());
    when(edgeConnectorForKVSConfiguration.getVideoUploader()).thenReturn(videoUploader);
    when(edgeConnectorForKVSConfiguration.getRecordingRequestsCount()).thenReturn(1);
    doNothing().when(edgeConnectorForKVSConfiguration).setInputStream(any());
    when(edgeConnectorForKVSConfiguration.getInputStream()).thenReturn(pipedInputStream);
    doNothing().when(edgeConnectorForKVSConfiguration).setOutputStream(any());
    when(edgeConnectorForKVSConfiguration.getOutputStream()).thenReturn(pipedOutputStream);
    edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
    // Mock for initConfiguration
    when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
    // Mock for initSecretsManager
    when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
    // then
    edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
    edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
    Thread.sleep(2000);
    edgeConnectorForKVSService.schedulerStopTaskCallback(Constants.JobType.LIVE_VIDEO_STREAMING, MOCK_KINESIS_VIDEO_STREAM_NAME);
    Thread.sleep(1000);
    // verify
    assertEquals(0, edgeConnectorForKVSConfigurationList.get(0).getLiveStreamingRequestsCount());
}
Also used : VideoUploader(com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader) ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) VideoRecorder(com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder) PipedOutputStream(java.io.PipedOutputStream) PipedInputStream(java.io.PipedInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

VideoUploader (com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader)11 VideoRecorder (com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder)10 EdgeConnectorForKVSConfiguration (com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)8 ArrayList (java.util.ArrayList)8 Test (org.junit.jupiter.api.Test)8 PipedOutputStream (java.io.PipedOutputStream)6 ReentrantLock (java.util.concurrent.locks.ReentrantLock)5 PipedInputStream (java.io.PipedInputStream)4 VideoUploadRequestEvent (com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent)2 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)2 EdgeConnectorForKVSUnrecoverableException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSUnrecoverableException)2 StatusChangedCallBack (com.aws.iot.edgeconnectorforkvs.videouploader.callback.StatusChangedCallBack)2 UploadCallBack (com.aws.iot.edgeconnectorforkvs.videouploader.callback.UploadCallBack)2 KvsStreamingException (com.aws.iot.edgeconnectorforkvs.videouploader.model.exceptions.KvsStreamingException)2 IOException (java.io.IOException)2 Date (java.util.Date)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1