Java Code Examples for com.beust.jcommander.internal.Lists

The following examples show how to use com.beust.jcommander.internal.Lists. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sherlock   Source File: DetectorServiceTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testRunDetectionWithConfig() throws Exception {
    initMocks();
    List<Anomaly> anomalies = Lists.newArrayList(new Anomaly(), new Anomaly());
    TimeSeries endSeries = new TimeSeries();
    endSeries.data = new TimeSeries.DataSequence();
    endSeries.data.add(new TimeSeries.Entry(123 * 60, 1000));
    List<TimeSeries> tslist = Lists.newArrayList(endSeries, new TimeSeries());
    Properties p = new Properties();
    p.setProperty("AD_MODEL", "model1");
    when(egads.getP()).thenReturn(p);
    when(egads.runEGADS(any(), anyDouble())).thenReturn(anomalies);
    when(ds.runDetection(any(), anyDouble(), any(EgadsConfig.class), anyInt(), anyString(), any(Granularity.class), anyInt()))
            .thenCallRealMethod();
    List<Anomaly> result = ds.runDetection(tslist, 3.0, null, 123, "day", Granularity.DAY, 1);
    assertEquals(result.size(), 3);
    result = ds.runDetection(tslist, 3.0, mock(EgadsConfig.class), 123, "day", Granularity.DAY, 1);
    assertEquals(result.size(), 3);
    verify(egads, times(2)).runEGADS(any(), any());
    verify(egads, times(1)).preRunConfigure(any(), any(), anyInt());
    verify(egads, times(1)).configureWith(any());
}
 
Example 2
Source Project: kite   Source File: TestCreateColumnMappingCommand.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMissingKeyPartition() throws Exception {
  // does not include an identity partition for email
  command.partitionStrategyFile = "resource:test-partitions/email-hash-part.json";
  command.partitions = Lists.newArrayList(
      "email:key"
  );
  TestHelpers.assertThrows("Should reject missing partitioner",
      ValidationException.class, new Callable() {
        @Override
        public Object call() throws Exception {
          command.run();
          return null;
        }
      });
}
 
Example 3
Source Project: sherlock   Source File: EgadsServiceTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testDetectAnomaliesEgadsResult() throws Exception {
    EgadsService egads = mock(EgadsService.class);
    ProcessableObject po = mock(ProcessableObject.class);
    when(egads.getEgadsProcessableObject(any())).thenReturn(po);
    List<Anomaly> result = Lists.newArrayList(
            new Anomaly(), new Anomaly(), new Anomaly()
    );
    when(po.result()).thenReturn(result);
    when(egads.detectAnomaliesResult(any())).thenCallRealMethod();
    try {
        egads.detectAnomaliesResult(mock(TimeSeries.class));
    } catch (SherlockException e) {
        return;
    }
    fail();
}
 
Example 4
Source Project: sherlock   Source File: EgadsTaskTest.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testEgadsTaskRunToCompletion() throws SherlockException, IOException {
    JobMetadata j = new JobMetadata();
    j.setJobId(1);
    LettuceAnomalyReportAccessor ara = mock(LettuceAnomalyReportAccessor.class);
    j.setGranularity(Granularity.HOUR.toString());
    j.setEffectiveQueryTime(123456);
    int runtime = 1234;
    List<TimeSeries> tslist = Collections.emptyList();
    DetectorService ds = mock(DetectorService.class);
    JobExecutionService jes = mock(JobExecutionService.class);
    EgadsTask et = new EgadsTask(j, runtime, tslist, ds, jes);
    List<AnomalyReport> arlist = Lists.newArrayList(new AnomalyReport(), new AnomalyReport(), new AnomalyReport());
    when(ds.runDetection(any(), anyDouble(), any(), anyInt(), anyString(), any(), anyInt())).thenReturn(new ArrayList<>());
    when(jes.getReports(any(), any())).thenReturn(arlist);
    when(jes.getSingletonReport(any())).thenReturn(new AnomalyReport());
    when(jes.getAnomalyReportAccessor()).thenReturn(ara);
    doNothing().when(ara).deleteAnomalyReportsForJobAtTime(anyString(), anyString(), anyString());
    et.run();
    assertEquals(et.getReports().size(), 3);
}
 
