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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations