Search in sources :

Example 21 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class DependencyManagerImplTest method testGetSomeObjectsFromDAO2NonZeroOffset.

/**
 * Gets the partial content of DAO #2, starting from a non-zero offset in DAO #2
 */
@Test
public void testGetSomeObjectsFromDAO2NonZeroOffset() throws Exception {
    DependencyManagerImpl dependencyManager = new DependencyManagerImpl();
    List<MigratableDAO> migratableDaos = new ArrayList<MigratableDAO>();
    MigratableDAO dao1 = Mockito.mock(MigratableDAO.class);
    when(dao1.getCount()).thenReturn(LIST_SIZE);
    when(dao1.getMigrationObjectData(eq(4L), /*offset*/
    anyLong(), /*limit*/
    anyBoolean())).thenReturn(generateMigrationData(0L, 0L, MigratableObjectType.ENTITY));
    migratableDaos.add(dao1);
    MigratableDAO dao2 = Mockito.mock(MigratableDAO.class);
    when(dao2.getCount()).thenReturn(LIST_SIZE);
    when(dao2.getMigrationObjectData(anyLong(), /*offset*/
    eq(1L), /*limit*/
    anyBoolean())).thenReturn(generateMigrationData(4L, 1L, MigratableObjectType.PRINCIPAL));
    migratableDaos.add(dao2);
    dependencyManager.setMigratableDaos(migratableDaos);
    int requestedNum = 1;
    int startIndex = 4;
    QueryResults<MigratableObjectData> results = dependencyManager.getAllObjects(startIndex, requestedNum, true);
    List<MigratableObjectData> ods = results.getResults();
    assertEquals(requestedNum, ods.size());
    assertEquals(2L * LIST_SIZE, results.getTotalNumberOfResults());
    // should get 2 from dao2
    for (int i = startIndex; i < 5L; i++) {
        MigratableObjectData od = ods.get(i - startIndex);
        MigratableObjectDescriptor id = od.getId();
        assertEquals(MigratableObjectType.PRINCIPAL, id.getType());
        assertEquals("" + i, id.getId());
    }
}
Also used : MigratableDAO(org.sagebionetworks.repo.model.MigratableDAO) ArrayList(java.util.ArrayList) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) Test(org.junit.Test)

Example 22 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class XestUtil method createMigratableObjectData.

public static MigratableObjectData createMigratableObjectData(String id, String etag, String parentId, MigratableObjectType mot) {
    MigratableObjectData ans = new MigratableObjectData();
    MigratableObjectDescriptor mod = new MigratableObjectDescriptor();
    mod.setId(id);
    mod.setType(mot);
    ans.setId(mod);
    ans.setEtag(etag);
    Set<MigratableObjectDescriptor> dependencies = new HashSet<MigratableObjectDescriptor>();
    if (parentId != null) {
        MigratableObjectDescriptor parent = new MigratableObjectDescriptor();
        parent.setId(parentId);
        parent.setType(mot);
        dependencies.add(parent);
    }
    ans.setDependencies(dependencies);
    return ans;
}
Also used : MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) HashSet(java.util.HashSet)

Example 23 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class UpdateJobBuilderTest method testDestinationSameAsSource.

@Test
public void testDestinationSameAsSource() throws Exception {
    // make sure the destination is the same as the source
    List<MigratableObjectData> dest = new ArrayList<MigratableObjectData>();
    for (MigratableObjectData fromSource : source) {
        dest.add(fromSource);
    }
    assertEquals(source, dest);
    Map<MigratableObjectDescriptor, MigratableObjectData> destMap = JobUtil.buildMigratableMapFromList(dest);
    // now run the job
    int batchSize = 5;
    UpdateJobBuilder builder = new UpdateJobBuilder(source, destMap, jobQueue, batchSize);
    BuilderResponse response = builder.call();
    assertNotNull(response);
    // Nothing should have been submitted.
    int expectedSubmited = 0;
    assertEquals(expectedSubmited, response.getSubmittedToQueue());
    assertEquals(0, response.pendingDependencies);
    assertEquals(0, jobQueue.size());
}
Also used : ArrayList(java.util.ArrayList) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) Test(org.junit.Test)

Example 24 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class UpdateJobBuilderTest method testSourceWithUpdates.

