Search in sources :

Example 36 with Arrays.asList

use of java.util.Arrays.asList in project jackrabbit-oak by apache.

the class ScalabilityRunner method main.

public static void main(String[] args) throws Exception {
    OptionParser parser = new OptionParser();
    OptionSpec<File> base = parser.accepts("base", "Base directory").withRequiredArg().ofType(File.class).defaultsTo(new File("target"));
    OptionSpec<String> host = parser.accepts("host", "MongoDB host").withRequiredArg().defaultsTo("localhost");
    OptionSpec<Integer> port = parser.accepts("port", "MongoDB port").withRequiredArg().ofType(Integer.class).defaultsTo(27017);
    OptionSpec<String> dbName = parser.accepts("db", "MongoDB database").withRequiredArg();
    OptionSpec<Boolean> dropDBAfterTest = parser.accepts("dropDBAfterTest", "Whether to drop the MongoDB database after the test").withOptionalArg().ofType(Boolean.class).defaultsTo(true);
    OptionSpec<String> rdbjdbcuri = parser.accepts("rdbjdbcuri", "RDB JDBC URI").withOptionalArg().defaultsTo("jdbc:h2:./target/benchmark");
    OptionSpec<String> rdbjdbcuser = parser.accepts("rdbjdbcuser", "RDB JDBC user").withOptionalArg().defaultsTo("");
    OptionSpec<String> rdbjdbcpasswd = parser.accepts("rdbjdbcpasswd", "RDB JDBC password").withOptionalArg().defaultsTo("");
    OptionSpec<String> rdbjdbctableprefix = parser.accepts("rdbjdbctableprefix", "RDB JDBC table prefix").withOptionalArg().defaultsTo("");
    OptionSpec<Boolean> mmap = parser.accepts("mmap", "TarMK memory mapping").withOptionalArg().ofType(Boolean.class).defaultsTo("64".equals(System.getProperty("sun.arch.data.model")));
    OptionSpec<Integer> cache = parser.accepts("cache", "cache size (MB)").withRequiredArg().ofType(Integer.class).defaultsTo(100);
    OptionSpec<Integer> fdsCache = parser.accepts("blobCache", "cache size (MB)").withRequiredArg().ofType(Integer.class).defaultsTo(32);
    OptionSpec<Boolean> withStorage = parser.accepts("storage", "Index storage enabled").withOptionalArg().ofType(Boolean.class);
    OptionSpec<File> csvFile = parser.accepts("csvFile", "File to write a CSV version of the benchmark data.").withOptionalArg().ofType(File.class);
    OptionSpec<Integer> coldSyncInterval = parser.accepts("coldSyncInterval", "interval between sync cycles in sec (Segment-Tar-Cold only)").withRequiredArg().ofType(Integer.class).defaultsTo(5);
    OptionSpec<Boolean> coldUseDataStore = parser.accepts("useDataStore", "Whether to use a datastore in the cold standby topology (Segment-Tar-Cold only)").withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
    OptionSpec<Boolean> coldShareDataStore = parser.accepts("shareDataStore", "Whether to share the datastore for primary and standby in the cold standby topology (Segment-Tar-Cold only)").withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.FALSE);
    OptionSpec<Boolean> coldOneShotRun = parser.accepts("oneShotRun", "Whether to do a continuous sync between client and server or sync only once (Segment-Tar-Cold only)").withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.TRUE);
    OptionSpec<Boolean> coldSecure = parser.accepts("secure", "Whether to enable secure communication between primary and standby in the cold standby topology (Segment-Tar-Cold only)").withOptionalArg().ofType(Boolean.class).defaultsTo(Boolean.FALSE);
    OptionSpec<?> help = parser.acceptsAll(asList("h", "?", "help"), "show help").forHelp();
    OptionSpec<String> nonOption = parser.nonOptions();
    OptionSet options = parser.parse(args);
    if (options.has(help)) {
        parser.printHelpOn(System.out);
        System.exit(0);
    }
    int cacheSize = cache.value(options);
    RepositoryFixture[] allFixtures = new RepositoryFixture[] { new JackrabbitRepositoryFixture(base.value(options), cacheSize), OakRepositoryFixture.getMemoryNS(cacheSize * MB), OakRepositoryFixture.getMongo(host.value(options), port.value(options), dbName.value(options), dropDBAfterTest.value(options), cacheSize * MB), OakRepositoryFixture.getMongoWithDS(host.value(options), port.value(options), dbName.value(options), dropDBAfterTest.value(options), cacheSize * MB, base.value(options), fdsCache.value(options)), OakRepositoryFixture.getMongoNS(host.value(options), port.value(options), dbName.value(options), dropDBAfterTest.value(options), cacheSize * MB), OakRepositoryFixture.getSegmentTar(base.value(options), 256, cacheSize, mmap.value(options)), OakRepositoryFixture.getSegmentTarWithDataStore(base.value(options), 256, cacheSize, mmap.value(options), fdsCache.value(options)), OakRepositoryFixture.getSegmentTarWithColdStandby(base.value(options), 256, cacheSize, mmap.value(options), coldUseDataStore.value(options), fdsCache.value(options), coldSyncInterval.value(options), coldShareDataStore.value(options), coldSecure.value(options), coldOneShotRun.value(options)), OakRepositoryFixture.getRDB(rdbjdbcuri.value(options), rdbjdbcuser.value(options), rdbjdbcpasswd.value(options), rdbjdbctableprefix.value(options), dropDBAfterTest.value(options), cacheSize * MB, -1), OakRepositoryFixture.getRDBWithDS(rdbjdbcuri.value(options), rdbjdbcuser.value(options), rdbjdbcpasswd.value(options), rdbjdbctableprefix.value(options), dropDBAfterTest.value(options), cacheSize * MB, base.value(options), fdsCache.value(options), -1) };
    ScalabilitySuite[] allSuites = new ScalabilitySuite[] { new ScalabilityBlobSearchSuite(withStorage.value(options)).addBenchmarks(new FullTextSearcher(), new NodeTypeSearcher(), new FormatSearcher(), new FacetSearcher(), new LastModifiedSearcher(Date.LAST_2_HRS), new LastModifiedSearcher(Date.LAST_24_HRS), new LastModifiedSearcher(Date.LAST_7_DAYS), new LastModifiedSearcher(Date.LAST_MONTH), new LastModifiedSearcher(Date.LAST_YEAR), new OrderByDate()), new ScalabilityNodeSuite(withStorage.value(options)).addBenchmarks(new OrderBySearcher(), new SplitOrderBySearcher(), new OrderByOffsetPageSearcher(), new SplitOrderByOffsetPageSearcher(), new OrderByKeysetPageSearcher(), new SplitOrderByKeysetPageSearcher(), new MultiFilterOrderBySearcher(), new MultiFilterSplitOrderBySearcher(), new MultiFilterOrderByOffsetPageSearcher(), new MultiFilterSplitOrderByOffsetPageSearcher(), new MultiFilterOrderByKeysetPageSearcher(), new MultiFilterSplitOrderByKeysetPageSearcher(), new ConcurrentReader(), new ConcurrentWriter()), new ScalabilityNodeRelationshipSuite(withStorage.value(options)).addBenchmarks(new AggregateNodeSearcher()), new ScalabilityStandbySuite().addBenchmarks(new StandbyBulkTransferBenchmark()) };
    Set<String> argset = Sets.newHashSet(nonOption.values(options));
    List<RepositoryFixture> fixtures = Lists.newArrayList();
    for (RepositoryFixture fixture : allFixtures) {
        if (argset.remove(fixture.toString())) {
            fixtures.add(fixture);
        }
    }
    Map<String, List<String>> argmap = Maps.newHashMap();
    // Split the args to get suites and benchmarks (i.e. suite:benchmark1,benchmark2)
    for (String arg : argset) {
        List<String> tokens = Splitter.on(":").limit(2).splitToList(arg);
        if (tokens.size() > 1) {
            argmap.put(tokens.get(0), Splitter.on(",").trimResults().splitToList(tokens.get(1)));
        } else {
            argmap.put(tokens.get(0), null);
        }
        argset.remove(arg);
    }
    if (argmap.isEmpty()) {
        System.err.println("Warning: no scalability suites specified, " + "supported  are: " + Arrays.asList(allSuites));
    }
    List<ScalabilitySuite> suites = Lists.newArrayList();
    for (ScalabilitySuite suite : allSuites) {
        if (argmap.containsKey(suite.toString())) {
            List<String> benchmarks = argmap.get(suite.toString());
            // Only keep requested benchmarks
            if (benchmarks != null) {
                Iterator<String> iter = suite.getBenchmarks().keySet().iterator();
                for (; iter.hasNext(); ) {
                    String availBenchmark = iter.next();
                    if (!benchmarks.contains(availBenchmark)) {
                        iter.remove();
                    }
                }
            }
            suites.add(suite);
            argmap.remove(suite.toString());
        }
    }
    if (argmap.isEmpty()) {
        PrintStream out = null;
        if (options.has(csvFile)) {
            out = new PrintStream(FileUtils.openOutputStream(csvFile.value(options), true), false, Charsets.UTF_8.name());
        }
        for (ScalabilitySuite suite : suites) {
            if (suite instanceof CSVResultGenerator) {
                ((CSVResultGenerator) suite).setPrintStream(out);
            }
            suite.run(fixtures);
        }
        if (out != null) {
            out.close();
        }
    } else {
        System.err.println("Unknown arguments: " + argset);
    }
}
Also used : JackrabbitRepositoryFixture(org.apache.jackrabbit.oak.fixture.JackrabbitRepositoryFixture) MultiFilterOrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterOrderByKeysetPageSearcher) SplitOrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.SplitOrderByKeysetPageSearcher) OrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.OrderByKeysetPageSearcher) MultiFilterSplitOrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderByKeysetPageSearcher) MultiFilterSplitOrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderBySearcher) MultiFilterOrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterOrderByKeysetPageSearcher) LastModifiedSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.LastModifiedSearcher) FormatSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.FormatSearcher) JackrabbitRepositoryFixture(org.apache.jackrabbit.oak.fixture.JackrabbitRepositoryFixture) OakRepositoryFixture(org.apache.jackrabbit.oak.fixture.OakRepositoryFixture) RepositoryFixture(org.apache.jackrabbit.oak.fixture.RepositoryFixture) CSVResultGenerator(org.apache.jackrabbit.oak.benchmark.CSVResultGenerator) Arrays.asList(java.util.Arrays.asList) List(java.util.List) ScalabilityNodeRelationshipSuite(org.apache.jackrabbit.oak.scalability.suites.ScalabilityNodeRelationshipSuite) ConcurrentWriter(org.apache.jackrabbit.oak.scalability.benchmarks.search.ConcurrentWriter) SplitOrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.SplitOrderByKeysetPageSearcher) MultiFilterSplitOrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderByKeysetPageSearcher) MultiFilterSplitOrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderBySearcher) SplitOrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.SplitOrderBySearcher) MultiFilterOrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterOrderBySearcher) OrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.OrderBySearcher) ScalabilityNodeSuite(org.apache.jackrabbit.oak.scalability.suites.ScalabilityNodeSuite) FullTextSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.FullTextSearcher) ConcurrentReader(org.apache.jackrabbit.oak.scalability.benchmarks.search.ConcurrentReader) OrderByDate(org.apache.jackrabbit.oak.scalability.benchmarks.search.OrderByDate) MultiFilterSplitOrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderByOffsetPageSearcher) SplitOrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.SplitOrderByOffsetPageSearcher) File(java.io.File) MultiFilterOrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterOrderBySearcher) OptionParser(joptsimple.OptionParser) NodeTypeSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.NodeTypeSearcher) ScalabilityBlobSearchSuite(org.apache.jackrabbit.oak.scalability.suites.ScalabilityBlobSearchSuite) MultiFilterOrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterOrderByOffsetPageSearcher) MultiFilterSplitOrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderByOffsetPageSearcher) OrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.OrderByOffsetPageSearcher) SplitOrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.SplitOrderByOffsetPageSearcher) PrintStream(java.io.PrintStream) MultiFilterSplitOrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderBySearcher) SplitOrderBySearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.SplitOrderBySearcher) MultiFilterSplitOrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderByOffsetPageSearcher) FacetSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.FacetSearcher) StandbyBulkTransferBenchmark(org.apache.jackrabbit.oak.scalability.benchmarks.segment.standby.StandbyBulkTransferBenchmark) MultiFilterSplitOrderByKeysetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterSplitOrderByKeysetPageSearcher) MultiFilterOrderByOffsetPageSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.MultiFilterOrderByOffsetPageSearcher) AggregateNodeSearcher(org.apache.jackrabbit.oak.scalability.benchmarks.search.AggregateNodeSearcher) ScalabilityStandbySuite(org.apache.jackrabbit.oak.scalability.suites.ScalabilityStandbySuite) OptionSet(joptsimple.OptionSet)