Example 5
Source Project: kite   Source File: TestCreateColumnMappingCommand.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testVersionWithCounterTypes() throws Exception {
  // longs and ints are mapped
  command.partitions = Lists.newArrayList(
      "email:key", "version:version", "username:u", "created_at:u");
  command.run();

  ColumnMapping mapping = new ColumnMapping.Builder()
      .version("version")
      .key("email")
      .column("username", "u", "username")
      .column("created_at", "u", "created_at")
      .build();
  verify(console).info(mapping.toString(true));
  verifyNoMoreInteractions(console);
}
 
Example 6
@Test
public void testPutJobMetadatas() throws IOException {
    List<JobMetadata> jobs = Lists.newArrayList(
            make(1, "RUNNING", 123),
            make(2, "STOPPED", 123),
            make(null, "CREATED", 1111),
            make(null, "CREATED", 1444)
    );
    mocks();
    doCallRealMethod().when(jma).putJobMetadata(anyList());
    when(jma.newIds(2)).thenReturn(new Integer[]{3, 4});
    jma.putJobMetadata(jobs);
    verify(jma).newIds(2);
    assertEquals(jobs.get(2).getJobId(), (Integer) 3);
    assertEquals(jobs.get(3).getJobId(), (Integer) 4);
    verify(async, times(4)).hmset(anyString(), anyMap());
    verify(async, times(12)).sadd(anyString(), anyVararg());
}
 
Example 7
private List<WitnessWrapper> getWitnessList() {
  final List<WitnessWrapper> witnessWrapperList = Lists.newArrayList();
  final WitnessWrapper witnessGSC = new WitnessWrapper(
      ByteString.copyFrom("00000000001".getBytes()), 0, "");
  final WitnessWrapper witnessOlivier = new WitnessWrapper(
      ByteString.copyFrom("00000000002".getBytes()), 100, "");
  final WitnessWrapper witnessVivider = new WitnessWrapper(
      ByteString.copyFrom("00000000003".getBytes()), 200, "");
  final WitnessWrapper witnessSenaLiu = new WitnessWrapper(
      ByteString.copyFrom("00000000004".getBytes()), 300, "");
  witnessWrapperList.add(witnessGSC);
  witnessWrapperList.add(witnessOlivier);
  witnessWrapperList.add(witnessVivider);
  witnessWrapperList.add(witnessSenaLiu);
  return witnessWrapperList;
}
 
Example 8
Source Project: wish-pay   Source File: WxUtils.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 签名算法
 *
 * @param o 要参与签名的数据对象
 * @return 签名
 * @throws IllegalAccessException
 */
public static String getSign(Object o, String key) throws IllegalAccessException {
    List<String> list = Lists.newArrayList();
    Class cls = o.getClass();
    Field[] fields = cls.getDeclaredFields();
    for (Field f : fields) {
        f.setAccessible(true);
        if (f.get(o) != null && f.get(o) != "") {
            list.add(f.getName() + "=" + f.get(o) + "&");
        }
    }
    int size = list.size();
    String[] arrayToSort = list.toArray(new String[size]);
    Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < size; i++) {
        sb.append(arrayToSort[i]);
    }
    String result = sb.toString();
    result += "key=" + key;
    //log.log("Sign Before MD5:" + result);
    result = md5(result).toUpperCase();
    //Util.log("Sign Result:" + result);
    return result;
}
 
Example 9
Source Project: wish-pay   Source File: WxUtils.java    License: Apache License 2.0 6 votes vote down vote up
public static String getSign(Map<String, Object> map, String key) {
    List<String> list = Lists.newArrayList();
    for (Map.Entry<String, Object> entry : map.entrySet()) {
        if (entry.getValue() != "") {
            list.add(entry.getKey() + "=" + entry.getValue() + "&");
        }
    }
    int size = list.size();
    String[] arrayToSort = list.toArray(new String[size]);
    Arrays.sort(arrayToSort, String.CASE_INSENSITIVE_ORDER);
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < size; i++) {
        sb.append(arrayToSort[i]);
    }
    String result = sb.toString();
    result += "key=" + key;
    //Util.log("Sign Before MD5:" + result);
    result = md5(result).toUpperCase();
    //Util.log("Sign Result:" + result);
    return result;
}
 
Example 10
Source Project: wish-pay   Source File: AliPayUtil.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 把数组所有元素按照字母顺序排序,并按照“参数=参数值”的模式用“&”字符拼接成字符串
 * <p>
 * 第一步: 在通知返回参数列表中,除去sign、sign_type两个参数外,凡是通知返回回来的参数皆是待验签的参数。
 * 第二步:将剩下参数进行url_decode, 然后进行字典排序,组成字符串,得到待签名字符串
 *
 * @param params 需要排序并参与字符拼接的参数组
 * @return 拼接后字符串
 * @Link 异步返回结果的验签:https://doc.open.alipay.com/docs/doc.htm?spm=a219a.7629140.0.0.OSyDs4&treeId=194&articleId=103296&docType=1#s1
 */
public static String createStringUrl(Map<String, String> params) {

    List<String> keys = Lists.newArrayList(params.keySet());
    Collections.sort(keys);

    StringBuffer prestr = new StringBuffer();

    int keySize = keys.size();
    int lastKeyLength = keySize - 1;
    for (int i = 0; i < keySize; i++) {
        String key = keys.get(i);
       /* if (*//*key.equals("sign") ||*//* key.equals("sign_type")) {//除去sign、sign_type两个参数
            continue;
        }*/

        String value = params.get(key);
        if (i == lastKeyLength) {//拼接时,不包括最后一个&字符
            prestr.append(key).append("=").append(value);
        } else {
            prestr.append(key).append("=").append(value).append("&");
        }
    }

    return prestr.toString();
}
 
Example 11
Source Project: yql-plus   Source File: JoinFilterPushDownTest.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testRightPush() throws IOException {
    OperatorNode<SequenceOperator> query = OperatorNode.create(SequenceOperator.FILTER,
            OperatorNode.create(SequenceOperator.JOIN,
                    OperatorNode.create(SequenceOperator.SCAN, ImmutableList.of("left"), Lists.newArrayList()).putAnnotation("alias", "left"),
                    OperatorNode.create(SequenceOperator.SCAN, ImmutableList.of("right"), Lists.newArrayList()).putAnnotation("alias", "right"),
                    OperatorNode.create(ExpressionOperator.EQ,
                            OperatorNode.create(ExpressionOperator.PROPREF, OperatorNode.create(ExpressionOperator.READ_RECORD, "left"), "id"),
                            OperatorNode.create(ExpressionOperator.PROPREF, OperatorNode.create(ExpressionOperator.READ_RECORD, "right"), "id"))
            ),
            OperatorNode.create(ExpressionOperator.EQ,
                    OperatorNode.create(ExpressionOperator.PROPREF, OperatorNode.create(ExpressionOperator.READ_RECORD, "right"), "id"),
                    OperatorNode.create(ExpressionOperator.LITERAL, "1"))
    );
    OperatorNode<SequenceOperator> transformed = new JoinFilterPushDown().visitSequenceOperator(query);
    Assert.assertEquals(transformed.getOperator(), SequenceOperator.JOIN);
    Assert.assertEquals(((OperatorNode) transformed.getArgument(0)).getOperator(), SequenceOperator.SCAN);
    Assert.assertEquals(((OperatorNode) transformed.getArgument(1)).getOperator(), SequenceOperator.FILTER);
    // TODO: validate the rest of the tree
}
 
Example 12
Source Project: kite   Source File: TestCSVImportCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testHDFSDirectoryImport() throws Exception {
  Path hdfsSample = getDFS().makeQualified(new Path("hdfs:/tmp/sample"));
  getDFS().mkdirs(hdfsSample);

  FSDataOutputStream one = getDFS().create(
      new Path(hdfsSample, "one.csv"), true /* overwrite */ );
  OutputStreamWriter writer = new OutputStreamWriter(one, "utf8");
  writer.write("id,username,email\n");
  writer.write("1,test,[email protected]\n");
  writer.close();

  FSDataOutputStream two = getDFS().create(
      new Path(hdfsSample, "two.csv"), true /* overwrite */ );
  writer = new OutputStreamWriter(two, "utf8");
  writer.append("id,username,email\n");
  writer.append("2,user,[email protected]\n");
  writer.close();

  command.targets = Lists.newArrayList(hdfsSample.toString(), datasetName);
  command.run();
  Assert.assertEquals("Should contain expected records",
      expected, DatasetTestUtilities.materialize(dataset));
  verify(console).info("Added {} records to \"{}\"", 2l, datasetName);
  verifyNoMoreInteractions(console);
}
 
Example 13
Source Project: sqoop-on-spark   Source File: AuthorizationEngine.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Filter resources, get all valid resources from all resources
 */
public static <T extends MPersistableEntity> List<T> filterResource(final MResource.TYPE type, List<T> resources) throws SqoopException {
  Collection<T> collection = Collections2.filter(resources, new Predicate<T>() {
    @Override
    public boolean apply(T input) {
      try {
        String name = String.valueOf(input.getPersistenceId());
        checkPrivilege(getPrivilege(type, name, MPrivilege.ACTION.READ));
        // add valid resource
        return true;
      } catch (Exception e) {
        //do not add into result if invalid resource
        return false;
      }
    }
  });
  return Lists.newArrayList(collection);
}
 
Example 14
Source Project: sqoop-on-spark   Source File: AuthorizationEngine.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Filter resources, get all valid resources from all resources
 */
public static List<MSubmission> filterSubmission(List<MSubmission> submissions) throws SqoopException {
  Collection<MSubmission> collection = Collections2.filter(submissions, new Predicate<MSubmission>() {
    @Override
    public boolean apply(MSubmission input) {
      try {
        String jobId = String.valueOf(input.getJobId());
        checkPrivilege(getPrivilege(MResource.TYPE.JOB, jobId, MPrivilege.ACTION.READ));
        // add valid submission
        return true;
      } catch (Exception e) {
        //do not add into result if invalid submission
        return false;
      }
    }
  });
  return Lists.newArrayList(collection);
}
 
Example 15
Source Project: kite   Source File: TestCopyCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public void testCopyWithNumWriters(int expectedFiles) throws Exception {
  Assume.assumeTrue(setLocalReducerMax(getConfiguration(), 3));

  command.repoURI = repoUri;
  command.numWriters = 3;
  command.datasets = Lists.newArrayList(source, dest);

  int rc = command.run();
  Assert.assertEquals("Should return success", 0, rc);

  DatasetRepository repo = DatasetRepositories.repositoryFor("repo:" + repoUri);
  FileSystemDataset<GenericData.Record> ds =
      (FileSystemDataset<GenericData.Record>) repo.<GenericData.Record>
          load("default", dest);
  int size = Iterators.size(ds.newReader());
  Assert.assertEquals("Should contain copied records", 6, size);

  Assert.assertEquals("Should produce " + expectedFiles + " files",
      expectedFiles, Iterators.size(ds.pathIterator()));

  verify(console).info("Added {} records to \"{}\"", 6l, dest);
  verifyNoMoreInteractions(console);
}
 
Example 16
@Test
public void verifyIndexedFailedCount() throws Exception {

  //given
  ElasticDataPointer dataPointer = ElasticDataPointerBuilder.builder()
      .setAddress("http://localhost:9300/" + INDEX + "/" + TYPE)
      .build();
  ProcessSynchronizer processSynchronizer = buildProcessSynchronizerMock();
  IndexingComponent indexingComponent = mock(IndexingComponent.class);
  when(indexingComponent.indexData(eq(dataPointer), any(SearchHit[].class)))
      .thenReturn(Optional.of(new BulkResult(0, Lists.newArrayList("1", "2"))));

  //when
  IndexingProcess updatesProcess = IndexingProcessBuilder.builder()
      .setProcessSynchronizer(processSynchronizer)
      .setIndexingComponent(indexingComponent)
      .setDataPointer(dataPointer)
      .build();
  updatesProcess.run();

  //then
  verify(processSynchronizer, times(1)).incrementFailures(2);
}
 
Example 17
Source Project: kite   Source File: TestCreatePartitionStrategyCommand.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testTime() throws Exception {
  command.partitions = Lists.newArrayList(
      "created_at:year", "created_at:month", "created_at:day",
      "created_at:hour", "created_at:minute"
  );
  command.run();

  PartitionStrategy strategy = new PartitionStrategy.Builder()
      .year("created_at")
      .month("created_at")
      .day("created_at")
      .hour("created_at")
      .minute("created_at")
      .build();
  verify(console).info(strategy.toString(true));
  verifyNoMoreInteractions(console);
}
 
