Search in sources :

Example 6 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project presto by prestodb.

the class TestSelectiveOrcReader method testMaps.

@Test
public void testMaps() throws Exception {
    Random random = new Random(0);
    tester.testRoundTrip(mapType(INTEGER, INTEGER), createList(NUM_ROWS, i -> createMap(i)));
    // map column with no nulls
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, mapType(INTEGER, INTEGER)), ImmutableList.of(createList(NUM_ROWS, i -> random.nextInt()), createList(NUM_ROWS, i -> createMap(i))), toSubfieldFilters(ImmutableMap.of(0, BigintRange.of(0, Integer.MAX_VALUE, false)), ImmutableMap.of(1, IS_NOT_NULL), ImmutableMap.of(1, IS_NULL)));
    // map column with nulls
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, mapType(INTEGER, INTEGER)), ImmutableList.of(createList(NUM_ROWS, i -> random.nextInt()), createList(NUM_ROWS, i -> i % 5 == 0 ? null : createMap(i))), toSubfieldFilters(ImmutableMap.of(0, BigintRange.of(0, Integer.MAX_VALUE, false)), ImmutableMap.of(1, IS_NOT_NULL), ImmutableMap.of(1, IS_NULL), ImmutableMap.of(0, BigintRange.of(0, Integer.MAX_VALUE, false), 1, IS_NULL), ImmutableMap.of(0, BigintRange.of(0, Integer.MAX_VALUE, false), 1, IS_NOT_NULL)));
    // map column with filter, followed by another column with filter
    tester.testRoundTripTypes(ImmutableList.of(mapType(INTEGER, INTEGER), INTEGER), ImmutableList.of(createList(NUM_ROWS, i -> i % 5 == 0 ? null : createMap(i)), createList(NUM_ROWS, i -> random.nextInt())), toSubfieldFilters(ImmutableMap.of(0, IS_NULL, 1, BigintRange.of(0, Integer.MAX_VALUE, false)), ImmutableMap.of(0, IS_NOT_NULL, 1, BigintRange.of(0, Integer.MAX_VALUE, false))));
    // empty maps
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, mapType(INTEGER, INTEGER)), ImmutableList.of(createList(NUM_ROWS, i -> random.nextInt()), Collections.nCopies(NUM_ROWS, ImmutableMap.of())), ImmutableList.of());
    // read selected positions from all nulls map column
    tester.testRoundTripTypes(ImmutableList.of(INTEGER, mapType(INTEGER, INTEGER)), ImmutableList.of(createList(NUM_ROWS, i -> random.nextInt(10)), createList(NUM_ROWS, i -> null)), toSubfieldFilters(ImmutableMap.of(0, BigintRange.of(0, 5, false))));
}
Also used : CharType.createCharType(com.facebook.presto.common.type.CharType.createCharType) Page(com.facebook.presto.common.Page) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) OrcTester.createCustomOrcSelectiveRecordReader(com.facebook.presto.orc.OrcTester.createCustomOrcSelectiveRecordReader) BigintRange(com.facebook.presto.common.predicate.TupleDomainFilter.BigintRange) Test(org.testng.annotations.Test) Random(java.util.Random) OrcTester.quickSelectiveOrcTester(com.facebook.presto.orc.OrcTester.quickSelectiveOrcTester) SESSION(com.facebook.presto.testing.TestingConnectorSession.SESSION) Iterables.concat(com.google.common.collect.Iterables.concat) Iterables.cycle(com.google.common.collect.Iterables.cycle) Slices(io.airlift.slice.Slices) Map(java.util.Map) HIVE_STORAGE_TIME_ZONE(com.facebook.presto.orc.OrcTester.HIVE_STORAGE_TIME_ZONE) FloatRange(com.facebook.presto.common.predicate.TupleDomainFilter.FloatRange) BigInteger(java.math.BigInteger) SqlDecimal(com.facebook.presto.common.type.SqlDecimal) BigintValuesUsingHashTable(com.facebook.presto.common.predicate.TupleDomainFilter.BigintValuesUsingHashTable) ImmutableMap(com.google.common.collect.ImmutableMap) DOUBLE(com.facebook.presto.common.type.DoubleType.DOUBLE) OrcTester.mapType(com.facebook.presto.orc.OrcTester.mapType) NONE(com.facebook.presto.orc.metadata.CompressionKind.NONE) Collections.nCopies(java.util.Collections.nCopies) BeforeClass(org.testng.annotations.BeforeClass) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Range(com.google.common.collect.Range) BooleanValue(com.facebook.presto.common.predicate.TupleDomainFilter.BooleanValue) Iterables.limit(com.google.common.collect.Iterables.limit) Assert.assertNotNull(org.testng.Assert.assertNotNull) Streams(com.google.common.collect.Streams) Assertions.assertBetweenInclusive(com.facebook.airlift.testing.Assertions.assertBetweenInclusive) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SqlTimestamp(com.facebook.presto.common.type.SqlTimestamp) IS_NOT_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NOT_NULL) INTEGER(com.facebook.presto.common.type.IntegerType.INTEGER) CompressionKind(com.facebook.presto.orc.metadata.CompressionKind) Optional(java.util.Optional) IS_NULL(com.facebook.presto.common.predicate.TupleDomainFilter.IS_NULL) IntStream(java.util.stream.IntStream) MAX_BLOCK_SIZE(com.facebook.presto.orc.OrcTester.MAX_BLOCK_SIZE) DecimalType(com.facebook.presto.common.type.DecimalType) ContiguousSet(com.google.common.collect.ContiguousSet) Slice(io.airlift.slice.Slice) Assert.assertNull(org.testng.Assert.assertNull) TINYINT(com.facebook.presto.common.type.TinyintType.TINYINT) VARCHAR(com.facebook.presto.common.type.VarcharType.VARCHAR) DateTimeTestingUtils.sqlTimestampOf(com.facebook.presto.testing.DateTimeTestingUtils.sqlTimestampOf) Assert.assertEquals(org.testng.Assert.assertEquals) TIMESTAMP(com.facebook.presto.common.type.TimestampType.TIMESTAMP) Function(java.util.function.Function) DATE(com.facebook.presto.common.type.DateType.DATE) REAL(com.facebook.presto.common.type.RealType.REAL) BytesRange(com.facebook.presto.common.predicate.TupleDomainFilter.BytesRange) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ZLIB(com.facebook.presto.orc.metadata.CompressionKind.ZLIB) SqlDate(com.facebook.presto.common.type.SqlDate) Subfield(com.facebook.presto.common.Subfield) ImmutableList(com.google.common.collect.ImmutableList) SqlVarbinary(com.facebook.presto.common.type.SqlVarbinary) DiscreteDomain(com.google.common.collect.DiscreteDomain) OrcTester.writeOrcColumnsPresto(com.facebook.presto.orc.OrcTester.writeOrcColumnsPresto) BOOLEAN(com.facebook.presto.common.type.BooleanType.BOOLEAN) CharType(com.facebook.presto.common.type.CharType) Type(com.facebook.presto.common.type.Type) MAX_BATCH_SIZE(com.facebook.presto.orc.OrcReader.MAX_BATCH_SIZE) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) OrcTester.arrayType(com.facebook.presto.orc.OrcTester.arrayType) InvalidFunctionArgumentException(com.facebook.presto.common.InvalidFunctionArgumentException) Iterator(java.util.Iterator) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Assert.fail(org.testng.Assert.fail) AbstractIterator(com.google.common.collect.AbstractIterator) TupleDomainFilterUtils.toBigintValues(com.facebook.presto.common.predicate.TupleDomainFilterUtils.toBigintValues) VARBINARY(com.facebook.presto.common.type.VarbinaryType.VARBINARY) Maps(com.google.common.collect.Maps) Ints(com.google.common.primitives.Ints) TupleDomainFilter(com.facebook.presto.common.predicate.TupleDomainFilter) DWRF(com.facebook.presto.orc.OrcTester.Format.DWRF) OrcReaderSettings(com.facebook.presto.orc.OrcTester.OrcReaderSettings) Collectors.toList(java.util.stream.Collectors.toList) SMALLINT(com.facebook.presto.common.type.SmallintType.SMALLINT) OrcTester.rowType(com.facebook.presto.orc.OrcTester.rowType) TestingOrcPredicate.createOrcPredicate(com.facebook.presto.orc.TestingOrcPredicate.createOrcPredicate) Assert.assertTrue(org.testng.Assert.assertTrue) Block(com.facebook.presto.common.block.Block) BytesValues(com.facebook.presto.common.predicate.TupleDomainFilter.BytesValues) DoubleRange(com.facebook.presto.common.predicate.TupleDomainFilter.DoubleRange) Collections(java.util.Collections) ZSTD(com.facebook.presto.orc.metadata.CompressionKind.ZSTD) Random(java.util.Random) Test(org.testng.annotations.Test)

