Search in sources :

Example 26 with EdgeConnectorForKVSConfiguration

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

the class EdgeConnectorForKVSServiceTest method testInitVideoUploaders_ThrowKvsStreamingException_ThenGetProcessLockTimeout.

@Test
public void testInitVideoUploaders_ThrowKvsStreamingException_ThenGetProcessLockTimeout(@TempDir Path tempDir) throws IOException, InterruptedException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    VideoRecorder videoRecorder = Mockito.mock(VideoRecorder.class);
    VideoUploader videoUploader = Mockito.mock(VideoUploader.class);
    ReentrantLock processLock = Mockito.mock(ReentrantLock.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);
    doNothing().when(edgeConnectorForKVSConfiguration).setProcessLock(any());
    when(edgeConnectorForKVSConfiguration.getProcessLock()).thenReturn(processLock);
    when(processLock.tryLock(anyLong(), any())).thenReturn(false);
    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());
    assertTrue(edgeConnectorForKVSConfiguration.getFatalStatus().get());
    assertFalse(edgeConnectorForKVSConfiguration.getProcessLock().isLocked());
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) 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 27 with EdgeConnectorForKVSConfiguration

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

the class EdgeConnectorForKVSServiceTest method test_StopLiveVideoStreaming_InterruptedException.

@Test
public void test_StopLiveVideoStreaming_InterruptedException(@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();
    ReentrantLock processLock = Mockito.mock(ReentrantLock.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(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);
    doNothing().when(edgeConnectorForKVSConfiguration).setProcessLock(any());
    when(edgeConnectorForKVSConfiguration.getProcessLock()).thenReturn(processLock);
    when(processLock.tryLock(anyLong(), any())).thenThrow(new InterruptedException());
    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(true, edgeConnectorForKVSConfiguration.getFatalStatus().get());
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) 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)

Example 28 with EdgeConnectorForKVSConfiguration

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

the class EdgeConnectorForKVSServiceTest method testInitSecretsManager.

@Test
public void testInitSecretsManager(@TempDir Path tempDir) throws IOException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).liveStreamingStartTime(LIVE_STREAMING_START_TIME).liveStreamingDurationInMinutes(LIVE_STREAMING_DURATION_IN_MINUTES).videoRecordFolderPath(tempDir).build();
    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);
    // verify
    assertEquals(MOCK_RTSP_STREAM_URL, edgeConnectorForKVSConfigurationList.get(0).getRtspStreamURL());
}
Also used : ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Test(org.junit.jupiter.api.Test)

Example 29 with EdgeConnectorForKVSConfiguration

use of com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration 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 30 with EdgeConnectorForKVSConfiguration

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

Aggregations

EdgeConnectorForKVSConfiguration (com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)51 Test (org.junit.jupiter.api.Test)39 ArrayList (java.util.ArrayList)37 ReentrantLock (java.util.concurrent.locks.ReentrantLock)12 VideoRecorder (com.aws.iot.edgeconnectorforkvs.videorecorder.VideoRecorder)8 VideoUploader (com.aws.iot.edgeconnectorforkvs.videouploader.VideoUploader)8 TestWatchEventCallBack (com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack)5 VideoUploadRequestEvent (com.aws.iot.edgeconnectorforkvs.handler.VideoUploadRequestEvent)5 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)5 PipedOutputStream (java.io.PipedOutputStream)5 WatchEvent (java.nio.file.WatchEvent)5 IOException (java.io.IOException)4 EdgeConnectorForKVSUnrecoverableException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSUnrecoverableException)3 PipedInputStream (java.io.PipedInputStream)3 KvsStreamingException (com.aws.iot.edgeconnectorforkvs.videouploader.model.exceptions.KvsStreamingException)2 Field (java.lang.reflect.Field)2 Path (java.nio.file.Path)2 List (java.util.List)2 ExecutionException (java.util.concurrent.ExecutionException)2 TimeoutException (java.util.concurrent.TimeoutException)2