Example 18
Source Project: kite   Source File: TestCSVImportCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testDirectoryImport() throws Exception {
  new File("target/sample").mkdir();
  BufferedWriter writer = Files.newWriter(
      new File("target/sample/one.csv"), CSVSchemaCommand.SCHEMA_CHARSET);
  writer.append("id,username,email\n");
  writer.append("1,test,[email protected]\n");
  writer.close();

  writer = Files.newWriter(
      new File("target/sample/two.csv"), CSVSchemaCommand.SCHEMA_CHARSET);
  writer.append("id,username,email\n");
  writer.append("2,user,[email protected]\n");
  writer.close();

  command.targets = Lists.newArrayList("target/sample", datasetName);
  command.run();
  Assert.assertEquals("Should contain expected records",
      expected, DatasetTestUtilities.materialize(dataset));
  verify(console).info("Added {} records to \"{}\"", 2l, datasetName);
  verifyNoMoreInteractions(console);
}
 
Example 19
Source Project: kite   Source File: TestCSVImportCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testEmptyHDFSSampleDirectory() throws Exception {
  String hdfsSample = "hdfs:/tmp/emptyDir";
  getDFS().mkdirs(new Path(hdfsSample));

  command.targets = Lists.newArrayList(hdfsSample, datasetName);
  TestHelpers.assertThrows("Should complain about no data files",
      IllegalArgumentException.class, new Callable() {
        @Override
        public Object call() throws Exception {
          command.run();
          return null;
        }
      });
  verifyNoMoreInteractions(console);
}
 
Example 20
Source Project: kite   Source File: TestCreateDatasetWithExistingData.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateFromExistingWithLocation() throws Exception {
  command.datasets = Lists.newArrayList(existingDataURI);
  command.location = existingPartitionedPathWithPartition.toString();
  command.run();

  verify(console).debug(contains("Created"), eq(existingDataURI));

  // load the new dataset and verify it
  Dataset<GenericRecord> users = Datasets.load(existingDataURI);
  Assert.assertEquals("Schema should match",
      USER_SCHEMA, users.getDescriptor().getSchema());
  Assert.assertFalse("Should not be partitioned",
      users.getDescriptor().isPartitioned());
  Assert.assertEquals("Should be Parquet",
      Formats.PARQUET, users.getDescriptor().getFormat());
  Assert.assertTrue("Location should point to the partitioned data",
      String.valueOf(users.getDescriptor().getLocation())
          .endsWith(existingPartitionedPathWithPartition.toString()));
}
 
Example 21
Source Project: kite   Source File: TestInputFormatImportCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testLocalImportWithTransform() throws Exception {
  String sample = temp.newFile("sample.sequence").toString();
  writeSequenceFile(getFS(), new Path(sample)); // local sequence file

  // Crunch will use a MemPipeline, so use the custom copying InputFormat
  command.inFormatClass = CopyingInputFormat.class.getName();
  command.targets = Lists.newArrayList(sample, datasetUri);
  command.noCompaction = true; // no need to run reducers
  command.transform = TransformMeasurement.class.getName();

  int rc = command.run();

  Assert.assertEquals("Should return success", 0, rc);

  verify(console).info("Added {} records to \"{}\"", 3L, datasetUri);
  verifyNoMoreInteractions(console);

  Set<Measurement> datasetContent = materialize(
      Datasets.load(datasetUri, Measurement.class));
  Set<Measurement> expected = Sets.newHashSet(Iterables.transform(
      measurements, new TransformMeasurement()));
  Assert.assertEquals(expected, datasetContent);
}
 
Example 22
Source Project: kite   Source File: TestInputFormatImportCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMRImport() throws Exception {
  Path sample = new Path(temp.newFile("sample.sequence").toString())
      .makeQualified(getDFS().getUri(), new Path("/"));
  writeSequenceFile(getDFS(), sample); // HDFS sequence file

  // Reusing records is okay when running in MR
  command.inFormatClass = SequenceFileInputFormat.class.getName();
  command.targets = Lists.newArrayList(sample.toString(), datasetUri);
  command.noCompaction = true; // no need to run reducers

  int rc = command.run();

  Assert.assertEquals("Should return success", 0, rc);

  verify(console).info("Added {} records to \"{}\"", 3L, datasetUri);
  verifyNoMoreInteractions(console);

  Set<Measurement> datasetContent = materialize(
      Datasets.load(datasetUri, Measurement.class));
  Assert.assertEquals(Sets.newHashSet(measurements), datasetContent);
}
 