Example 37 with Arrays.asList

use of java.util.Arrays.asList in project bullet-core by yahoo.

the class MetaTest method testErrorsAddition.

@Test
public void testErrorsAddition() {
    ParsingError errorA = new ParsingError("foo", asList("1", "2"));
    ParsingError errorB = new ParsingError("bar", asList("3", "4"));
    Meta meta = Meta.of(errorA, errorB);
    Map<String, Object> actual = meta.asMap();
    Assert.assertEquals(actual.size(), 1);
    List<ParsingError> actualErrors = (List<ParsingError>) actual.get(Meta.ERROR_KEY);
    Assert.assertEquals(actualErrors.size(), 2);
    Assert.assertEquals(actualErrors.get(0).getError(), "foo");
    Assert.assertEquals(actualErrors.get(0).getResolutions(), asList("1", "2"));
    Assert.assertEquals(actualErrors.get(1).getError(), "bar");
    Assert.assertEquals(actualErrors.get(1).getResolutions(), asList("3", "4"));
    ParsingError errorC = new ParsingError("baz", asList("5", "6"));
    ParsingError errorD = new ParsingError("qux", singletonList("7"));
    meta.addErrors(Arrays.asList(errorC, errorD));
    Assert.assertEquals(actualErrors.size(), 4);
    Assert.assertEquals(actualErrors.get(0).getError(), "foo");
    Assert.assertEquals(actualErrors.get(0).getResolutions(), asList("1", "2"));
    Assert.assertEquals(actualErrors.get(1).getError(), "bar");
    Assert.assertEquals(actualErrors.get(1).getResolutions(), asList("3", "4"));
    Assert.assertEquals(actualErrors.get(2).getError(), "baz");
    Assert.assertEquals(actualErrors.get(2).getResolutions(), asList("5", "6"));
    Assert.assertEquals(actualErrors.get(3).getError(), "qux");
    Assert.assertEquals(actualErrors.get(3).getResolutions(), singletonList("7"));
}
Also used : ParsingError(com.yahoo.bullet.parsing.ParsingError) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) List(java.util.List) Arrays.asList(java.util.Arrays.asList) Test(org.testng.annotations.Test)