Example 7 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project cas by apereo.

the class BaseOidcScopeAttributeReleasePolicy method getAttributesInternal.

@Override
public Map<String, List<Object>> getAttributesInternal(final RegisteredServiceAttributeReleasePolicyContext context, final Map<String, List<Object>> attributes) {
    val applicationContext = ApplicationContextProvider.getApplicationContext();
    if (applicationContext == null) {
        LOGGER.warn("Could not locate the application context to process attributes");
        return new HashMap<>(0);
    }
    val resolvedAttributes = new TreeMap<String, List<Object>>(String.CASE_INSENSITIVE_ORDER);
    resolvedAttributes.putAll(attributes);
    val attributesToRelease = Maps.<String, List<Object>>newHashMapWithExpectedSize(attributes.size());
    LOGGER.debug("Attempting to map and filter claims based on resolved attributes [{}]", resolvedAttributes);
    val properties = applicationContext.getBean(CasConfigurationProperties.class);
    val supportedClaims = properties.getAuthn().getOidc().getDiscovery().getClaims();
    val allowedClaims = new LinkedHashSet<>(getAllowedAttributes());
    allowedClaims.retainAll(supportedClaims);
    LOGGER.debug("[{}] is designed to allow claims [{}] for scope [{}]. After cross-checking with " + "supported claims [{}], the final collection of allowed attributes is [{}]", getClass().getSimpleName(), getAllowedAttributes(), getScopeType(), supportedClaims, allowedClaims);
    allowedClaims.stream().map(claim -> mapClaimToAttribute(claim, resolvedAttributes)).filter(p -> p.getValue() != null).forEach(p -> attributesToRelease.put(p.getKey(), CollectionUtils.toCollection(p.getValue(), ArrayList.class)));
    return attributesToRelease;
}
Also used : lombok.val(lombok.val) LinkedHashSet(java.util.LinkedHashSet) CasConfigurationProperties(org.apereo.cas.configuration.CasConfigurationProperties) JsonProperty(com.fasterxml.jackson.annotation.JsonProperty) Setter(lombok.Setter) OidcAttributeToScopeClaimMapper(org.apereo.cas.oidc.claims.mapping.OidcAttributeToScopeClaimMapper) RegisteredServiceAttributeReleasePolicyContext(org.apereo.cas.services.RegisteredServiceAttributeReleasePolicyContext) Getter(lombok.Getter) lombok.val(lombok.val) HashMap(java.util.HashMap) EqualsAndHashCode(lombok.EqualsAndHashCode) Maps(com.google.common.collect.Maps) ArrayList(java.util.ArrayList) AbstractRegisteredServiceAttributeReleasePolicy(org.apereo.cas.services.AbstractRegisteredServiceAttributeReleasePolicy) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Pair(org.apache.commons.lang3.tuple.Pair) TreeMap(java.util.TreeMap) Map(java.util.Map) CollectionUtils(org.apereo.cas.util.CollectionUtils) JsonIgnore(com.fasterxml.jackson.annotation.JsonIgnore) ToString(lombok.ToString) JsonInclude(com.fasterxml.jackson.annotation.JsonInclude) ApplicationContextProvider(org.apereo.cas.util.spring.ApplicationContextProvider) LinkedHashSet(java.util.LinkedHashSet) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) List(java.util.List) ToString(lombok.ToString) TreeMap(java.util.TreeMap)