Example 23
Source Project: kite   Source File: TestInputFormatImportCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testMRImportWithTransform() throws Exception {
  Path sample = new Path(temp.newFile("sample.sequence").toString())
      .makeQualified(getDFS().getUri(), new Path("/"));
  writeSequenceFile(getDFS(), sample); // HDFS sequence file

  // Reusing records is okay when running in MR
  command.inFormatClass = SequenceFileInputFormat.class.getName();
  command.targets = Lists.newArrayList(sample.toString(), datasetUri);
  command.noCompaction = true; // no need to run reducers
  command.transform = TransformMeasurement.class.getName();

  int rc = command.run();

  Assert.assertEquals("Should return success", 0, rc);

  verify(console).info("Added {} records to \"{}\"", 3L, datasetUri);
  verifyNoMoreInteractions(console);

  Set<Measurement> datasetContent = materialize(
      Datasets.load(datasetUri, Measurement.class));
  Set<Measurement> expected = Sets.newHashSet(Iterables.transform(
      measurements, new TransformMeasurement()));
  Assert.assertEquals(expected, datasetContent);
}
 
Example 24
Source Project: kite   Source File: TestCSVImportCommand.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void testIncompatibleSchemaFieldType() throws Exception {
  BufferedWriter writer = Files.newWriter(
      new File("target/incompatible.csv"), CSVSchemaCommand.SCHEMA_CHARSET);
  writer.append("id,username,email\n");
  writer.append("NaN,test,[email protected]\n"); // id will be String
  writer.close();

  // This will fail because NaN isn't a valid long and the field is required
  command.targets = Lists.newArrayList("target/incompatible.csv", datasetName);

  int rc = command.run();
  Assert.assertEquals(1, rc);

  verify(console).trace(contains("repo:file:target/data"));
  verifyNoMoreInteractions(console);
}
 
Example 25
Source Project: kite   Source File: TestCompactCommandCluster.java    License: Apache License 2.0 6 votes vote down vote up
@Test
@SuppressWarnings("unchecked")
public void testCompactUnpartitionedWithNumWriters() throws Exception {
  Assume.assumeTrue(setLocalReducerMax(getConfiguration(), 3));

  command.repoURI = repoUri;
  command.numWriters = 3;
  command.datasets = Lists.newArrayList(unpartitioned);

  int rc = command.run();
  Assert.assertEquals("Should return success", 0, rc);

  DatasetRepository repo = DatasetRepositories.repositoryFor("repo:" + repoUri);
  FileSystemDataset<GenericData.Record> ds =
      (FileSystemDataset<GenericData.Record>) repo.<GenericData.Record>
          load("default", unpartitioned);
  int size = Iterators.size(ds.newReader());
  Assert.assertEquals("Should contain copied records", numRecords, size);

  Assert.assertEquals("Should produce 3 files",
      3, Iterators.size(ds.pathIterator()));

  verify(console).info("Compacted {} records in \"{}\"",(long) numRecords, unpartitioned);
  verifyNoMoreInteractions(console);
}
 
Example 26
@SpringJUnit4ParameterizedClassRunner.Parameters
public static Collection<Object[]> getTestParameters() {

  return Arrays.asList(new Object[][] {
      {"/ncss/grid/testGFSfmrc/files/GFS_CONUS_80km_20120418_1200.nc",
          Lists.newArrayList("Pressure", "Pressure_reduced_to_MSL"), new int[][] {{1, 2, 2}, {1, 2, 2}},
          // No vertical levels
          new ProjectionRect(-4226.106971141345, -832.6983183345455, -4126.106971141345, -732.6983183345455)},

      {"/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd",
          Lists.newArrayList("Relative_humidity_height_above_ground", "Temperature_height_above_ground"),
          // Same vertical level (one level)
          new int[][] {{1, 1, 16, 15}, {1, 1, 16, 15}}, new ProjectionRect(-600, -600, 600, 600)},

      {"/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd", Lists.newArrayList("Temperature", "Relative_humidity"),
          new int[][] {{1, 29, 2, 93}, {1, 29, 2, 93}},
          // Same vertical level (multiple level)
          new ProjectionRect(-4226.106971141345, 4268.6456816654545, 3250.825028858655, 4368.6456816654545)},

      {"/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd",
          Lists.newArrayList("Pressure", "Temperature", "Relative_humidity_height_above_ground"),
          new int[][] {{1, 2, 93}, {1, 29, 2, 93}, {1, 1, 2, 93}},
          // No vertical levels and vertical levels
          new ProjectionRect(-4226.106971141345, 4268.6456816654545, 3250.825028858655, 4368.6456816654545)},

      {"/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd",
          Lists.newArrayList("Relative_humidity_height_above_ground", "Temperature"),
          new int[][] {{1, 1, 65, 93}, {1, 29, 65, 93}},
          // Full extension
          new ProjectionRect(-4264.248291015625, -872.8428344726562, 3293.955078125, 4409.772216796875)},

      {"/ncss/grid/testGFSfmrc/GFS_CONUS_80km_nc_best.ncd",
          Lists.newArrayList("Relative_humidity_height_above_ground", "Temperature"),
          new int[][] {{1, 1, 11, 53}, {1, 29, 11, 53}},
          new ProjectionRect(-4864.248291015625, -1272.8428344726562, 0, 0)} // Intersection
  });
}
 