@Test
public void testSourceWithUpdates() throws Exception {
    // make sure the destination is the same as the source
    List<MigratableObjectData> dest = new ArrayList<MigratableObjectData>();
    for (MigratableObjectData fromSource : source) {
        dest.add(XestUtil.cloneMigratableObjectData(fromSource));
    }
    assertEquals(source, dest);
    // Change some eTags on the source
    source.get(2).setEtag("33");
    source.get(5).setEtag("33");
    source.get(7).setEtag("33");
    Map<MigratableObjectDescriptor, MigratableObjectData> destMap = JobUtil.buildMigratableMapFromList(dest);
    // now run the job
    int batchSize = 2;
    UpdateJobBuilder builder = new UpdateJobBuilder(source, destMap, jobQueue, batchSize);
    BuilderResponse response = builder.call();
    assertNotNull(response);
    // Nothing should have been submitted.
    int expectedSubmited = 3;
    assertEquals(expectedSubmited, response.getSubmittedToQueue());
    assertEquals(0, response.pendingDependencies);
    assertEquals(expectedSubmited / batchSize + 1, jobQueue.size());
    // Check the jobQue
    Job job = null;
    while ((job = jobQueue.poll()) != null) {
        assertNotNull(job);
        assertEquals(Type.UPDATE, job.getJobType());
        assertNotNull(job.getObjectIds());
        assertTrue(job.getObjectIds().size() <= batchSize);
    }
}
Also used : ArrayList(java.util.ArrayList) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor) Test(org.junit.Test)

Example 25 with MigratableObjectDescriptor

use of org.sagebionetworks.repo.model.MigratableObjectDescriptor in project Synapse-Repository-Services by Sage-Bionetworks.

the class JobUtil method buildMigratableMapFromList.

/**
 * Build a map from the list. The key will be entity MigratableObjectDescriptors.
 * @param list
 * @return
 */
public static Map<MigratableObjectDescriptor, MigratableObjectData> buildMigratableMapFromList(List<MigratableObjectData> list) {
    Map<MigratableObjectDescriptor, MigratableObjectData> map = new HashMap<MigratableObjectDescriptor, MigratableObjectData>();
    Map<MigratableObjectType, Integer> mapStats = new HashMap<MigratableObjectType, Integer>();
    for (MigratableObjectData entity : list) {
        if (!map.containsKey(entity.getId())) {
            // only count entities once
            Integer typeCount = mapStats.get(entity.getId().getType());
            if (typeCount == null)
                typeCount = 1;
            else
                typeCount++;
            mapStats.put(entity.getId().getType(), typeCount);
        }
        map.put(entity.getId(), entity);
    }
    System.out.println("Migratable list count by type: " + mapStats);
    return map;
}
Also used : MigratableObjectType(org.sagebionetworks.repo.model.MigratableObjectType) HashMap(java.util.HashMap) MigratableObjectData(org.sagebionetworks.repo.model.MigratableObjectData) MigratableObjectDescriptor(org.sagebionetworks.repo.model.MigratableObjectDescriptor)

Aggregations

MigratableObjectDescriptor (org.sagebionetworks.repo.model.MigratableObjectDescriptor)25 MigratableObjectData (org.sagebionetworks.repo.model.MigratableObjectData)21 Test (org.junit.Test)12 ArrayList (java.util.ArrayList)8 HashSet (java.util.HashSet)5 MigratableDAO (org.sagebionetworks.repo.model.MigratableDAO)4 ResultSet (java.sql.ResultSet)3 SQLException (java.sql.SQLException)3 QueryResults (org.sagebionetworks.repo.model.QueryResults)3 MapSqlParameterSource (org.springframework.jdbc.core.namedparam.MapSqlParameterSource)3 HashMap (java.util.HashMap)2 AccessRequirement (org.sagebionetworks.repo.model.AccessRequirement)2 TermsOfUseAccessRequirement (org.sagebionetworks.repo.model.TermsOfUseAccessRequirement)2 UserProfile (org.sagebionetworks.repo.model.UserProfile)2 SocketTimeoutException (java.net.SocketTimeoutException)1 Set (java.util.Set)1 SynapseAdministration (org.sagebionetworks.client.SynapseAdministration)1 SynapseNotFoundException (org.sagebionetworks.client.exceptions.SynapseNotFoundException)1 SynapseServiceException (org.sagebionetworks.client.exceptions.SynapseServiceException)1 ConflictingUpdateException (org.sagebionetworks.repo.model.ConflictingUpdateException)1