Example 38 with Arrays.asList

use of java.util.Arrays.asList in project bullet-core by yahoo.

the class DistributionTest method testRounding.

@Test
public void testRounding() {
    Distribution distribution = makeDistribution(Distribution.Type.QUANTILE, 20, 6, 0.0, 1.0, 0.1);
    IntStream.range(0, 10).mapToDouble(i -> (i * 0.1)).mapToObj(d -> RecordBox.get().add("field", d).getRecord()).forEach(distribution::consume);
    Clip result = distribution.getResult();
    Map<String, Object> metadata = (Map<String, Object>) result.getMeta().asMap().get("meta");
    Assert.assertEquals(metadata.size(), 7);
    Assert.assertFalse((Boolean) metadata.get("isEst"));
    List<BulletRecord> records = result.getRecords();
    Assert.assertEquals(records.size(), 11);
    Set<String> actualQuantilePoints = records.stream().map(r -> r.get(QUANTILE_FIELD).toString()).collect(Collectors.toSet());
    Set<String> expectedQuantilePoints = new HashSet<>(Arrays.asList("0.0", "0.1", "0.2", "0.3", "0.4", "0.5", "0.6", "0.7", "0.8", "0.9", "1.0"));
    Assert.assertEquals(actualQuantilePoints, expectedQuantilePoints);
    Assert.assertEquals(distribution.getRecords(), result.getRecords());
    Assert.assertEquals(distribution.getMetadata().asMap(), result.getMeta().asMap());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) BulletError(com.yahoo.bullet.common.BulletError) Concept(com.yahoo.bullet.result.Meta.Concept) Test(org.testng.annotations.Test) HashMap(java.util.HashMap) RecordBox(com.yahoo.bullet.result.RecordBox) PROBABILITY_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.PROBABILITY_FIELD) Clip(com.yahoo.bullet.result.Clip) Family(com.yahoo.sketches.Family) SEPARATOR(com.yahoo.bullet.aggregations.sketches.QuantileSketch.SEPARATOR) HashSet(java.util.HashSet) VALUE_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.VALUE_FIELD) Pair(org.apache.commons.lang3.tuple.Pair) Assert(org.testng.Assert) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) AggregationUtils.makeAttributes(com.yahoo.bullet.parsing.AggregationUtils.makeAttributes) QUANTILE_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.QUANTILE_FIELD) BulletRecord(com.yahoo.bullet.record.BulletRecord) DoublesSketch(com.yahoo.sketches.quantiles.DoublesSketch) Aggregation(com.yahoo.bullet.parsing.Aggregation) COUNT_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.COUNT_FIELD) POSITIVE_INFINITY_END(com.yahoo.bullet.aggregations.sketches.QuantileSketch.POSITIVE_INFINITY_END) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) TestHelpers.assertApproxEquals(com.yahoo.bullet.TestHelpers.assertApproxEquals) START_INCLUSIVE(com.yahoo.bullet.aggregations.sketches.QuantileSketch.START_INCLUSIVE) TestHelpers.addMetadata(com.yahoo.bullet.TestHelpers.addMetadata) NEGATIVE_INFINITY_START(com.yahoo.bullet.aggregations.sketches.QuantileSketch.NEGATIVE_INFINITY_START) BulletConfig(com.yahoo.bullet.common.BulletConfig) Optional(java.util.Optional) RANGE_FIELD(com.yahoo.bullet.aggregations.sketches.QuantileSketch.RANGE_FIELD) Collections(java.util.Collections) END_EXCLUSIVE(com.yahoo.bullet.aggregations.sketches.QuantileSketch.END_EXCLUSIVE) Clip(com.yahoo.bullet.result.Clip) BulletRecord(com.yahoo.bullet.record.BulletRecord) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 39 with Arrays.asList

