Search in sources :

Example 1 with TestWatchEventCallBack

use of com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack 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 2 with TestWatchEventCallBack

use of com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack 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)

Example 3 with TestWatchEventCallBack

use of com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class DiskManagerTest method testWatchService_Path_Register_Failed_Case.

@Test
public void testWatchService_Path_Register_Failed_Case() {
    // 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
    try {
        diskManager.setupDiskManagerThread();
    } catch (EdgeConnectorForKVSException 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)

Example 4 with TestWatchEventCallBack

use of com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack 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)

Example 5 with TestWatchEventCallBack

use of com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack in project aws-iot-greengrass-edge-connector-for-kinesis-video-stream by awslabs.

the class DiskManagerTest method testWatchService_Build_Recorder_Files_Exception_Case.

@Test
public void testWatchService_Build_Recorder_Files_Exception_Case() {
    // 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
    assertThrows(EdgeConnectorForKVSException.class, () -> diskManager.initDiskManager());
}
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

TestWatchEventCallBack (com.aws.iot.edgeconnectorforkvs.diskmanager.callback.TestWatchEventCallBack)5 EdgeConnectorForKVSConfiguration (com.aws.iot.edgeconnectorforkvs.model.EdgeConnectorForKVSConfiguration)5 WatchEvent (java.nio.file.WatchEvent)5 ArrayList (java.util.ArrayList)5 Test (org.junit.jupiter.api.Test)5 EdgeConnectorForKVSException (com.aws.iot.edgeconnectorforkvs.model.exceptions.EdgeConnectorForKVSException)2