Search in sources :

Example 16 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_InitScheduler.

@Test
public void test_InitScheduler(@TempDir Path tempDir) throws IOException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = new ArrayList();
    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(CAPTURE_START_TIME);
    when(edgeConnectorForKVSConfiguration.getLiveStreamingStartTime()).thenReturn(LIVE_STREAMING_START_TIME);
    when(edgeConnectorForKVSConfiguration.getVideoRecordFolderPath()).thenReturn(tempDir);
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoUploader(any());
    doNothing().when(edgeConnectorForKVSConfiguration).setVideoUploader(any());
    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 17 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 DiskManagerUtil method buildRecordedFilesMap.

/**
 * Method to initialize local cached video file records.
 * The method all walk all given dir paths, generate Map, key is directoryPath, value is the
 * ConcurrentLinkedQueue which contains all existing video files.
 *
 * @param edgeConnectorForKVSConfiguration EdgeConnectorForKVSConfiguration
 * @throws IOException           throw IOException
 */
public void buildRecordedFilesMap(@NonNull EdgeConnectorForKVSConfiguration edgeConnectorForKVSConfiguration) throws IOException {
    Path directoryPath = edgeConnectorForKVSConfiguration.getVideoRecordFolderPath();
    ConcurrentLinkedDeque<Path> recordedFilesQueue = new ConcurrentLinkedDeque<>();
    recordedFilesMap.put(directoryPath, recordedFilesQueue);
    int localDataRetentionPeriodInMinutes = edgeConnectorForKVSConfiguration.getLocalDataRetentionPeriodInMinutes();
    recordedFilesRetentionPeriodMap.put(directoryPath, localDataRetentionPeriodInMinutes);
    try (Stream<Path> walk = Files.walk(directoryPath)) {
        walk.filter(p -> !Files.isDirectory(p)).sorted(Comparator.comparing(Path::getFileName)).collect(Collectors.toList()).forEach(p -> appendRecordFileToDirPath(directoryPath, p));
    } catch (IOException e) {
        log.error("Unable to initialize recorded files map for dir path: " + directoryPath);
        log.error(e.getMessage());
        throw new IOException(e);
    }
}
Also used : Path(java.nio.file.Path) Getter(lombok.Getter) Files(java.nio.file.Files) NonNull(lombok.NonNull) Date(java.util.Date) IOException(java.io.IOException) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque) VideoRecordVisitor(com.aws.iot.edgeconnectorforkvs.util.VideoRecordVisitor) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) ChronoUnit(java.time.temporal.ChronoUnit) Stream(java.util.stream.Stream) MAX_EXPECTED_VIDEO_FILE_TIME_GAP_IN_MINUTES(com.aws.iot.edgeconnectorforkvs.util.Constants.MAX_EXPECTED_VIDEO_FILE_TIME_GAP_IN_MINUTES) Map(java.util.Map) MAX_TIME_GAP_FOR_BACKFILL_SITEWISE_TIMESTAMP_IN_MINUTES(com.aws.iot.edgeconnectorforkvs.util.Constants.MAX_TIME_GAP_FOR_BACKFILL_SITEWISE_TIMESTAMP_IN_MINUTES) EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Comparator(java.util.Comparator) Path(java.nio.file.Path) Hashtable(java.util.Hashtable) NoArgsConstructor(lombok.NoArgsConstructor) IOException(java.io.IOException) ConcurrentLinkedDeque(java.util.concurrent.ConcurrentLinkedDeque)

Example 18 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_Build_Recorder_Files_Success_Case.

@Test
public void testWatchService_Build_Recorder_Files_Success_Case(@TempDir Path tempDir) {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = Collections.singletonList(EdgeConnectorForKVSConfiguration.builder().videoRecordFolderPath(tempDir).localDataRetentionPeriodInMinutes(LOCAL_DATA_RETENTION_PERIOD_IN_MINUTES).build());
    filePath = tempDir.resolve(FILE_NAME);
    List<WatchEvent<?>> events = new ArrayList<>();
    testWatchEventCallBack = new TestWatchEventCallBack(events);
    diskManager = new DiskManager(edgeConnectorForKVSConfigurationList, diskManagerUtil, watchServiceExecutor, fileCleanerService, testWatchEventCallBack);
    // then
    diskManager.initDiskManager();
    assertTrue(diskManagerUtil.getRecordedFilesMap().size() > 0);
}
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)

Example 19 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 test_GetEdgeConnectorForKVSConfigurationFromPath.

@Test
public void test_GetEdgeConnectorForKVSConfigurationFromPath(@TempDir Path tempDir) {
    // when
    EdgeConnectorForKVSConfiguration configuration = new EdgeConnectorForKVSConfiguration();
    diskManagerUtil.getEdgeConnectorForKVSConfigurationMap().put(tempDir, configuration);
    // then and verify
    assertEquals(diskManagerUtil.getEdgeConnectorForKVSConfigurationFromPath(tempDir), configuration);
}
Also used : EdgeConnectorForKVSConfiguration(com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration) Test(org.junit.jupiter.api.Test)

Example 20 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_Monitor_Thread_Exists_Case.

@Test
public void testWatchService_File_Monitor_Thread_Exists_Case(@TempDir Path tempDir) throws InterruptedException, IOException {
    // when
    List<EdgeConnectorForKVSConfiguration> edgeConnectorForKVSConfigurationList = Collections.singletonList(EdgeConnectorForKVSConfiguration.builder().videoRecordFolderPath(Paths.get("NonExistentFile.txt")).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 and verify
    diskManager.setupDiskManagerThread();
    diskManager.setupDiskManagerThread();
    Thread.sleep(3000);
    filePath = tempDir.resolve(FILE_NAME);
    Files.write(filePath, Collections.singletonList(MOCK_VALUE));
    // then
    try {
        diskManager.setupDiskManagerThread();
        Thread.sleep(3000);
    } catch (EdgeConnectorForKVSException | InterruptedException e) {
        assertEquals(e.getClass(), EdgeConnectorForKVSException.class);
    }
}
Also used : EdgeConnectorForKVSException(com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException) 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