Search in sources :

Example 26 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.

the class ScheduleFilePlanLoadersUnitTest method testCalculateMaxChildrenWithoutMix.

@Test
public void testCalculateMaxChildrenWithoutMix() throws Exception {
    int maxActiveLoaders = 8;
    int rootCategoriesNumber = 0;
    int categoriesChildrenNumber = 2;
    int foldersChildrenNumber = 0;
    int categoryStructureDepth = 4;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    scheduleFilePlanLoaders.setChildCategNumber(categoriesChildrenNumber);
    scheduleFilePlanLoaders.setFolderNumber(foldersChildrenNumber);
    scheduleFilePlanLoaders.setFolderCategoryMix(false);
    FolderData mockedRootCategoryFolder = mock(FolderData.class);
    when(mockedRootCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedRootCategoryFolder.getPath()).thenReturn("/a");
    String name1 = ROOT_CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedRootCategoryFolder.getName()).thenReturn(name1);
    FolderData mockedChildCategoryFolder = mock(FolderData.class);
    when(mockedChildCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedChildCategoryFolder.getPath()).thenReturn("/b");
    String name2 = CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedChildCategoryFolder.getName()).thenReturn(name2);
    FolderData filePlanFolder = mock(FolderData.class);
    when(filePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(filePlanFolder.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(filePlanFolder);
    String id1 = UUID.randomUUID().toString();
    FolderData auxFolder1 = mock(FolderData.class);
    when(auxFolder1.getFolderCount()).thenReturn(1L).thenReturn(0L);
    when(mockedRootCategoryFolder.getId()).thenReturn(id1);
    when(mockedAuxFileFolderService.getFolder(id1)).thenReturn(auxFolder1);
    String id2 = UUID.randomUUID().toString();
    FolderData auxFolder2 = mock(FolderData.class);
    when(auxFolder2.getFolderCount()).thenReturn(1L).thenReturn(0L);
    when(mockedChildCategoryFolder.getId()).thenReturn(id2);
    when(mockedAuxFileFolderService.getFolder(id2)).thenReturn(auxFolder2);
    List<FolderData> folders = Arrays.asList(mockedRootCategoryFolder, mockedChildCategoryFolder);
    when(mockedFileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, Long.valueOf(FILE_PLAN_LEVEL + 1), Long.valueOf(scheduleFilePlanLoaders.getMaxLevel() - 1), 0L, Long.valueOf(categoriesChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
    FolderData mockedExitingCategory1 = mock(FolderData.class);
    FolderData mockedExitingCategory2 = mock(FolderData.class);
    when(mockedFileFolderService.getChildFolders(RECORD_CATEGORY_CONTEXT, "/a", 0, 100)).thenReturn(Arrays.asList(mockedExitingCategory1));
    when(mockedFileFolderService.getChildFolders(RECORD_CATEGORY_CONTEXT, "/b", 0, 100)).thenReturn(Arrays.asList(mockedExitingCategory2));
    when(mockedRootCategoryFolder.getFolderCount()).thenReturn(1L);
    when(mockedFileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, null, null, null, null, null, null, 0, 1)).thenReturn(Arrays.asList(mockedRootCategoryFolder));
    EventResult result = scheduleFilePlanLoaders.processEvent(null, new StopWatch());
    verify(mockedSessionService, times(2)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 2 events and rescheduled self.", result.getData());
    assertEquals(3, result.getNextEvents().size());
    for (int i = 0; i < 2; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_SUB_CATEGORY, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_CATEGORY_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        if (i == 0) {
            assertEquals("/a", (String) dataObj.get(FIELD_PATH));
        } else {
            assertEquals("/b", (String) dataObj.get(FIELD_PATH));
        }
        assertEquals(LOAD_SUB_CATEGORY_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_SELF, result.getNextEvents().get(2).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 27 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.

the class ScheduleFilePlanLoadersUnitTest method testCalculateMaxChildrenWithMix.

@Test
public void testCalculateMaxChildrenWithMix() throws Exception {
    int maxActiveLoaders = 8;
    int rootCategoriesNumber = 0;
    int categoriesChildrenNumber = 2;
    int foldersChildrenNumber = 0;
    int categoryStructureDepth = 4;
    scheduleFilePlanLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleFilePlanLoaders.setCategoryNumber(rootCategoriesNumber);
    scheduleFilePlanLoaders.setCategoryStructureDepth(categoryStructureDepth);
    scheduleFilePlanLoaders.setChildCategNumber(categoriesChildrenNumber);
    scheduleFilePlanLoaders.setFolderNumber(foldersChildrenNumber);
    scheduleFilePlanLoaders.setFolderCategoryMix(true);
    FolderData mockedRootCategoryFolder = mock(FolderData.class);
    when(mockedRootCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedRootCategoryFolder.getPath()).thenReturn("/a");
    String name1 = ROOT_CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedRootCategoryFolder.getName()).thenReturn(name1);
    FolderData mockedChildCategoryFolder = mock(FolderData.class);
    when(mockedChildCategoryFolder.getContext()).thenReturn(RECORD_CATEGORY_CONTEXT);
    when(mockedChildCategoryFolder.getPath()).thenReturn("/b");
    String name2 = CATEGORY_NAME_IDENTIFIER + UUID.randomUUID().toString();
    when(mockedChildCategoryFolder.getName()).thenReturn(name2);
    FolderData filePlanFolder = mock(FolderData.class);
    when(filePlanFolder.getContext()).thenReturn(FILEPLAN_CONTEXT);
    when(filePlanFolder.getPath()).thenReturn(RECORD_CONTAINER_PATH);
    when(mockedFileFolderService.getFolder(FILEPLAN_CONTEXT, RECORD_CONTAINER_PATH)).thenReturn(filePlanFolder);
    String id1 = UUID.randomUUID().toString();
    FolderData auxFolder1 = mock(FolderData.class);
    when(auxFolder1.getFolderCount()).thenReturn(1L).thenReturn(0L);
    when(mockedRootCategoryFolder.getId()).thenReturn(id1);
    when(mockedAuxFileFolderService.getFolder(id1)).thenReturn(auxFolder1);
    String id2 = UUID.randomUUID().toString();
    FolderData auxFolder2 = mock(FolderData.class);
    when(auxFolder2.getFolderCount()).thenReturn(1L).thenReturn(0L);
    when(mockedChildCategoryFolder.getId()).thenReturn(id2);
    when(mockedAuxFileFolderService.getFolder(id2)).thenReturn(auxFolder2);
    List<FolderData> folders = Arrays.asList(mockedRootCategoryFolder, mockedChildCategoryFolder);
    when(mockedFileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, Long.valueOf(FILE_PLAN_LEVEL + 1), Long.valueOf(scheduleFilePlanLoaders.getMaxLevel() - 1), 0L, Long.valueOf(categoriesChildrenNumber - 1), null, null, 0, 100)).thenReturn(folders);
    FolderData mockedExitingCategory1 = mock(FolderData.class);
    FolderData mockedExitingCategory2 = mock(FolderData.class);
    when(mockedFileFolderService.getChildFolders(RECORD_CATEGORY_CONTEXT, "/a", 0, 100)).thenReturn(Arrays.asList(mockedExitingCategory1));
    when(mockedFileFolderService.getChildFolders(RECORD_CATEGORY_CONTEXT, "/b", 0, 100)).thenReturn(Arrays.asList(mockedExitingCategory2));
    when(mockedRootCategoryFolder.getFolderCount()).thenReturn(1L);
    when(mockedFileFolderService.getFoldersByCounts(RECORD_CATEGORY_CONTEXT, null, null, null, null, null, null, 0, 1)).thenReturn(Arrays.asList(mockedRootCategoryFolder));
    EventResult result = scheduleFilePlanLoaders.processEvent(null, new StopWatch());
    verify(mockedSessionService, times(2)).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Raised further 2 events and rescheduled self.", result.getData());
    assertEquals(3, result.getNextEvents().size());
    for (int i = 0; i < 2; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_SUB_CATEGORY, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_CATEGORY_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        if (i == 0) {
            assertEquals("/a", (String) dataObj.get(FIELD_PATH));
        } else {
            assertEquals("/b", (String) dataObj.get(FIELD_PATH));
        }
        assertEquals(LOAD_SUB_CATEGORY_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_SELF, result.getNextEvents().get(2).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 28 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.

the class ScheduleRecordLoadersUnitTest method testUploadNoRecords.

@Test
public void testUploadNoRecords() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 0;
    scheduleRecordLoaders.setUploadRecords(true);
    scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleRecordLoaders.setRecordsNumber(recordsNumber);
    EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, never()).createNewFolder(any(FolderData.class));
    verify(mockedFileFolderService, never()).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
    verify(mockedSessionService, never()).startSession(any(DBObject.class));
    assertEquals(true, result.isSuccess());
    assertEquals("Loading completed.  Raising 'done' event.", result.getData());
    assertEquals(1, result.getNextEvents().size());
    assertEquals(EVENT_COMPLETE, result.getNextEvents().get(0).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 29 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.

the class ScheduleRecordLoadersUnitTest method testUploadRecordsWithExceptionWhenCreatingPreconfiguredPaths.

@Test
public void testUploadRecordsWithExceptionWhenCreatingPreconfiguredPaths() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 4;
    String configuredPath1 = "/e1/e2/e3";
    String configuredPath2 = "/e1/e2/e4";
    String paths = configuredPath1 + "," + configuredPath2;
    scheduleRecordLoaders.setUploadRecords(true);
    scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleRecordLoaders.setRecordsNumber(recordsNumber);
    scheduleRecordLoaders.setRecordFolderPaths(paths);
    String path1 = RECORD_CONTAINER_PATH + "/categ1/folder1";
    FolderData mockedRecordFolder1 = mock(FolderData.class);
    when(mockedRecordFolder1.getId()).thenReturn("recordFolder1Id");
    when(mockedRecordFolder1.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedRecordFolder1.getPath()).thenReturn(path1);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path1)).thenReturn(mockedRecordFolder1);
    String path2 = RECORD_CONTAINER_PATH + "/categ2/folder2";
    FolderData mockedRecordFolder2 = mock(FolderData.class);
    when(mockedRecordFolder2.getId()).thenReturn("recordFolder2Id");
    when(mockedRecordFolder2.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedRecordFolder2.getPath()).thenReturn(path2);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path2)).thenReturn(mockedRecordFolder2);
    when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
    when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
    // returns available record folders
    when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 0, 100)).thenReturn(Arrays.asList(mockedRecordFolder1, mockedRecordFolder2));
    when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 100, 100)).thenReturn(new ArrayList<FolderData>());
    EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, times(2)).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
    assertEquals(true, result.isSuccess());
    verify(mockedSessionService, times(recordsNumber)).startSession(any(DBObject.class));
    assertEquals("Raised further " + (recordsNumber) + " events and rescheduled self.", result.getData());
    assertEquals(recordsNumber + 1, result.getNextEvents().size());
    for (int i = 0; i < recordsNumber; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_RECORD_LOADERS, result.getNextEvents().get(recordsNumber).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Example 30 with StopWatch

use of org.apache.commons.lang3.time.StopWatch in project records-management by Alfresco.

the class ScheduleRecordLoadersUnitTest method testUploadRecordsWithNoPreconfiguredPaths.

@Test
public void testUploadRecordsWithNoPreconfiguredPaths() throws Exception {
    int maxActiveLoaders = 8;
    int recordsNumber = 4;
    String paths = "";
    scheduleRecordLoaders.setUploadRecords(true);
    scheduleRecordLoaders.setMaxActiveLoaders(maxActiveLoaders);
    scheduleRecordLoaders.setRecordsNumber(recordsNumber);
    scheduleRecordLoaders.setRecordFolderPaths(paths);
    String path1 = RECORD_CONTAINER_PATH + "/RootCateg1/recordFolder1";
    FolderData mockedRecordFolder1 = mock(FolderData.class);
    when(mockedRecordFolder1.getId()).thenReturn("recordFolder1Id");
    when(mockedRecordFolder1.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedRecordFolder1.getPath()).thenReturn(path1);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path1)).thenReturn(mockedRecordFolder1);
    String path2 = RECORD_CONTAINER_PATH + "/RootCateg1/recordFolder2";
    FolderData mockedRecordFolder2 = mock(FolderData.class);
    when(mockedRecordFolder2.getId()).thenReturn("recordFolder2Id");
    when(mockedRecordFolder2.getContext()).thenReturn(RECORD_FOLDER_CONTEXT);
    when(mockedRecordFolder2.getPath()).thenReturn(path2);
    when(mockedFileFolderService.getFolder(RECORD_FOLDER_CONTEXT, path2)).thenReturn(mockedRecordFolder2);
    when(mockedRestApiFactory.getFilePlansAPI()).thenReturn(mockedFilePlanAPI);
    when(mockedRestApiFactory.getRecordCategoryAPI()).thenReturn(mockedRecordCategoryAPI);
    // returns record folders
    when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 0, 100)).thenReturn(Arrays.asList(mockedRecordFolder1, mockedRecordFolder2));
    when(mockedFileFolderService.getFoldersByCounts(RECORD_FOLDER_CONTEXT, null, null, null, null, null, null, 100, 100)).thenReturn(new ArrayList<FolderData>());
    EventResult result = scheduleRecordLoaders.processEvent(null, new StopWatch());
    verify(mockedFileFolderService, times(2)).getFoldersByCounts(any(String.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Long.class), any(Integer.class), any(Integer.class));
    assertEquals(true, result.isSuccess());
    verify(mockedSessionService, times(recordsNumber)).startSession(any(DBObject.class));
    assertEquals("Raised further " + (recordsNumber) + " events and rescheduled self.", result.getData());
    assertEquals(recordsNumber + 1, result.getNextEvents().size());
    for (int i = 0; i < recordsNumber; i++) {
        Event event = result.getNextEvents().get(i);
        assertEquals(EVENT_LOAD_RECORD, event.getName());
        DBObject dataObj = (DBObject) event.getData();
        assertNotNull(dataObj);
        assertEquals(RECORD_FOLDER_CONTEXT, (String) dataObj.get(FIELD_CONTEXT));
        assertEquals(LOAD_RECORD_OPERATION, dataObj.get(FIELD_LOAD_OPERATION));
    }
    assertEquals(EVENT_SCHEDULE_RECORD_LOADERS, result.getNextEvents().get(recordsNumber).getName());
}
Also used : EventResult(org.alfresco.bm.event.EventResult) FolderData(org.alfresco.bm.cm.FolderData) Event(org.alfresco.bm.event.Event) DBObject(com.mongodb.DBObject) StopWatch(org.apache.commons.lang3.time.StopWatch) Test(org.junit.Test)

Aggregations

StopWatch (org.apache.commons.lang3.time.StopWatch)500 Test (org.junit.Test)149 EventResult (org.alfresco.bm.event.EventResult)97 DBObject (com.mongodb.DBObject)90 Event (org.alfresco.bm.event.Event)87 FolderData (org.alfresco.bm.cm.FolderData)75 File (java.io.File)72 ArrayList (java.util.ArrayList)48 HashSet (java.util.HashSet)31 Gene (ubic.gemma.model.genome.Gene)31 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)26 BaseTest (org.umlg.sqlg.test.BaseTest)26 Element (org.w3c.dom.Element)25 LoadSingleComponentUnitTest (org.alfresco.bm.dataload.LoadSingleComponentUnitTest)23 UserModel (org.alfresco.utility.model.UserModel)23 IOException (java.io.IOException)20 Collectors (java.util.stream.Collectors)19 HashMap (java.util.HashMap)18 List (java.util.List)18 ExpressionExperiment (ubic.gemma.model.expression.experiment.ExpressionExperiment)18