use of java.util.Arrays.asList in project motech by motech.

the class LookupProcessorTest method shouldNotUpdateRestExposedValueForLookupsThatHaveThatModifiedByUser.

@Test
public void shouldNotUpdateRestExposedValueForLookupsThatHaveThatModifiedByUser() throws Exception {
    when(paranamer.lookupParameterNames(getTestMethodExposedViaRest())).thenReturn(argNames);
    AdvancedSettingsDto advanced = mock(AdvancedSettingsDto.class);
    RestOptionsDto restOptions = mock(RestOptionsDto.class);
    when(schemaHolder.getAdvancedSettings(TEST_CLASS_NAME)).thenReturn(advanced);
    when(advanced.getRestOptions()).thenReturn(restOptions);
    when(restOptions.isModifiedByUser()).thenReturn(true);
    EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(new FieldDto("aaa", "bbb", TypeDto.STRING)));
    lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
    Method method = getTestMethodExposedViaRest();
    LookupDto dto = new LookupDto("Test Method Exposed Via Rest", true, false, lookupFieldDtos(argNames), true, "testMethodExposedViaRest", asList(argNames), true);
    lookupProcessor.process(method);
    Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
    assertTrue(elements.containsKey(TEST_CLASS_NAME));
    List<LookupDto> list = elements.get(TEST_CLASS_NAME);
    assertEquals(1, list.size());
    assertEquals(dto, list.get(0));
}
Also used : EntityDto(org.motechproject.mds.dto.EntityDto) LookupDto(org.motechproject.mds.dto.LookupDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) AdvancedSettingsDto(org.motechproject.mds.dto.AdvancedSettingsDto) Method(java.lang.reflect.Method) RestOptionsDto(org.motechproject.mds.dto.RestOptionsDto) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Example 40 with Arrays.asList

