use of java.util.Spliterator in project mapdb by jankotek.
the class LinkedBlockingDeque8Test method testSpliterator_characteristics.
/**
* Spliterator characteristics are as advertised
*/
public void testSpliterator_characteristics() {
BlockingDeque q = newDeque();
Spliterator s = q.spliterator();
int characteristics = s.characteristics();
int required = Spliterator.CONCURRENT | Spliterator.NONNULL | Spliterator.ORDERED;
assertEquals(required, characteristics & required);
assertTrue(s.hasCharacteristics(required));
assertEquals(0, characteristics & (Spliterator.DISTINCT | Spliterator.IMMUTABLE | Spliterator.SORTED));
}
use of java.util.Spliterator in project molgenis by molgenis.
the class VcfImporterServiceTest method doImportVcfWithoutSamples.
@SuppressWarnings("unchecked")
@Test
void doImportVcfWithoutSamples() {
when(dataService.getMeta()).thenReturn(metaDataService);
when(metaDataService.getDefaultBackend()).thenReturn(repositoryCollection);
when(repositoryCollection.getName()).thenReturn("default");
// Test with multiple input repositories not possible due to
// https://github.com/molgenis/molgenis/issues/4544
String entityTypeId0 = "entity0";
List<String> entityTypeIds = singletonList(entityTypeId0);
EntityType entityType0 = mock(EntityType.class);
when(entityType0.getId()).thenReturn(entityTypeId0);
Entity entity0 = mock(Entity.class);
Entity entity1 = mock(Entity.class);
List<Entity> entities = Arrays.asList(entity0, entity1);
Repository<Entity> repo0 = Mockito.spy(new AbstractRepository() {
@Override
public Set<RepositoryCapability> getCapabilities() {
return null;
}
public EntityType getEntityType() {
return entityType0;
}
@Override
public Iterator<Entity> iterator() {
return entities.iterator();
}
@Override
public Spliterator<Entity> spliterator() {
return entities.spliterator();
}
@Override
public String getName() {
return entityTypeId0;
}
@Override
public void forEachBatched(Consumer<List<Entity>> consumer, int batchSize) {
this.forEachBatched(null, consumer, batchSize);
}
});
when(dataService.hasRepository(entityTypeId0)).thenReturn(false);
Repository<Entity> outRepo0 = mock(Repository.class);
when(metaDataService.createRepository(argThat(eqName(entityType0)))).thenReturn(outRepo0);
when(outRepo0.add(any(Stream.class))).thenAnswer(invocation -> {
Stream<Entity> entities1 = (Stream<Entity>) invocation.getArguments()[0];
List<Entity> entityList = entities1.collect(Collectors.toList());
return entityList.size();
});
RepositoryCollection source = mock(RepositoryCollection.class);
when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
when(source.getRepository(entityTypeId0)).thenReturn(repo0);
String importPackageId = "package";
Package importPackage = mock(Package.class);
when(metaDataService.getPackage(importPackageId)).thenReturn(Optional.of(importPackage));
EntityImportReport entityImportReport = vcfImporterService.doImport(source, MetadataAction.ADD, DataAction.ADD, importPackageId);
EntityImportReport expectedEntityImportReport = new EntityImportReport();
expectedEntityImportReport.addEntityCount(entityTypeId0, entities.size());
expectedEntityImportReport.addNewEntity(entityTypeId0);
assertEquals(expectedEntityImportReport, entityImportReport);
verify(metaDataService, times(1)).createRepository(argThat(eqName(entityType0)));
verify(permissionSystemService, times(1)).giveUserWriteMetaPermissions(entityType0);
}
use of java.util.Spliterator in project molgenis by molgenis.
the class VcfImporterServiceTest method doImportVcfWithSamples.
@SuppressWarnings("unchecked")
@Test
void doImportVcfWithSamples() {
when(dataService.getMeta()).thenReturn(metaDataService);
when(metaDataService.getDefaultBackend()).thenReturn(repositoryCollection);
when(repositoryCollection.getName()).thenReturn("default");
// Test with multiple input repositories not possible due to
// https://github.com/molgenis/molgenis/issues/4544
String entityTypeId0 = "entity0";
List<String> entityTypeIds = singletonList(entityTypeId0);
String sampleEntityName0 = "entity0sample";
EntityType sampleEntityType0 = mock(EntityType.class);
when(sampleEntityType0.getId()).thenReturn(sampleEntityName0);
Repository<Entity> outSampleRepo0 = mock(Repository.class);
when(outSampleRepo0.getName()).thenReturn(sampleEntityName0);
doReturn(outSampleRepo0).when(metaDataService).createRepository(argThat(eqName(sampleEntityType0)));
Attribute sampleAttr = mock(Attribute.class);
when(sampleAttr.getRefEntity()).thenReturn(sampleEntityType0);
EntityType entityType0 = mock(EntityType.class);
when(entityType0.getId()).thenReturn(entityTypeId0);
when(entityType0.getAttribute(VcfAttributes.SAMPLES)).thenReturn(sampleAttr);
Entity entity0Sample0 = mock(Entity.class);
Entity entity0Sample1 = mock(Entity.class);
Entity entity1Sample0 = mock(Entity.class);
Entity entity1Sample1 = mock(Entity.class);
Entity entity0 = mock(Entity.class);
when(entity0.getEntities(VcfAttributes.SAMPLES)).thenReturn(Arrays.asList(entity0Sample0, entity0Sample1));
Entity entity1 = mock(Entity.class);
when(entity1.getEntities(VcfAttributes.SAMPLES)).thenReturn(Arrays.asList(entity1Sample0, entity1Sample1));
List<Entity> entities = Arrays.asList(entity0, entity1);
Repository<Entity> repo0 = Mockito.spy(new AbstractRepository() {
@Override
public Set<RepositoryCapability> getCapabilities() {
return null;
}
public EntityType getEntityType() {
return entityType0;
}
@Override
public Iterator<Entity> iterator() {
return entities.iterator();
}
@Override
public Spliterator<Entity> spliterator() {
return entities.spliterator();
}
@Override
public String getName() {
return entityTypeId0;
}
@Override
public void forEachBatched(Consumer<List<Entity>> consumer, int batchSize) {
this.forEachBatched(null, consumer, batchSize);
}
});
when(dataService.hasRepository(entityTypeId0)).thenReturn(false);
Repository<Entity> outRepo0 = mock(Repository.class);
doReturn(outRepo0).when(metaDataService).createRepository(argThat(eqName(entityType0)));
when(outRepo0.add(any(Stream.class))).thenAnswer(invocation -> {
Stream<Entity> entities1 = (Stream<Entity>) invocation.getArguments()[0];
List<Entity> entityList = entities1.collect(Collectors.toList());
return entityList.size();
});
RepositoryCollection source = mock(RepositoryCollection.class);
when(source.getEntityTypeIds()).thenReturn(entityTypeIds);
when(source.getRepository(entityTypeId0)).thenReturn(repo0);
String importPackageId = "package";
Package importPackage = mock(Package.class);
when(metaDataService.getPackage(importPackageId)).thenReturn(Optional.of(importPackage));
EntityImportReport entityImportReport = vcfImporterService.doImport(source, MetadataAction.ADD, DataAction.ADD, importPackageId);
EntityImportReport expectedEntityImportReport = new EntityImportReport();
expectedEntityImportReport.addNewEntity(sampleEntityName0);
expectedEntityImportReport.addEntityCount(sampleEntityName0, 4);
expectedEntityImportReport.addNewEntity(entityTypeId0);
expectedEntityImportReport.addEntityCount(entityTypeId0, entities.size());
assertEquals(expectedEntityImportReport, entityImportReport);
verify(metaDataService).createRepository(argThat(eqName(sampleEntityType0)));
verify(metaDataService).createRepository(argThat(eqName(entityType0)));
verify(permissionSystemService).giveUserWriteMetaPermissions(entityType0);
verify(permissionSystemService).giveUserWriteMetaPermissions(sampleEntityType0);
}
use of java.util.Spliterator in project archiva by apache.
the class JcrMetadataRepository method getArtifactStream.
@Override
public Stream<ArtifactMetadata> getArtifactStream(final RepositorySession session, final String repositoryId, final String namespace, final String projectId, final String projectVersion, final QueryParameter queryParameter) throws MetadataResolutionException {
final Session jcrSession;
try {
jcrSession = getSession(session);
} catch (MetadataRepositoryException e) {
throw new MetadataResolutionException(e.getMessage());
}
try {
Node root = jcrSession.getRootNode();
String path = getProjectVersionPath(repositoryId, namespace, projectId, projectVersion);
if (root.hasNode(path)) {
Node node = root.getNode(path);
return StreamSupport.stream(JcrUtils.getChildNodes(node).spliterator(), false).filter(JcrMetadataRepository::isArtifactNodeType).map(n -> getArtifactOptional(repositoryId, n)).map(Optional::get).skip(queryParameter.getOffset()).limit(queryParameter.getLimit());
} else {
return Stream.empty();
}
} catch (RepositoryException e) {
throw new MetadataResolutionException(e.getMessage(), e);
}
}
use of java.util.Spliterator in project archiva by apache.
the class CassandraMetadataRepository method getChildNamespaces.
// FIXME this one need peformance improvement maybe a cache?
@Override
public List<String> getChildNamespaces(RepositorySession repositorySession, final String repoId, final String namespaceId) throws MetadataResolutionException {
final String calledNs = namespaceId.endsWith(".") ? namespaceId : namespaceId + ".";
final int nslen = calledNs.length();
CqlSession session = cassandraArchivaManager.getSession();
{
String table = cassandraArchivaManager.getNamespaceFamilyName();
Select query = selectFrom(table).column(NAME.toString()).whereColumn(REPOSITORY_NAME.toString()).isEqualTo(literal(repoId));
return StreamSupport.stream(session.execute(query.build()).spliterator(), false).map(row -> row.get(NAME.toString(), String.class)).filter(namespace -> namespace.length() > nslen && namespace.startsWith(calledNs)).map(namespace -> StringUtils.substringBefore(StringUtils.substringAfter(namespace, calledNs), ".")).distinct().collect(Collectors.toList());
}
}
Aggregations