Search in sources :

Example 31 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_SchedulerStartTaskCallback_StartRecordingJob.

@Test
public void test_SchedulerStartTaskCallback_StartRecordingJob(@TempDir Path tempDir) throws IOException, InterruptedException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(MOCK_KINESIS_VIDEO_STREAM_NAME).captureStartTime("").liveStreamingStartTime("").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);
    Thread.sleep(3000);
    edgeConnectorForKVSConfiguration.setRecordingRequestsCount(2);
    edgeConnectorForKVSService.schedulerStartTaskCallback(Constants.JobType.LOCAL_VIDEO_CAPTURE, MOCK_KINESIS_VIDEO_STREAM_NAME);
    Thread.sleep(1000);
    // verify
    assertNotNull(edgeConnectorForKVSConfiguration.videoUploader);
    assertNotNull(edgeConnectorForKVSConfiguration.inputStream);
    assertEquals(3, edgeConnectorForKVSConfiguration.getRecordingRequestsCount());
}
Also used : ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Test(org.junit.jupiter.api.Test)

Example 32 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 testInitVideoRecorders.

@Test
public void testInitVideoRecorders(@TempDir Path tempDir) throws IOException, InterruptedException {
    // 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).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);
}
Also used : ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Test(org.junit.jupiter.api.Test)

Example 33 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 JobSchedulerTest method stop_singleCamera_stopsScheduler.

@Test
public void stop_singleCamera_stopsScheduler() throws SchedulerException {
    // mock
    EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration = EdgeConnectorForKVSConfiguration.builder().kinesisVideoStreamName(STREAM_NAME).build();
    JobDetail recorderJobDetail = newJob(StartJob.class).withIdentity(STREAM_NAME, Constants.JobType.LOCAL_VIDEO_CAPTURE.name() + "_START").build();
    JobDetail uploaderJobDetail = newJob(StartJob.class).withIdentity(STREAM_NAME, Constants.JobType.LIVE_VIDEO_STREAMING.name() + "_START").build();
    JobKey recorderJobKey = recorderJobDetail.getKey();
    JobKey uploaderJobKey = uploaderJobDetail.getKey();
    // when
    when(schedulerFactory.getScheduler()).thenReturn(scheduler);
    when(scheduler.checkExists(recorderJobKey)).thenReturn(true);
    when(scheduler.checkExists(uploaderJobKey)).thenReturn(true);
    when(scheduler.deleteJob(recorderJobKey)).thenReturn(true);
    when(scheduler.deleteJob(uploaderJobKey)).thenReturn(true);
    // then
    jobScheduler.stop(edgeConnectorForKVSConfiguration);
    // verify
    verify(scheduler, times(1)).checkExists(recorderJobKey);
    verify(scheduler, times(1)).checkExists(uploaderJobKey);
    verify(scheduler, times(1)).deleteJob(recorderJobKey);
    verify(scheduler, times(1)).deleteJob(uploaderJobKey);
}
Also used : JobDetail(org.quartz.JobDetail) JobKey(org.quartz.JobKey) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Test(org.junit.jupiter.api.Test)

Example 34 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 SiteWiseManagerTest method testInitEdgeConnectorForKVSServiceConfiguration.