Example 27
Source Project: kite   Source File: TestCreateColumnMappingCommand.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testKAC() throws Exception {
  command.partitions = Lists.newArrayList(
      "email:key", "username:u", "preferences:prefs");
  command.run();

  ColumnMapping mapping = new ColumnMapping.Builder()
      .key("email")
      .column("username", "u", "username")
      .keyAsColumn("preferences", "prefs")
      .build();
  verify(console).info(mapping.toString(true));
  verifyNoMoreInteractions(console);
}
 
Example 28
Source Project: kite   Source File: TestCreateDatasetWithExistingData.java    License: Apache License 2.0 5 votes vote down vote up
@Test
public void testFailCreateIfDatasetExists() throws Exception {
  command.datasets = Lists.newArrayList(sourceDatasetURI);

  TestHelpers.assertThrows(
      "Should fail because the dataset already exists",
      DatasetExistsException.class, new Callable<Void>() {
        @Override
        public Void call() throws IOException {
          command.run();
          return null;
        }
      });
}
 
Example 29
Source Project: sherlock   Source File: RoutesTest.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testDebugPerformEgadsQuery() throws Exception {
    mocks();
    JsonObject jo = new JsonObject();
    jo.addProperty(QueryConstants.POSTAGGREGATIONS, "a");
    jo.addProperty(QueryConstants.AGGREGATIONS, "a");
    JsonObject gran = new JsonObject();
    gran.addProperty(QueryConstants.PERIOD, "P1H");
    jo.add(QueryConstants.GRANULARITY, gran);
    jo.addProperty(QueryConstants.INTERVALS, "1");
    QueryParamsMap map = mock(QueryParamsMap.class);
    Map<String, String[]> smap = new HashMap<>();
    when(map.toMap()).thenReturn(smap);
    when(req.queryMap()).thenReturn(map);
    smap.put("query", new String[]{new Gson().toJson(jo)});
    smap.put("ownerEmail", new String[]{"[email protected],[email protected]"});
    EgadsResult er = mock(EgadsResult.class);
    EgadsResult.Series series = mock(EgadsResult.Series.class);
    EgadsResult.Series[] data = {series, series, series};
    when(er.getData()).thenReturn(data);
    List<Anomaly> anomalies = Lists.newArrayList(new Anomaly());
    when(er.getAnomalies()).thenReturn(anomalies);
    List<EgadsResult> erlist = Lists.newArrayList(er);
    when(tte.render(any(ModelAndView.class))).thenReturn("html");
    when(ds.detectWithResults(any(), anyDouble(), any(), anyInt(), any())).thenReturn(erlist);
    ModelAndView mav = Routes.debugPerformEgadsQuery(req, res);
    assertTrue(params(mav).containsKey("tableHtml"));
    assertEquals(params(mav).get("tableHtml"), "html");
    assertTrue(params(mav).containsKey("data"));
    verify(ds, times(1)).detectWithResults(any(), anyDouble(), any(), anyInt(), any());
    verify(jes, times(1)).getReports(any(), any());
}
 
Example 30
@Test
public void testBulkPushQueue() throws IOException {
    mocks();
    doCallRealMethod().when(sch).pushQueue(anyList());
    List<Pair<Integer, String>> pairs = Lists.newArrayList(
            ImmutablePair.of(1000, "1"),
            ImmutablePair.of(2000, "2"),
            ImmutablePair.of(3000, "3")
    );
    sch.pushQueue(pairs);
    verify(sync, times(3)).zadd(anyString(), anyDouble(), anyString());
}