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());
}
}
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;
}
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());
}
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);
}
}
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;
}
Aggregations