Example 8 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project SONG by overture-stack.

the class AnalysisServiceTest method testGetAnalysisAndIdSearch.

@Test
public void testGetAnalysisAndIdSearch() {
    val studyGenerator = createStudyGenerator(studyService, randomGenerator);
    val studyId = studyGenerator.createRandomStudy();
    val analysisGenerator = createAnalysisGenerator(studyId, service, payloadGenerator);
    val numAnalysis = 10;
    val sraMap = Maps.<String, SequencingReadAnalysis>newHashMap();
    val vcaMap = Maps.<String, VariantCallAnalysis>newHashMap();
    val expectedAnalyses = Sets.<Analysis>newHashSet();
    for (int i = 1; i <= numAnalysis; i++) {
        if (i % 2 == 0) {
            val sra = analysisGenerator.createDefaultRandomSequencingReadAnalysis();
            assertThat(sraMap.containsKey(sra.getAnalysisId())).isFalse();
            sraMap.put(sra.getAnalysisId(), sra);
            expectedAnalyses.add(sra);
        } else {
            val vca = analysisGenerator.createDefaultRandomVariantCallAnalysis();
            assertThat(sraMap.containsKey(vca.getAnalysisId())).isFalse();
            vcaMap.put(vca.getAnalysisId(), vca);
            expectedAnalyses.add(vca);
        }
    }
    assertThat(expectedAnalyses).hasSize(numAnalysis);
    assertThat(sraMap.keySet().size() + vcaMap.keySet().size()).isEqualTo(numAnalysis);
    val expectedVCAs = newHashSet(vcaMap.values());
    val expectedSRAs = newHashSet(sraMap.values());
    assertThat(expectedSRAs).hasSize(sraMap.keySet().size());
    assertThat(expectedVCAs).hasSize(vcaMap.keySet().size());
    val actualAnalyses = service.getAnalysis(studyId);
    val actualSRAs = actualAnalyses.stream().filter(x -> resolveAnalysisType(x.getAnalysisType()) == SEQUENCING_READ).collect(toSet());
    val actualVCAs = actualAnalyses.stream().filter(x -> resolveAnalysisType(x.getAnalysisType()) == VARIANT_CALL).collect(toSet());
    assertThat(actualSRAs).hasSize(sraMap.keySet().size());
    assertThat(actualVCAs).hasSize(vcaMap.keySet().size());
    assertThat(actualSRAs).containsAll(expectedSRAs);
    assertThat(actualVCAs).containsAll(expectedVCAs);
    // Do a study-wide idSearch and verify the response effectively has the same
    // number of results as the getAnalysis method
    val searchedAnalyses = service.idSearch(studyId, createIdSearchRequest(null, null, null, null));
    assertThat(searchedAnalyses).hasSameSizeAs(expectedAnalyses);
    assertThat(searchedAnalyses).containsOnlyElementsOf(expectedAnalyses);
}
Also used : lombok.val(lombok.val) ANALYSIS_ID_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_ID_NOT_FOUND) ExistenceService.createExistenceService(org.icgc.dcc.song.server.service.ExistenceService.createExistenceService) File(org.icgc.dcc.song.server.model.entity.File) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) ActiveProfiles(org.springframework.test.context.ActiveProfiles) DUPLICATE_ANALYSIS_ATTEMPT(org.icgc.dcc.song.core.exceptions.ServerErrors.DUPLICATE_ANALYSIS_ATTEMPT) AnalysisTypes.resolveAnalysisType(org.icgc.dcc.song.server.model.enums.AnalysisTypes.resolveAnalysisType) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) Study(org.icgc.dcc.song.server.model.entity.Study) PayloadGenerator.createPayloadGenerator(org.icgc.dcc.song.server.utils.PayloadGenerator.createPayloadGenerator) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) SpringRunner(org.springframework.test.context.junit4.SpringRunner) SongErrorAssertions.assertSongError(org.icgc.dcc.song.core.testing.SongErrorAssertions.assertSongError) Collectors.toSet(java.util.stream.Collectors.toSet) STUDY_ID_DOES_NOT_EXIST(org.icgc.dcc.song.core.exceptions.ServerErrors.STUDY_ID_DOES_NOT_EXIST) ANALYSIS_MISSING_FILES(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_MISSING_FILES) RandomGenerator.createRandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) TestFiles.assertInfoKVPair(org.icgc.dcc.song.server.utils.TestFiles.assertInfoKVPair) Sets(com.google.common.collect.Sets) String.format(java.lang.String.format) JsonUtils(org.icgc.dcc.song.core.utils.JsonUtils) Slf4j(lombok.extern.slf4j.Slf4j) Assertions.fail(org.assertj.core.api.Assertions.fail) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) ANALYSIS_MISSING_SAMPLES(org.icgc.dcc.song.core.exceptions.ServerErrors.ANALYSIS_MISSING_SAMPLES) JsonUtils.fromJson(org.icgc.dcc.song.core.utils.JsonUtils.fromJson) RandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator) IdSearchRequest.createIdSearchRequest(org.icgc.dcc.song.server.repository.search.IdSearchRequest.createIdSearchRequest) RunWith(org.junit.runner.RunWith) SEQUENCING_READ(org.icgc.dcc.song.server.model.enums.AnalysisTypes.SEQUENCING_READ) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis) ArrayList(java.util.ArrayList) WireMockRule(com.github.tomakehurst.wiremock.junit.WireMockRule) AnalysisGenerator.createAnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator) AnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) UNPUBLISHED_FILE_IDS(org.icgc.dcc.song.core.exceptions.ServerErrors.UNPUBLISHED_FILE_IDS) Before(org.junit.Before) WireMock.get(com.github.tomakehurst.wiremock.client.WireMock.get) VARIANT_CALL(org.icgc.dcc.song.server.model.enums.AnalysisTypes.VARIANT_CALL) JsonUtils.toJson(org.icgc.dcc.song.core.utils.JsonUtils.toJson) lombok.val(lombok.val) WireMockConfiguration.options(com.github.tomakehurst.wiremock.core.WireMockConfiguration.options) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) Maps(com.google.common.collect.Maps) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) WireMock.urlMatching(com.github.tomakehurst.wiremock.client.WireMock.urlMatching) UNPUBLISHED(org.icgc.dcc.song.server.model.enums.AnalysisStates.UNPUBLISHED) TestFiles.getJsonStringFromClasspath(org.icgc.dcc.song.server.utils.TestFiles.getJsonStringFromClasspath) AnalysisRepository(org.icgc.dcc.song.server.repository.AnalysisRepository) SEQUENCING_READ_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.SEQUENCING_READ_NOT_FOUND) PayloadGenerator(org.icgc.dcc.song.server.utils.PayloadGenerator) Rule(org.junit.Rule) Metadata(org.icgc.dcc.song.server.model.Metadata) SampleRepository(org.icgc.dcc.song.server.repository.SampleRepository) VARIANT_CALL_NOT_FOUND(org.icgc.dcc.song.core.exceptions.ServerErrors.VARIANT_CALL_NOT_FOUND) StudyGenerator.createStudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator) RetryTemplate(org.springframework.retry.support.RetryTemplate) OK(org.springframework.http.HttpStatus.OK) Sample(org.icgc.dcc.song.server.model.entity.Sample) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Test(org.junit.Test)