use of java.util.Arrays.asList in project motech by motech.

the class LookupProcessorTest method shouldProcessMethodWithRangeParam.

@Test
public void shouldProcessMethodWithRangeParam() throws NoSuchMethodException {
    FieldDto arg0Field = new FieldDto("arg0Field", "Arg 0 Field", TypeDto.BOOLEAN);
    FieldDto rangeField = new FieldDto("rangeField", "Range Field", TypeDto.STRING);
    FieldDto regularFieldField = new FieldDto("regularField", "Regular Field", TypeDto.BOOLEAN);
    FieldDto rangeFieldField = new FieldDto("rangeFieldDouble", "Range Field Double", TypeDto.DOUBLE);
    EntityProcessorOutput eop = mockEntityProcessorOutput(new EntityDto(TestClass.class.getName()), Arrays.asList(arg0Field, rangeField, regularFieldField, rangeFieldField));
    lookupProcessor.setEntityProcessingResult(Arrays.asList(eop));
    LookupFieldDto[][] expectedFields = { { lookupFieldDto("arg0"), lookupFieldDto("range", RANGE) }, { lookupFieldDto("regularField"), lookupFieldDto("rangeField", RANGE) } };
    String[][] expectedFieldsOrder = { { "arg0", "range" }, { "regularField", "rangeField" } };
    // test two methods, one with @LookupField annotations, second without
    for (int i = 0; i < 2; i++) {
        Method method = getTestMethodWithRangeParam(i);
        when(paranamer.lookupParameterNames(method)).thenReturn(new String[] { "arg0", "range" });
        LookupDto expectedLookup = new LookupDto("Test Method With Range Param " + i, false, false, asList(expectedFields[i]), true, "testMethodWithRangeParam" + i, asList(expectedFieldsOrder[i]), true);
        lookupProcessor.process(method);
        Map<String, List<LookupDto>> elements = lookupProcessor.getProcessingResult();
        assertTrue(elements.containsKey(TEST_CLASS_NAME));
        List<LookupDto> list = elements.get(TEST_CLASS_NAME);
        assertEquals(1, list.size());
        assertEquals(expectedLookup, list.get(0));
        assertEquals(asList(VALUE, RANGE), extract(list.get(0).getLookupFields(), on(LookupFieldDto.class).getType()));
        lookupProcessor.clear();
    }
}
Also used : LookupDto(org.motechproject.mds.dto.LookupDto) Method(java.lang.reflect.Method) EntityDto(org.motechproject.mds.dto.EntityDto) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) FieldTestHelper.lookupFieldDto(org.motechproject.mds.testutil.FieldTestHelper.lookupFieldDto) FieldDto(org.motechproject.mds.dto.FieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) LookupFieldDto(org.motechproject.mds.dto.LookupFieldDto) Test(org.junit.Test)

Aggregations

Arrays.asList (java.util.Arrays.asList)73 List (java.util.List)66 ArrayList (java.util.ArrayList)49 Test (org.junit.Test)37 Arrays (java.util.Arrays)22 Collections.singletonList (java.util.Collections.singletonList)20 Map (java.util.Map)18 Collectors (java.util.stream.Collectors)18 Test (org.junit.jupiter.api.Test)15 HashMap (java.util.HashMap)14 Before (org.junit.Before)13 Collection (java.util.Collection)12 Stream (java.util.stream.Stream)10 Method (java.lang.reflect.Method)9 Optional (java.util.Optional)9 Collections (java.util.Collections)8 Collections.emptyList (java.util.Collections.emptyList)8 TopicPartition (org.apache.kafka.common.TopicPartition)8 Employee (com.artezio.arttime.datamodel.Employee)6 HourType (com.artezio.arttime.datamodel.HourType)6