com.beust.jcommander.internal.Lists Java Examples

The following examples show how to use com.beust.jcommander.internal.Lists. 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 File: LettuceJobMetadataAccessorTest.java    From sherlock with GNU General Public License v3.0 6 votes vote down vote up
@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 #2
Source File: TestCSVImportCommandCluster.java    From kite with 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 #3
Source File: TestCSVImportCommand.java    From kite with 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 #4
Source File: DetectorServiceTest.java    From sherlock with 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 #5
Source File: TestCreateColumnMappingCommand.java    From kite with 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 #6
Source File: EgadsServiceTest.java    From sherlock with 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 #7
Source File: EgadsTaskTest.java    From sherlock with 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 #8
Source File: TestCreatePartitionStrategyCommand.java    From kite with 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 #9
Source File: TestCompactCommandCluster.java    From kite with 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 #10
Source File: TestCSVImportCommandCluster.java    From kite with 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 #11
Source File: TestCreateColumnMappingCommand.java    From kite with 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 #12
Source File: TestCreateDatasetWithExistingData.java    From kite with 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 #13
Source File: TestInputFormatImportCommandCluster.java    From kite with 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 #14
Source File: RandomGeneratorTest.java    From gsc-core with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #15
Source File: WxUtils.java    From wish-pay with 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 #16
Source File: WxUtils.java    From wish-pay with 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 #17
Source File: AliPayUtil.java    From wish-pay with 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 #18
Source File: TestInputFormatImportCommandCluster.java    From kite with 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 #19
Source File: TestInputFormatImportCommandCluster.java    From kite with 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 #20
Source File: IndexingProcessTest.java    From elasticsearch-reindex-tool with Apache License 2.0 6 votes vote down vote up
@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 #21
Source File: JoinFilterPushDownTest.java    From yql-plus with 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 #22
Source File: TestCopyCommandCluster.java    From kite with 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 #23
Source File: TestCSVImportCommandCluster.java    From kite with 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 #24
Source File: AuthorizationEngine.java    From sqoop-on-spark with 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 #25
Source File: AuthorizationEngine.java    From sqoop-on-spark with 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 #26
Source File: StringToolsTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@DataProvider (parallel = true)
public Iterator<Object[]> testCaseGenerator() {
    List<Object[]> testCases = Lists.newArrayList();

    testCases.add(new String[] {null, null});
    testCases.add(new String[] {"", ""});

    testCases.add(new String[] {null, ""});
    testCases.add(new String[] {"", null});

    testCases.add(new String[] {RandomStringUtils.randomAscii(1<<2), null});
    testCases.add(new String[] {RandomStringUtils.randomAscii(1<<2), ""});

    testCases.add(new String[] {null, RandomStringUtils.randomAscii(1<<2)});
    testCases.add(new String[] {"", RandomStringUtils.randomAscii(1<<2)});


    int i=1<<6;
    while(i-- > 0) {
        testCases.add(new String[] { RandomStringUtils.randomAscii(1<<10), RandomStringUtils.randomAscii(1<<2) });
        testCases.add(new String[] { RandomStringUtils.randomAscii(1<<2), RandomStringUtils.randomAscii(1<<10) });

        testCases.add(new String[] { RandomStringUtils.randomAlphabetic(1<<10), RandomStringUtils.randomAlphabetic(1<<2) });
        testCases.add(new String[] { RandomStringUtils.randomAlphabetic(1<<2), RandomStringUtils.randomAlphabetic(1<<10) });

        testCases.add(new String[] { RandomStringUtils.randomAlphanumeric(1<<10), RandomStringUtils.randomAlphanumeric(1<<2) });
        testCases.add(new String[] { RandomStringUtils.randomAlphanumeric(1<<2), RandomStringUtils.randomAlphanumeric(1<<10) });
    }

    return testCases.iterator();
}
 
Example #27
Source File: ObjectSchemaCommand.java    From kite with Apache License 2.0 5 votes vote down vote up
@Override
public List<String> getExamples() {
  return Lists.newArrayList(
      "# Create a schema for an example User class:",
      "org.kitesdk.cli.example.User",
      "# Create a schema for a class in a jar:",
      "com.example.MyRecord --jar my-application.jar",
      "# Save the schema for the example User class to user.avsc:",
      "org.kitesdk.cli.example.User -o user.avsc"
  );
}
 
Example #28
Source File: TestTarImportCommand.java    From kite with Apache License 2.0 5 votes vote down vote up
@Test
public void testTarNoCompressionImportCommand() throws IOException {
  command.targets = Lists.newArrayList(TAR_TEST_FILE, datasetUri);
  command.compressionType = "none";
  assertEquals(0, command.run());
  verify(console).info("Using {} compression",
      TarImportCommand.CompressionType.NONE);
  verify(console).info("Added {} records to \"{}\"",
      NUM_TEST_FILES,
      TEST_DATASET_NAME);
}
 
Example #29
Source File: ChainrInitializationTest.java    From jolt with Apache License 2.0 5 votes vote down vote up
@Test( expectedExceptions = SpecException.class )
public void failsOnOverEagerTransform() {
    List<JoltTransform> badSpec = Lists.newArrayList();

    // Stupid JoltTransform that implements both "real" interfaces
    badSpec.add( new OverEagerTransform() );

    new Chainr( badSpec );
}
 
Example #30
Source File: ClientServerTest.java    From opc-ua-stack with Apache License 2.0 5 votes vote down vote up
private void connectAndTest(Variant input, UaTcpStackClient client) throws InterruptedException, java.util.concurrent.ExecutionException {
    client.connect().get();

    List<TestStackRequest> requests = Lists.newArrayList();
    List<CompletableFuture<? extends UaResponseMessage>> futures = Lists.newArrayList();

    for (int i = 0; i < 1000; i++) {
        RequestHeader header = new RequestHeader(
                NodeId.NULL_VALUE,
                DateTime.now(),
                uint(i), uint(0), null,
                uint(60000), null);

        requests.add(new TestStackRequest(header, uint(i), i, input));

        CompletableFuture<TestStackResponse> future = new CompletableFuture<>();

        future.thenAccept((response) -> assertEquals(response.getOutput(), input));

        futures.add(future);
    }

    client.sendRequests(requests, futures);

    CompletableFuture.allOf(futures.toArray(new CompletableFuture[futures.size()])).get();

    client.disconnect().get();
    Thread.sleep(100);
}