Example 9 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project SONG by overture-stack.

the class ExportServiceTest method runFullLoopTest.

/**
 * Given that  0 < numStudies < numAnalysesPerStudy, this test ensures that if the export service is requested for ONE
 * analysisId from EACH study, the response will return a list of size {@code numStudies}, where each element (which is
 * of type ExportedPayload) has exactly ONE payload (since there is only one analysis per study). This is a 2 in 1 test:
 * - it verifies the conversion of an existing analysis to a payload is correct, by submitting the
 * converted payload and comparing it with the original analysis
 * - it verifies the aggregation functionality of the export service, when given analysisIds belonging to
 * different studies
 */
private void runFullLoopTest(Class<? extends Analysis> analysisClass, int numStudies, int numAnalysesPerStudy) {
    val includeOtherIds = false;
    val includeAnalysisId = true;
    // Check the right parameters for this test are set
    assertCorrectConfig(numStudies, numAnalysesPerStudy);
    // Generate studies and there associated analyses
    val data = generateData(analysisClass, numStudies, numAnalysesPerStudy, includeAnalysisId, true);
    // [REDUCTION_TAG] Reduce the data so that there is one analysis for each study
    val reducedData = Maps.<String, Analysis>newHashMap();
    data.entrySet().stream().filter(e -> !reducedData.containsKey(e.getKey())).forEach(e -> {
        String studyId = e.getKey();
        List<? extends Analysis> analyses = e.getValue();
        int numAnalyses = analyses.size();
        int randomAnalysisPos = randomGenerator.generateRandomIntRange(0, numAnalyses);
        Analysis randomAnalysis = analyses.get(randomAnalysisPos);
        reducedData.put(studyId, randomAnalysis);
    });
    assertThat(reducedData.keySet()).hasSize(numStudies);
    assertThat(reducedData.values()).hasSize(numStudies);
    // Create a list of analysisIds that covers all the previously generated studies
    val requestedAnalysisIds = reducedData.values().stream().map(Analysis::getAnalysisId).collect(toImmutableList());
    assertThat(requestedAnalysisIds).hasSize(numStudies);
    // Export the analysis for the requested analysisIds
    val exportedPayloads = exportService.exportPayload(requestedAnalysisIds, includeAnalysisId, includeOtherIds);
    // There should be an ExportedPayload object for each study
    assertThat(exportedPayloads).hasSize(numStudies);
    for (val exportedPayload : exportedPayloads) {
        // There should be only 1 analysis for each study. Refer to the comment with REDUCTION_TAG.
        val studyId = exportedPayload.getStudyId();
        assertThat(exportedPayload.getPayloads()).hasSize(1);
        val payload = exportedPayload.getPayloads().get(0);
        val expectedAnalysis = reducedData.get(studyId);
        // Delete the previously created analysis so it can be created using the uploadService (frontdoor creation)
        deleteAnalysis(expectedAnalysis);
        // Depending on includeAnalysisId's value, either remove or keep the analysisId. Always keep the
        // other ids, so that it can be compared to the re-create analysis after submission
        massageAnalysisInplace(expectedAnalysis, includeAnalysisId, true);
        // Submit payload. Should create the same "otherIds" as the expected
        val actualAnalysis = submitPayload(studyId, payload, analysisClass);
        // Assert output analysis is correct
        assertAnalysis(actualAnalysis, expectedAnalysis);
    }
}
Also used : lombok.val(lombok.val) File(org.icgc.dcc.song.server.model.entity.File) SneakyThrows(lombok.SneakyThrows) IntStream.range(java.util.stream.IntStream.range) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Autowired(org.springframework.beans.factory.annotation.Autowired) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) ActiveProfiles(org.springframework.test.context.ActiveProfiles) TestFiles.assertSetsMatch(org.icgc.dcc.song.server.utils.TestFiles.assertSetsMatch) AnalysisTypes.resolveAnalysisType(org.icgc.dcc.song.server.model.enums.AnalysisTypes.resolveAnalysisType) TestExecutionListeners(org.springframework.test.context.TestExecutionListeners) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Map(java.util.Map) JsonNode(com.fasterxml.jackson.databind.JsonNode) ExportService(org.icgc.dcc.song.server.service.export.ExportService) SpringRunner(org.springframework.test.context.junit4.SpringRunner) Collectors.toSet(java.util.stream.Collectors.toSet) RandomGenerator.createRandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator) Reductions.groupUnique(org.icgc.dcc.song.core.utils.Reductions.groupUnique) ImmutableMap(com.google.common.collect.ImmutableMap) Specimen(org.icgc.dcc.song.server.model.entity.Specimen) Collection(java.util.Collection) Set(java.util.Set) JsonUtils(org.icgc.dcc.song.core.utils.JsonUtils) Slf4j(lombok.extern.slf4j.Slf4j) List(java.util.List) Lists.newArrayList(com.google.common.collect.Lists.newArrayList) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) JsonUtils.fromJson(org.icgc.dcc.song.core.utils.JsonUtils.fromJson) RandomGenerator(org.icgc.dcc.song.core.utils.RandomGenerator) RunWith(org.junit.runner.RunWith) SEQUENCING_READ(org.icgc.dcc.song.server.model.enums.AnalysisTypes.SEQUENCING_READ) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis) StudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator) AnalysisGenerator.createAnalysisGenerator(org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator) DependencyInjectionTestExecutionListener(org.springframework.test.context.support.DependencyInjectionTestExecutionListener) Before(org.junit.Before) Donor(org.icgc.dcc.song.server.model.entity.Donor) VARIANT_CALL(org.icgc.dcc.song.server.model.enums.AnalysisTypes.VARIANT_CALL) JsonUtils.toJson(org.icgc.dcc.song.core.utils.JsonUtils.toJson) lombok.val(lombok.val) Test(org.junit.Test) Maps(com.google.common.collect.Maps) CompositeEntity(org.icgc.dcc.song.server.model.entity.composites.CompositeEntity) UploadStates.resolveState(org.icgc.dcc.song.server.model.enums.UploadStates.resolveState) AnalysisRepository(org.icgc.dcc.song.server.repository.AnalysisRepository) EMPTY_STRING(org.icgc.dcc.song.server.utils.TestFiles.EMPTY_STRING) Collectors.toImmutableList(org.icgc.dcc.common.core.util.stream.Collectors.toImmutableList) StudyGenerator.createStudyGenerator(org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator) UploadStates(org.icgc.dcc.song.server.model.enums.UploadStates) ResponseEntity(org.springframework.http.ResponseEntity) Sample(org.icgc.dcc.song.server.model.entity.Sample) SequencingReadAnalysis(org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis) VariantCallAnalysis(org.icgc.dcc.song.server.model.analysis.VariantCallAnalysis) Analysis(org.icgc.dcc.song.server.model.analysis.Analysis)

