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 testStopRecordingJob_JobStop.
@Test
public void testStopRecordingJob_JobStop(@TempDir Path tempDir) throws IOException, InterruptedException {
// when
List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
Pipeline mockedPipeline = Mockito.mock(Pipeline.class);
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).liveStreamingStartTime(LIVE_STREAMING_START_TIME).liveStreamingDurationInMinutes(LIVE_STREAMING_DURATION_IN_MINUTES).captureStartTime(START_TIME_ALWAYS).videoRecordFolderPath(tempDir).videoRecorder(videoRecorder).build();
edgeConnectorForKVSConfigurationList.add(edgeConnectorForKVSConfiguration);
// Mock for initConfiguration
when(siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(any())).thenReturn(edgeConnectorForKVSConfigurationList);
// Mock for initSecretsManager
when(secretsClient.getSecretValue(any())).thenReturn(gson.toJson(secretMap));
// Mock for videoRecorder status
when(videoRecorder.getStatus()).thenReturn(RecorderStatus.STOPPED);
// Mock for videoRecorder pipeline
when(videoRecorder.getPipeline()).thenReturn(mockedPipeline);
// then
edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
Thread.sleep(2000);
edgeConnectorForKVSService.schedulerStopTaskCallback(Constants.JobType.LOCAL_VIDEO_CAPTURE, MOCK_KINESIS_VIDEO_STREAM_NAME);
Thread.sleep(1000);
// verify
assertEquals(0, edgeConnectorForKVSConfigurationList.get(0).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 test_StopLiveVideoStreaming_ProcessLock_Timeout.
@Test
public void test_StopLiveVideoStreaming_ProcessLock_Timeout(@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())).thenReturn(false);
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 testInitVideoRecorders_startRecordingJob_ProcessLock_TimeOut.
@Test
public void testInitVideoRecorders_startRecordingJob_ProcessLock_TimeOut(@TempDir Path tempDir) throws IOException, InterruptedException {
// when
List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = Mockito.spy(EdgeConnectorForKVSConfiguration.class);
ReentrantLock processLock = Mockito.mock(ReentrantLock.class);
when(edgeConnectorForKVSConfiguration.getKinesisVideoStreamName()).thenReturn(MOCK_KINESIS_VIDEO_STREAM_NAME);
when(edgeConnectorForKVSConfiguration.getLiveStreamingStartTime()).thenReturn(START_TIME_ALWAYS);
when(edgeConnectorForKVSConfiguration.getCaptureStartTime()).thenReturn(START_TIME_ALWAYS);
when(edgeConnectorForKVSConfiguration.getVideoRecordFolderPath()).thenReturn(tempDir);
doNothing().when(edgeConnectorForKVSConfiguration).setVideoUploader(any());
doNothing().when(edgeConnectorForKVSConfiguration).setVideoRecorder(any());
doNothing().when(edgeConnectorForKVSConfiguration).setProcessLock(any());
when(edgeConnectorForKVSConfiguration.getProcessLock()).thenReturn(processLock);
when(processLock.tryLock(anyLong(), any())).thenReturn(false);
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(0, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
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 test_SchedulerStartTaskCallback_StartLiveStreamingJob_ThrowException.
@Test
public void test_SchedulerStartTaskCallback_StartLiveStreamingJob_ThrowException(@TempDir Path tempDir) throws IOException, InterruptedException {
// mock
EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = Mockito.spy(EdgeConnectorForKVSConfiguration.class);
setUpMockConfiguration(edgeConnectorForKVSConfiguration);
// then
edgeConnectorForKVSService.setUpSharedEdgeConnectorForKVSService();
edgeConnectorForKVSService.setUpCameraLevelEdgeConnectorForKVSService(edgeConnectorForKVSConfiguration);
Thread.sleep(3000);
edgeConnectorForKVSConfiguration.setRecordingRequestsCount(2);
edgeConnectorForKVSService.schedulerStartTaskCallback(Constants.JobType.LIVE_VIDEO_STREAMING, MOCK_KINESIS_VIDEO_STREAM_NAME);
Thread.sleep(1000);
// verify
assertTrue(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 testInitVideoRecorders_HasOneRecorderStated.
@Test
public void testInitVideoRecorders_HasOneRecorderStated(@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).captureStartTime(START_TIME_ALWAYS).videoRecordFolderPath(tempDir).recordingRequestsCount(2).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
assertNull(edgeConnectorForKVSConfiguration.videoRecorder);
assertNull(edgeConnectorForKVSConfiguration.outputStream);
}
Aggregations