@Test
public void testInitEdgeConnectorForKVSServiceConfiguration() {
    // when
    when(siteWiseClient.isAssetInheritedFromAssetModel(anyString(), anyString())).thenReturn(true);
    when(siteWiseClient.describeAsset(anyString())).thenReturn(describeAssetResponse);
    when(siteWiseClient.listAssociatedAssets(anyString())).thenReturn(cameraSiteWiseAssetIdList);
    when(siteWiseClient.getAssetPropertyValue(anyString(), eq(generateSiteWisePropertyId(SITE_WISE_CAMERA_MODEL_KINESIS_VIDEO_STREAM_NAME)))).thenReturn(GetAssetPropertyValueResponse.builder().propertyValue(AssetPropertyValue.builder().value(Variant.builder().stringValue(generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_KINESIS_VIDEO_STREAM_NAME)).build()).build()).build());
    when(siteWiseClient.getAssetPropertyValue(anyString(), eq(generateSiteWisePropertyId(SITE_WISE_CAMERA_MODEL_RTSP_STREAM_URL)))).thenReturn(GetAssetPropertyValueResponse.builder().propertyValue(AssetPropertyValue.builder().value(Variant.builder().stringValue(generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_RTSP_STREAM_URL)).build()).build()).build());
    when(siteWiseClient.getAssetPropertyValue(anyString(), eq(generateSiteWisePropertyId(SITE_WISE_CAMERA_MODEL_LIVE_STREAMING_START_TIME)))).thenReturn(GetAssetPropertyValueResponse.builder().propertyValue(AssetPropertyValue.builder().value(Variant.builder().stringValue(generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_LIVE_STREAMING_START_TIME)).build()).build()).build());
    when(siteWiseClient.getAssetPropertyValue(anyString(), eq(generateSiteWisePropertyId(SITE_WISE_CAMERA_MODEL_LIVE_STREAMING_DURATION_IN_MINUTES)))).thenReturn(GetAssetPropertyValueResponse.builder().propertyValue(AssetPropertyValue.builder().value(Variant.builder().integerValue(liveStreamingDurationInMinutes).build()).build()).build());
    when(siteWiseClient.getAssetPropertyValue(anyString(), eq(generateSiteWisePropertyId(SITE_WISE_CAMERA_MODEL_LOCAL_DATA_RETENTION_PERIOD_IN_MINUTES)))).thenReturn(GetAssetPropertyValueResponse.builder().propertyValue(AssetPropertyValue.builder().value(Variant.builder().integerValue(localDataRetentionPeriodInMinutes).build()).build()).build());
    when(siteWiseClient.getAssetPropertyValue(anyString(), eq(generateSiteWisePropertyId(SITE_WISE_CAMERA_MODEL_CAPTURE_START_TIME)))).thenReturn(GetAssetPropertyValueResponse.builder().propertyValue(AssetPropertyValue.builder().value(Variant.builder().stringValue(generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_CAPTURE_START_TIME)).build()).build()).build());
    when(siteWiseClient.getAssetPropertyValue(anyString(), eq(generateSiteWisePropertyId(SITE_WISE_CAMERA_MODEL_CAPTURE_DURATION_IN_MINUTES)))).thenReturn(GetAssetPropertyValueResponse.builder().propertyValue(AssetPropertyValue.builder().value(Variant.builder().integerValue(captureDurationInMinutes).build()).build()).build());
    // then
    List<EdgeConnectorForKVSConfiguration> result = siteWiseManager.initEdgeConnectorForKVSServiceConfiguration(MOCK_HUB_DEVICE_SITE_WISE_ASSET_ID);
    // verify
    EdgeConnectorForKVSConfiguration configuration = result.get(0);
    assertEquals(configuration.getKinesisVideoStreamName(), generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_KINESIS_VIDEO_STREAM_NAME));
    assertEquals(configuration.getRtspStreamURL(), generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_RTSP_STREAM_URL));
    assertEquals(configuration.getLiveStreamingStartTime(), generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_LIVE_STREAMING_START_TIME));
    assertEquals(configuration.getLiveStreamingDurationInMinutes(), liveStreamingDurationInMinutes);
    assertEquals(configuration.getLocalDataRetentionPeriodInMinutes(), localDataRetentionPeriodInMinutes);
    assertEquals(configuration.getCaptureStartTime(), generateSiteWisePropertyValue(SITE_WISE_CAMERA_MODEL_CAPTURE_START_TIME));
    assertEquals(configuration.getCaptureDurationInMinutes(), captureDurationInMinutes);
    assertEquals(configuration.getVideoUploadedTimeRangePropertyId(), generateSiteWisePropertyId(SITE_WISE_VIDEO_UPLOADED_TIME_RANGE_MEASUREMENT_NAME));
    assertEquals(configuration.getVideoRecordedTimeRangePropertyId(), generateSiteWisePropertyId(SITE_WISE_VIDEO_RECORDED_TIME_RANGE_MEASUREMENT_NAME));
    assertEquals(configuration.getCachedVideoAgeOutOnEdgePropertyId(), generateSiteWisePropertyId(SITE_WISE_CACHED_VIDEO_AGE_OUT_ON_EDGE_MEASUREMENT_NAME));
}
Also used : EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Test(org.junit.jupiter.api.Test)

Example 35 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 DiskManagerTest method testWatchService_File_Creation_Case.

@Test
public void testWatchService_File_Creation_Case(@TempDir Path tempDir) throws InterruptedException, IOException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = Collections.singletonList(EdgeConnectorForKVSConfiguration.builder().videoRecordFolderPath(tempDir).localDataRetentionPeriodInMinutes(LOCAL_DATA_RETENTION_PERIOD_IN_MINUTES).build());
    List<WatchEvent<?>> events = new ArrayList<>();
    testWatchEventCallBack = new TestWatchEventCallBack(events);
    diskManager = new DiskManager(edgeConnectorForKVSConfigurationList, diskManagerUtil, watchServiceExecutor, fileCleanerService, testWatchEventCallBack);
    // then
    diskManager.setupDiskManagerThread();
    Thread.sleep(3000);
    filePath = tempDir.resolve(FILE_NAME);
    Files.write(filePath, Collections.singletonList(MOCK_VALUE));
    // verify
    synchronized (events) {
        int i = 0;
        while (events.size() < 1 && i < testRepeatTimes) {
            events.wait(3000);
            i++;
        }
        assertEquals(1, events.size());
    }
}
Also used : TestWatchEventCallBack(com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack) ArrayList(java.util.ArrayList) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) WatchEvent(java.nio.file.WatchEvent) 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