Example 10 with Maps

use of org.apache.flink.shaded.guava30.com.google.common.collect.Maps in project atomix by atomix.

the class ConsistentMapProxyBuilder method buildAsync.

@Override
@SuppressWarnings("unchecked")
public CompletableFuture<ConsistentMap<K, V>> buildAsync() {
    PrimitiveProtocol protocol = protocol();
    PartitionGroup<?> partitions = managementService.getPartitionService().getPartitionGroup(protocol);
    Map<PartitionId, CompletableFuture<AsyncConsistentMap<byte[], byte[]>>> maps = Maps.newConcurrentMap();
    for (Partition partition : partitions.getPartitions()) {
        maps.put(partition.id(), partition.getPrimitiveClient().newProxy(name(), primitiveType(), protocol).connect().thenApply(proxy -> new TranscodingAsyncConsistentMap<>(new ConsistentMapProxy(proxy), BaseEncoding.base16()::encode, BaseEncoding.base16()::decode, Function.identity(), Function.identity())));
    }
    Partitioner<byte[]> partitioner = key -> {
        int bucket = Math.abs(Hashing.murmur3_32().hashBytes(key).asInt()) % NUM_BUCKETS;
        return partitions.getPartitionIds().get(Hashing.consistentHash(bucket, partitions.getPartitionIds().size()));
    };
    return Futures.allOf(Lists.newArrayList(maps.values())).thenApply(m -> {
        AsyncConsistentMap<byte[], byte[]> partitionedMap = new PartitionedAsyncConsistentMap<>(name(), Maps.transformValues(maps, v -> v.getNow(null)), partitioner);
        Serializer serializer = serializer();
        AsyncConsistentMap<K, V> map = new TranscodingAsyncConsistentMap<>(partitionedMap, key -> serializer.encode(key), bytes -> serializer.decode(bytes), value -> value == null ? null : serializer.encode(value), bytes -> serializer.decode(bytes));
        if (!nullValues()) {
            map = new NotNullAsyncConsistentMap<>(map);
        }
        if (relaxedReadConsistency()) {
            map = new CachingAsyncConsistentMap<>(map);
        }
        if (readOnly()) {
            map = new UnmodifiableAsyncConsistentMap<>(map);
        }
        return map.sync();
    });
}
Also used : BaseEncoding(com.google.common.io.BaseEncoding) ConsistentMapBuilder(io.atomix.core.map.ConsistentMapBuilder) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) Hashing(com.google.common.hash.Hashing) CompletableFuture(java.util.concurrent.CompletableFuture) Maps(com.google.common.collect.Maps) PartitionGroup(io.atomix.primitive.partition.PartitionGroup) Function(java.util.function.Function) PartitionId(io.atomix.primitive.partition.PartitionId) Lists(com.google.common.collect.Lists) AsyncConsistentMap(io.atomix.core.map.AsyncConsistentMap) Partition(io.atomix.primitive.partition.Partition) PrimitiveManagementService(io.atomix.primitive.PrimitiveManagementService) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol) ConsistentMap(io.atomix.core.map.ConsistentMap) Map(java.util.Map) Partitioner(io.atomix.primitive.partition.Partitioner) Serializer(io.atomix.utils.serializer.Serializer) Futures(io.atomix.utils.concurrent.Futures) Partition(io.atomix.primitive.partition.Partition) PartitionId(io.atomix.primitive.partition.PartitionId) CompletableFuture(java.util.concurrent.CompletableFuture) PrimitiveProtocol(io.atomix.primitive.PrimitiveProtocol) Serializer(io.atomix.utils.serializer.Serializer)

Aggregations

Maps (com.google.common.collect.Maps)15 Map (java.util.Map)10 Slf4j (lombok.extern.slf4j.Slf4j)9 List (java.util.List)8 lombok.val (lombok.val)8 Test (org.junit.Test)7 ArrayList (java.util.ArrayList)6 Collection (java.util.Collection)5 Collectors.toSet (java.util.stream.Collectors.toSet)5 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)5 RandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator)5 RandomGenerator.createRandomGenerator (org.icgc.dcc.song.core.utils.RandomGenerator.createRandomGenerator)5 SequencingReadAnalysis (org.icgc.dcc.song.server.model.analysis.SequencingReadAnalysis)5 Sample (org.icgc.dcc.song.server.model.entity.Sample)5 CompositeEntity (org.icgc.dcc.song.server.model.entity.composites.CompositeEntity)5 AnalysisGenerator.createAnalysisGenerator (org.icgc.dcc.song.server.utils.AnalysisGenerator.createAnalysisGenerator)5 StudyGenerator.createStudyGenerator (org.icgc.dcc.song.server.utils.StudyGenerator.createStudyGenerator)5 Before (org.junit.Before)5 RunWith (org.junit.runner.RunWith)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5